ASP reads files in Excel. xls Format

Source: Internet
Author: User

ASP reads Excel files
ASP reads an Excel file and regards the Excel file as an accexx database. A worksheet is considered as a database table, and a column in an Excel table is considered as a field in an access table.
The database connection string is similar to access.
The following two methods can be used to read excel2003 files, that is, Excel files in. xls Format and. XLSX files in 07 files.

'The first connection method:
Set conn = server. Createobject ("ADODB. Connection ")
Driver = "driver = {Microsoft Excel Driver (*. xls )};"
Dbpath = "DBQ =" & server. mappath ("test.xlsx ")
Conn. Open driver & dbpath

'Method 2
'Set conn = server. Createobject ("ADODB. Connection ")
'Connstr = "provider = Microsoft. jet. oledb.4.0; Data Source = "& server. mappath ("test.xls") & "; extended properties = 'excel 8.0; HDR = no; IMEX = 1 ';"

'Here, the HDR value is yes, no, indicating whether the first row is a field name
'Img 1, 2,
'Among them, 1 is the key to solving this problem (some people say that the value 1 can only be resolved if an appeal problem occurs in 16 consecutive rows without confirmation ?)
'
2 of them only find someone to use, but it is not clear what it represents!

'HDR = yes. This indicates that the first line is the title and is not used as data. If HDR = No is used, it indicates that the first line is not the title and used as data. The default value is yes.

 

''Response. Write ("connstr =" & connstr)
'Conn. Open connstr

Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open "select * from [sheet1 $]", Conn, 1, 1

Rows = Rs. recordcount
Cells = Rs. Fields. Count
Response. Write (rows & "," & cells)

 

Because of different systems,CodeThe following error may occur during execution:

Microsoft Jet Database Engine Error '20140901'

Unspecified error

This error is mostly caused by system security.

Solution:Modify the permissions of the temp folder in the C:/Windows/directory.

Write Permission to the user in the temp folder.

run the code again. OK.

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.