Skip to content

Instantly share code, notes, and snippets.

@JunaidQadirB
Created November 23, 2015 04:41
Show Gist options
  • Save JunaidQadirB/00d61798cd3218e7e80b to your computer and use it in GitHub Desktop.
Save JunaidQadirB/00d61798cd3218e7e80b to your computer and use it in GitHub Desktop.
<%
SUB reacExcelFile(fileName)
'initialize variables
Dim objConn, strSQL
Dim x
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DRIVER={Microsoft Excel Driver (*.xls)}; IMEX=1; HDR=NO; "&_
"Excel 8.0; DBQ=" & Server.MapPath(fileName) & "; "
strSQL = "SELECT * FROM A1:G1000"
Response.Write("<table border=""1"">")
Response.Write("<tr>")
'write all columnNames
For x=0 To objRS.Fields.Count-1
Response.Write("<th>" & objRS.Fields(x).Name & "</th>")
Next
Response.Write("</tr>")
Do Until objRS.EOF
' write as much columns as there are in your excel file
Response.Write("<td>" & objRS.Fields(0).Value & "</td>")
Response.Write("<td>" & objRS.Fields(1).Value & "</td>")
Response.Write("<td>" & objRS.Fields(2).Value & "</td>")
Response.Write("<td>" & objRS.Fields(3).Value & "</td>")
Response.Write("<td>" & objRS.Fields(4).Value & "</td>")
Response.Write("<td>" & objRS.Fields(5).Value & "</td>")
Response.Write("<td>" & objRS.Fields(6).Value & "</td>")
objRS.Close
Response.Write("</table>")
Set objRS=Nothing
END SUB
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment