When I imported Excel Data yesterday, I accidentally found that some of the data could not be imported normally. Later I found that the data item content was already null when I imported it to dataset. It seems that it was an Excel Data source problem, after you view the data items that cannot be normally imported in a targeted manner, you can find the difference. The data format of the null cells is different from that of other cells, and there is no green triangle in the upper left corner. Follow these steps to modify the cell format, then the operation is OK. It seems that the format of the cell is caused.
The procedure is as follows:
1. Select any cell in the worksheet. For example, select C5 cell and enter '1' in the cell.
2. Select the C5 cell and click the "Start" tab → "format brush" under the "Clipboard" group. The mouse changes to a small brush shape.
3. Select cell A1: A18 and use this brush to fl the area.
4. Select cell A1: A18, click the "column" button in the "data tools" group under the "data" tab → next → select "text" in "column data format" → complete.
The import code is as follows:
Dataset dsexcel;
Httppostedfile file;
String strfilepath, strexe;
Strfilepath = string. empty;
If (fileupload1.hasfile)
{
File = fileupload1.postedfile;
Strexe = path. getextension (file. filename );
If (! Strexe. toupper (). Equals (". xls "))
{
Share. promptmessage (this, "the file format is incorrect! Select the correct Excel file! ");
Return false;
}
Strfilepath = configurationmanager. deleetpipeline ["affixpath"];
If (! Directory. exists (strfilepath ))
Directory. createdirectory (strfilepath );
Strfilepath + = "//" + m_excelfilename;
File. saveas (strfilepath );
}
If (! File. exists (strfilepath ))
{
Share. promptmessage (this, "An error occurred while uploading the Excel file! ");
Return false;
}
Dsexcel = excelmanage. exceltods (strfilepath );
If (dsexcel! = NULL & dsexcel. Tables [0]. Rows. Count> 0)
{
Import Operation .......
}