ADO. NET Access EXCEL (learning notes)

Source: Internet
Author: User

// Connection string
String xlsPath = Server. MapPath ("~ /App_data/somefile.xls "); // absolute physical path
String connStr = "Provider = Microsoft. Jet. OLEDB.4.0;" +
"Extended Properties = Excel 8.0;" +
"Data source =" + xlsPath;
// Query statement


String SQL = "SELECT * FROM [Sheet1 $]";

 

 

 

1. When the data provider uses Jet, you must specify the Extended Properties keyword to set specific Excel attributes. Different Versions of Excel correspond to different attribute values.
2. Use the physical absolute path for the Data Source Path
3. How to reference A Table Name:
A valid reference to a table (or range) in an Excel Workbook.
To reference the fully used worksheet range, specify the worksheet name followed by the dollar sign. For example:
Select * from [Sheet1 $]
To reference a specific address range on a worksheet, specify the worksheet name that follows the dollar sign and the range. For example:
Select * from [Sheet1 $ A1: B10]
To reference a specified range, use the name of the range. For example:
Select * from [MyNamedRange]


 

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.