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);