导出excel设置样式(Aspose.Cells)
2016-11-28 15:48
337 查看
1.导出excel样式大全
//设置格式
Aspose.Cells.Style style = xlBook.Styles[xlBook.Styles.Add()];
style1.Pattern = Aspose.Cells.BackgroundType.Solid;//单元格的线:实线
style1.HorizontalAlignment = Aspose.Cells.TextAlignmentType.Center;
//字体居中
style1.Font.Name = "宋体";//文字字体
style1.Font.Size = 8;//文字大小
style1.IsTextWrapped = true;//单元格内容自动换行
style1.ForegroundColor = System.Drawing.Color.FromArgb(50, 205, 50);//设置背景色 可以参考颜色代码对照表
style1.Font.IsBold = true;
//粗体
Cells.Merge(1, 2, 2, 2);
//合并单元格
Cells.SetRowHeight(0, 38);
//设置行高
Cells.SetColumnWidth(0, 25);
//设置列宽
Cells[0, 1].PutValue("2016年中科核安(标准产品)名称型号库存对照表");
//添加内容
style1.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
//应用边界线 左边界线
style1.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
style1.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
//应用边界线 上边界线
style1.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
//应用边界线 下边界线
//excel数据列 循环列添加样式
for (int i = 0; i < dgv.ColumnCount-1; i++)
{
Cells[0, i].SetStyle(style1);
}
//excel数据行 循环行添加样式
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < 10; j++)
{
xlSheet.Cells[i + 1, j].SetStyle (style2);
Cells[i+1, 0].SetStyle(style3);
}
}
//设置格式
Aspose.Cells.Style style = xlBook.Styles[xlBook.Styles.Add()];
style1.Pattern = Aspose.Cells.BackgroundType.Solid;//单元格的线:实线
style1.HorizontalAlignment = Aspose.Cells.TextAlignmentType.Center;
//字体居中
style1.Font.Name = "宋体";//文字字体
style1.Font.Size = 8;//文字大小
style1.IsTextWrapped = true;//单元格内容自动换行
style1.ForegroundColor = System.Drawing.Color.FromArgb(50, 205, 50);//设置背景色 可以参考颜色代码对照表
style1.Font.IsBold = true;
//粗体
Cells.Merge(1, 2, 2, 2);
//合并单元格
Cells.SetRowHeight(0, 38);
//设置行高
Cells.SetColumnWidth(0, 25);
//设置列宽
Cells[0, 1].PutValue("2016年中科核安(标准产品)名称型号库存对照表");
//添加内容
style1.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
//应用边界线 左边界线
style1.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
style1.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
//应用边界线 上边界线
style1.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
//应用边界线 下边界线
//excel数据列 循环列添加样式
for (int i = 0; i < dgv.ColumnCount-1; i++)
{
Cells[0, i].SetStyle(style1);
}
//excel数据行 循环行添加样式
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < 10; j++)
{
xlSheet.Cells[i + 1, j].SetStyle (style2);
Cells[i+1, 0].SetStyle(style3);
}
}
相关文章推荐
- C#+Aspose.Cells 导出Excel及设置样式 (Webform/Winform)
- 导出excel设置样式(Aspose.Cells)
- Asp.Net中应用Aspose.Cells输出报表到Excel 及样式设置
- Asp.Net中应用Aspose.Cells输出报表到Excel 及样式设置
- C# WinForm 导出导入Excel/Doc 完整实例教程[使用Aspose.Cells.dll]
- NPOI导出至Excel——合并单元格、设置样式、输入公式
- Aspose.Cells Smart markers 基于模板导出Excel
- C# winform 导出导入Excel/Doc 完整实例教程 使用Aspose.Cells.dll——第三篇
- 导出Excel并设置样式
- 导出Excel之Epplus使用教程2(样式设置)
- Java中导出到Excel实现_aspose.cells
- extjs+Aspose.Cells导出到Excel
- C# WinForm 导出导入Excel/Doc 完整实例教程[使用Aspose.Cells.dll]
- Aspose.Cells 导入导出EXCEL(转)
- Java中导出到Excel实现_aspose.cells
- Aspose.cells 导出Excel
- C# winform 导出导入Excel/Doc 完整实例教程 使用Aspose.Cells.dll——第一篇
- C# WinForm使用Aspose.Cells.dll 导出导入Excel/Doc 完整实例教程
- C# winform 导出导入Excel/Doc 完整实例教程 使用Aspose.Cells.dll——第二篇
- Aspose.Cells导出 Array.ArrayList.DataTable.DataColumn.DataView.DataGrid.GridView.DataReader数据源到Excel