使用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
使用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();
运行读取的结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。