C#使用Aspose.Cells创建和读取Excel文件

时间:2022-02-10 20:54:59

使用aspose.cells创建和读取excel文件,供大家参考,具体内容如下

1. 创建excel

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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文件:

C#使用Aspose.Cells创建和读取Excel文件

2.读取excel

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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#使用Aspose.Cells创建和读取Excel文件

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://www.cnblogs.com/ChengWenHao/archive/2018/10/19/AsposeCellsExcel.html