본문 바로가기

classic asp

[classic asp] 엑셀파일 읽기

https://www.microsoft.com/ko-kr/download/details.aspx?id=54920에서 드라이버 다운로드.

32비트는 그냥 설치하면 되지만, 64비트는 cmd 에서 accessdatabaseengine_X64.exe /passive 으로 설치해야 함.

 

<%
Dim dextUp
Set dextUp = SERVER.CREATEOBJECT("dext.fileupload")
dextUp.DefaultPath = Server.Mappath("./") & "\temp"

Dim attachExcel, dmFileName
attachExcel = dextUp("attachExcel").Save( ,False) '업로드한 엑셀파일
Set dextUp = Nothing

Dim excelCon
Dim conString
Set excelCon = Server.CreateObject("ADODB.Connection")
conString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & attachExcel & "; Extended Properties='Excel 12.0;HDR=YES;IMEX=1'"
excelCon.Open conString

Dim adox, SheetName
Set adox = CreateObject("adox.catalog")
adox.ActiveConnection = conString
SheetName = adox.Tables(0).Name
Set adox = Nothing

Dim userID, userName, userTel
Sql = "SELECT 아이디, 이름, 전화 FROM [" & SheetName & "] "
Set adoRecord = Server.CreateObject("adodb.recordset")
adoRecord.Open Sql, excelCon, 1
Do Until adoRecord.EOF
	userID = adoRecord.Fields(0)
	userName = adoRecord.Fields(1)
	userTel = adoRecord.Fields(2)
	
	Response.Write "아이디:" & userID & " / "
	Response.Write "이름:" & userName & " / "
	Response.Write "전화:" & userTel & " / "
	Response.Write "<br>"
	
	adoRecord.MoveNext
Loop
adoRecord.Close
Set adoRecord = Nothing

excelCon.Close
Set excelCon = Nothing
%>