Note the following when using an ASP. net excel file:
ASP. NET operation EXCEL1. Add oledb reference
Using System. Data. OleDb;
ASP. NET operation EXCEL2. Obtain the excel path, which varies depending on the control used. In asp. net2003, only the HTML control File Field can be used. Obtained path: excel_route = this. File1.PostedFile. FileName. ToString ();
In asp. net2005, the obtained path is based on the FileUpload web control.
String excel_route = this. FileUpload1.PostedFile. FileName. ToString ();
Although they are all the same, 05 is better than 03.
ASP. NET EXCEL3, according to the use of Excel version does not need, when creating a link with excel, you need to use a different drive, currently with office2003 as the most common office, the drive type is
String connStr = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source = '" + excel_route + "'; Extended Properties = Excel 8.0 ;";
ASP. NET operations EXCEL4, Excel operations, just like reading a database table correctly, the difference is that the table name of the excel database is the name of the worksheet, that is, the name of the sheet.
String load_excel = "SELECT * FROM [" + sheet_name + "$]";
Generally, the workbook name is sheet1 by default, but sometimes the user will change the name without authorization, so it is best to have the user enter the sheet name.
ASP. NET EXCEL5. When reading an excel table, note that some excel files are exported from a program and the html code is directly output to the Excel file using Response, when reading such an excel table, a prompt is displayed.
The "External table is not in the expected format" error occurs. In this case, you need to manually open the excel table and save it again.
ASP. NET EXCEL6 operations, read excel data, the same as operating a common database
- DataSet ds = new DataSet();
- ds.Dispose();
- OleDbDataAdapter da = new OleDbDataAdapter(load_excel, connStr);
- da.Fill(ds);
In this way, the Excel Data is read into ds, and the rest can be operated at will.
ASP. NET Excel is here to introduce you and hope to help you.
- Analysis of ASP. NET database programming technology
- Miscellaneous on the learning path of ASP. NET programmers
- Development Analysis of ASP. NET Custom Controls
- Analysis on the lifecycle of ASP. NET Server controls
- Dynamic Implementation of Excel in ASP. NET