C#使用Aspose.Cells创建和读取Excel文件
程序员文章站
2023-12-15 21:21:34
使用aspose.cells创建和读取excel文件,供大家参考,具体内容如下
1. 创建excel
aspose.cells.license li = new...
使用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();
运行读取的结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。