C# Aspose.Cells控件读取Excel
Workbook workbook = new Workbook(); workbook.Open("C:\\test.xlsx"); Cells cells = workbook.Worksheets[0].Cells; for (int i = 0; i < cells.MaxDataRow + 1; i++) { for (int j = 0; j < cells.MaxDataColumn + 1; j++) { string s = cells[i, j].StringValue.Trim(); //一行行的读取数据,插入数据库的代码也可以在这里写 } }
返回DataTable
Cells cells = workbook.Worksheets[1].Cells; //无标题 System.Data.DataTable dataTable1 = cells.ExportDataTable(1, 0, cells.MaxDataRow,cells.MaxColumn); //有标题 System.Data.DataTable dataTable2 = cells.ExportDataTable(0, 0, cells.MaxDataRow+1,cells.MaxColumn,true);