<%

         Set DBCon = CreateObject("ADODB.Connection")

         dbCon.Open "file name=D:\wwwroot\util\Excel\strDB.udl"

        

         'pathXsl = Server.MapPath("\")&"\excel\excel_2.xls"

         pathXslFile = "D:\wwwroot\util\Excel\excel.xls"

        

         Set objFs   = CreateObject("Scripting.FileSystemObject")

         Set objFile = objFs.CreateTextFile(pathXslFile, true)

 

         SQL = "Select id, comp_nm, dept_nm " &_

                    "  From compinfo"

          

         Response.Write "SQL             :" & SQL & "<br>"

         Response.Write "생성될 파일경로 :" & pathXslFile

        

         Set Rs    = CreateObject("ADODB.RecordSet")

         Rs.open SQL, DBCon

                  

         ' 셀의 제목이 될 부분

         ' " " 부분을 탭으로 밀어주면 필드별로 입력

         xlsLine = "       "  

         xlsLine = xlsLine & "번호"   & "   "

         xlsLine = xlsLine & "업체명" & "   "

         xlsLine = xlsLine & "부서"   & "   "

 

        ' 실제 Excel 파일에 쓰기

         objFile.WriteLine(xlsLine)

        

         ' 셀의 값이 될 부분

         DO UNTIL Rs.EOF

                  xlsLine = "       "

                  xlsLine = xlsLine & rs(0) & "      "

                  xlsLine = xlsLine & rs(1) & "      "

                  xlsLine = xlsLine & rs(2) & "      "

                 

                  objFile.WriteLine(xlsLine)

 

                  Rs.MoveNext

         LOOP

%>

 

출처:http://cafe.naver.com/webzero0/279 

반응형

+ Recent posts