SoFunction
Updated on 2025-03-07

C# Read Excel using controls

Aspose is a very powerful control, which can be used to operate word, excel, ppt and other files. It is very convenient to use this control to import and export data. Among them, it is used to operate Excel, and there are many functions. What I'm using is the most basic function, read the data of Excel and import it into a Dataset or database. The code for reading Excel table data is as follows:

First, we need to introduce a namespace: using;

Copy the codeThe code is as follows:

Workbook workbook = new Workbook();
("C:\\");
Cells cells = [0].Cells;
for (int i = 0; i < + 1; i++)
{
 for (int j = 0; j < + 1; j++)
 {
  string s = cells[i, j].();
//Line-by-line reading data, the code to insert into the database can also be written here
 }
}

Return Datatable:

Copy the codeThe code is as follows:

Cells cells = [1].Cells;
dataTable1 = (1, 0, ,);//noneTitle
dataTable2 = (0, 0, +1,,true);//showTitle