직접적으로는 Excel 매크로로 하는것이 편리합니다만..
웹에서 필요한 경우가 있어서..정리해보았습니다.
Excel 파일 읽어서 디비에 넣기 샘플 소스입니다.
업로드 파일을 읽어서 집어 넣고 블라블라 하는 방식으로도 응용가능.
Excel 버전에 따라 Provider 변경할 것
- Provider=Microsoft.ACE.OLEDB.12.0; ' 2007 이상
- Provider=Microsoft.Jet.OLEDB.4.0; ' 2003 이하
<%@codepage = "65001"%> <%session.codepage = "65001"%> <% Response.CharSet = "utf-8" Response.AddHeader "Pragma","no-cache" Response.AddHeader "Expires","0" Set DbCon = Server.CreateObject("ADODB.Connection") Set DbCon2 = Server.CreateObject("ADODB.Connection") conn = "Provider=SQLOLEDB.1;Password=패스워드;Persist Security Info=True;User ID=아이디;Initial Catalog=디비명;Data Source=아이피" DbCon.Open conn conn2 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=파일경로; Extended Properties=Excel 12.0;" DbCon2.Open conn2 sql = "Select * FROM [Sheet3$]" Set Rs = dbcon2.execute(sql) Do until Rs.EOF SQL = "INSERT INTO tblMember (id,pw) VALUES ( N'" & Rs(0) & "', N'" & Rs(1) & "' ) " DBCon.Execute(sql) Rs.movenext Loop Rs.Close Set Rs = Nothing Set DbCon = Nothing Set DbCon2 = Nothing Response.Write "<SCRIPT LANGUAGE='JavaScript'> alert('등록되었습니다.'); </SCRIPT>" %> <%session.codepage = 949%>