aspose.excel格式

  1. Aspose.Cells.Style style = xlBook.Styles[xlBook.Styles.Add()];  
  2. style1.Pattern = Aspose.Cells.BackgroundType.Solid;//单元格的线:实线  
  3. style1.HorizontalAlignment = Aspose.Cells.TextAlignmentType.Center;//字体居中  
  4. style1.Font.Name = "宋体";//文字字体  
  5. style1.Font.Size = 8;//文字大小  
  6. style1.IsTextWrapped = true;//单元格内容自动换行  
  7. style1.ForegroundColor = System.Drawing.Color.FromArgb(50, 205, 50);//设置背景色 可以参考颜色代码对照表  
  8. style1.Font.IsBold = true;//粗体  
  9. Cells.Merge(1, 2, 2, 2);//合并单元格  
  10. Cells.SetRowHeight(0, 38);//设置行高   
  11. Cells.SetColumnWidth(0, 25);//设置列宽  
  12. Cells[0, 1].PutValue("2016年中科核安(标准产品)名称型号库存对照表");//添加内容  
  13. style1.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;//应用边界线 左边界线  
  14. style1.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线  
  15. style1.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;//应用边界线 上边界线  
  16. style1.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;//应用边界线 下边界线  
  17.   
  18. //excel数据列 循环列添加样式  
  19. for (int i = 0; i < dgv.ColumnCount-1; i++)  
  20. {  
  21. Cells[0, i].SetStyle(style1);  
  22. }  
  23. //excel数据行 循环行添加样式  
  24. for (int i = 0; i < dt.Rows.Count; i++)  
  25. {  
  26. for (int j = 0; j < 10; j++)  
  27. {  
  28. xlSheet.Cells[i + 1, j].SetStyle (style2);  
  29. Cells[i+1, 0].SetStyle(style3);  
  30. }  
  31. }   

猜你喜欢

转载自blog.csdn.net/maaici/article/details/76147496