본문 바로가기
Developer/asp

xls 파일 읽어오기

by MindOpener 2015. 6. 15.
반응형
'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.xls") & "; "
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


반응형