Notes on Excel operations using ASP. NET

Source: Internet
Author: User

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

 
 
  1. DataSet ds = new DataSet();  
  2. ds.Dispose();  
  3. OleDbDataAdapter da = new OleDbDataAdapter(load_excel, connStr);  
  4. 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.

  1. Analysis of ASP. NET database programming technology
  2. Miscellaneous on the learning path of ASP. NET programmers
  3. Development Analysis of ASP. NET Custom Controls
  4. Analysis on the lifecycle of ASP. NET Server controls
  5. Dynamic Implementation of Excel in ASP. NET

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.