标签:null pat xlsx 导出到excel cci cat excel write text
using Aspose.Cells;
void WriteToExcel(string filePath, List<object[]> datas, string sheetName = "Sheet0")
{
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 < Rownum; i++)
{
for (int j = 0; j < Colnum; 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<object[]> excelDatas = new List<object[]>();
object[] objTitle = new object[] { "SIM", "ICCID" };
excelDatas.Add(objTitle);
WriteToExcel("d:\\test.xlsx",excelDatas);
C# 基于Aspose.Cells的数据导出到Excel
标签:null pat xlsx 导出到excel cci cat excel write text
原文地址:http://www.cnblogs.com/94cool/p/7527268.html