[Convert] Aspose. Cells reads the excel file, aspose. cellsexcel
Aspose is a powerful control that can be used to operate files such as word, excel, and ppt files. It is very convenient to use this control to import and export data. Among them, Aspose. Cells is used to operate Excel and has many functions. I use the most basic function to read Excel Data and import it to Dataset or database. The code for reading data from an Excel table is as follows:
First introduce the namespace: using Aspose. Cells;
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 (); // read data in one row. You can also insert the database code here }}
Returned Datatable:
Cells cells = workbook. worksheets [1]. cells; System. data. dataTable ableable1 = cells. exportDataTable (1, 0, cells. maxDataRow, cells. maxColumn); // noneTitleSystem. data. dataTable ableable2 = cells. exportDataTableAsString (0, 0, cells. maxDataRow + 1, cells. maxColumn, true); // showTitle // ExportDataTableAsString prevents the field of the date type from being read into a numeric string, such as "4859.321"