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.