Created
May 27, 2014 05:40
A sample ASP (VB) script for reading from an Excel file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
ExcelFile = "c:\temp\unlocodes.xlsx" | |
SQL = "SELECT [ISO 3166-1], [Country Name] FROM [Sheet1$]" | |
Set ExcelConnection = Server.createobject("ADODB.Connection") | |
ExcelConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ExcelFile & ";Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1"";" | |
SET RS = Server.CreateObject("ADODB.Recordset") | |
RS.Open SQL, ExcelConnection | |
Response.Write "<table border=""1""><thead><tr>" | |
FOR EACH Column IN RS.Fields | |
Response.Write "<th>" & Column.Name & "</th>" | |
NEXT | |
Response.Write "</tr></thead><tbody>" | |
IF NOT RS.EOF THEN | |
WHILE NOT RS.eof | |
Response.Write "<tr>" | |
FOR EACH Field IN RS.Fields | |
Response.Write "<td>" & Field.value & "</td>" | |
NEXT | |
Response.Write "</tr>" | |
RS.movenext | |
WEND | |
END IF | |
Response.Write "</tbody></table>" | |
RS.close | |
ExcelConnection.Close | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What to do if we want to read the name of the sheet also and we do not want to hard code that part?