C# 基于Aspose.Cells的数据导出到Excel
标签:null pat xlsx 导出到excel cci cat excel write text
using Aspose.Cells;
void WriteToExcel(string filePath, List
{
try
{
Workbook workBook = new Workbook();
Worksheet sheet = workBook.Worksheets[0];
sheet.Name = sheetName;
Aspose.Cells.Style style = workBook.Styles[workBook.Styles.Add()];
style.HorizontalAlignment = Aspose.Cells.TextAlignmentType.Center;
style.Font.IsBold = true;
int Colnum = datas[0].Length;//表格列数
int Rownum = datas.Count;//表格行数
//生成数据行
for (int i = 0; i
{
for (int j = 0; j
{
object obj = null;
if (datas[i].Length > j)
{
obj = datas[i][j];
}
sheet.Cells[i, j].PutValue(obj);
if (i == 0)
{
sheet.Cells[i, j].SetStyle(style);
}
}
}
workBook.Save(filePath);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
catch (Exception e)
{
}
}
List
评论