使用Aspose.Cells创建和读取Excel文件,供大家参考,具体内容如下
1. 创建Excel
Aspose.Cells.License li = new Aspose.Cells.License();
li.SetLicense("Aspose.Cells.lic");
Aspose.Cells.Workbook wk = new Aspose.Cells.Workbook();
Worksheet ws = wk.Worksheets[0];
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
ws.Cells.Rows[i][j].Value = (i + 1) + "*" + (j + 1) + "=" + (i + 1) * (j + 1);
}
}
wk.Save("d:\\zzz\\d.xls");
Console.WriteLine("ok");
Console.ReadKey();产生的Excel文件:
2.读取Excel
DataTable dt = new DataTable();
Aspose.Cells.License li = new Aspose.Cells.License();
li.SetLicense("Aspose.Cells.lic");
Aspose.Cells.Workbook wk = new Aspose.Cells.Workbook("d:\\zzz\\d.xls");
Worksheet ws = wk.Worksheets[0];
dt = ws.Cells.ExportDataTable(0, 0, 9, 9);
for (int k = 0; k < dt.Rows.Count; k++)
{
for (int h = 0; h < dt.Columns.Count; h++)
{
Console.Write(dt.Rows[k][h].ToString() + " ");
}
Console.WriteLine();
}
Console.WriteLine("ok");
Console.ReadKey();
运行读取的结果:
您可能感兴趣的文章:C#语言MVC框架Aspose.Cells控件导出Excel表数据C# Winform实现导入和导出Excel文件C#使用Aspose.Cells导出excelAsp.Net(C#)使用oleDbConnection 连接Excel的方法C#使用Datatable导出ExcelC#在Excel表格中插入、编辑和删除批注C#结束Excel进程的步骤教学