Skip to content

Instantly share code, notes, and snippets.

@patcullen
Created May 27, 2014 05:40
Show Gist options
  • Save patcullen/9a51295350f0c33dae34 to your computer and use it in GitHub Desktop.
Save patcullen/9a51295350f0c33dae34 to your computer and use it in GitHub Desktop.
A sample ASP (VB) script for reading from an Excel file
<%
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
%>
@sritamonline
Copy link

What to do if we want to read the name of the sheet also and we do not want to hard code that part?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment