Excel 데이터를 SQL Server로 가져오는 ASP의 코드는 약간 지저분하므로 필요에 따라 찾아볼 수 있습니다. 다음과 같이 코드 코드를 복사합니다.
<form action=insert.asp method=post enctype=multipart/form-data name=form1 onSubmit=b1_onclick()>
<테이블 너비=500 테두리=1 정렬=가운데 셀 패딩=0 셀 간격=0>
<tr>
<td colspan=2 bgcolor=#999999 class=t>파일 선택
</td>
</tr>
<tr>
<td colspan=2 클래스=t> </td>
</tr>
<tr>
<td width=126 class=t>파일 선택(엑셀)
</td>
<td 너비=368 클래스=t><라벨>
<입력 이름=filexls 유형=파일 크기=35>
</label></td>
</tr>
<tr>
<td colspan=2 클래스=t>
<라벨>
<입력 유형=제출 이름=제출 값=데이터 가져오기>
</label>
<a href=1122.asp class=t>반품</a>
</td>
</tr>
</table>
</form>
<!--#include 가상=/inc/clsdbctrl.asp-->
<!--#include 가상=/inc/function.asp-->
<%
희미한 upfile_5xSoft_Stream
수업 업로드_5xSoft
희미한 양식, 파일, 버전
비공개 하위 클래스_초기화
희미한 iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
희미한 strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
버전=런샹의 특별 업로드 프로그램
Request.TotalBytes<1이면 Sub를 종료합니다.
Form=CreateObject(Scripting.Dictionary)를 설정합니다.
File=CreateObject(Scripting.Dictionary) 설정
set upfile_5xSoft_Stream=CreateObject(Adodb.Stream)
upfile_5xSoft_Stream.mode=3
upfile_5xSoft_Stream.type=1
upfile_5xSoft_Stream.open
upfile_5xSoft_Stream.write Request.BinaryRead(Request.TotalBytes)
vbEnter=문자(13)&문자(10)
iDivLen=inString(1,vbEnter)+1
strDiv=하위 문자열(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
iFormStart < iFormEnd 동안
iStart=inString(iFormStart,이름=)
iEnd=inString(iStart+6,)
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,파일 이름=)
iFileNameStart>0 및 iFileNameStart<iFormEnd인 경우
iFileNameEnd=inString(iFileNameStart+10,)
mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
iEnd>iStart이면
mFileSize=iEnd-iStart-4
또 다른
m파일크기=0
종료하면
theFile=new FileInfo를 설정합니다.
theFile.FileName=getFileName(m파일이름)
theFile.FilePath=getFilePath(m파일이름)
theFile.FileSize=m파일 크기
theFile.FileStart=iStart+4
theFile.FormName=양식 이름
file.add mFormName,theFile
또 다른
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
iEnd>iStart이면
mFormValue=subString(iStart+4,iEnd-iStart-4)
또 다른
m양식값=
종료하면
form.mFormName,mFormValue 추가
종료하면
iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
향하게 하다
서브 끝
비공개 함수 subString(theStart,theLen)
디미,c,스템프
upfile_5xSoft_Stream.Position=theStart-1
줄기=
i=1에서 theLen까지
upfile_5xSoft_Stream.EOS인 경우 종료합니다.
c=ascB(upfile_5xSoft_Stream.Read(1))
c > 127이면
upfile_5xSoft_Stream.EOS인 경우 종료합니다.
줄기=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
나=나+1
또 다른
줄기=줄기&Chr(c)
종료 조건
다음
하위 문자열=stemp
기능 종료
개인 함수 inString(theStart,varStr)
희미한 i,j,bt,theLen,str
문자열=0
Str=toByte(varStr)
theLen=LenB(Str)
i=theStart to upfile_5xSoft_Stream.Size-theLen의 경우
i>upfile_5xSoft_Stream.size이면 함수를 종료합니다.
upfile_5xSoft_Stream.Position=i-1
if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) 그러면
InString=i
j=2에서 theLen까지
upfile_5xSoft_Stream.EOS인 경우
문자열=0
다음으로 종료
종료하면
if AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
문자열=0
종료 대상
종료하면
다음
InString<>0이면 함수 종료
종료하면
다음
기능 종료
비공개 하위 클래스_종료
form.RemoveAll
파일.모두 제거
양식 설정 = 없음
파일 설정 = 없음
upfile_5xSoft_Stream.close
setupfile_5xSoft_Stream=아무것도 설정하지 않음
서브 끝
개인 함수 GetFilePath(FullPath)
FullPath <>인 경우
GetFilePath = 왼쪽(FullPath,InStrRev(FullPath, /))
또 다른
GetFilePath =
종료 조건
기능 종료
개인 함수 GetFileName(FullPath)
FullPath <>인 경우
GetFileName = mid(FullPath,InStrRev(FullPath, /)+1)
또 다른
파일이름 가져오기 =
종료 조건
기능 종료
개인 함수 toByte(Str)
희미한 i,iCode,c,iLow,iHigh
toByte=
i=1에서 Len(Str)으로
c=중간(Str,i,1)
아이코드 =Asc(c)
iCode<0이면 iCode = iCode + 65535
iCode>255이면
iLow = 왼쪽(Hex(Asc(c)),2)
iHigh =오른쪽(Hex(Asc(c)),2)
toByte = toByte & chrB(&H&iLow) & chrB(&H&iHigh)
또 다른
toByte = toByte & chrB(AscB(c))
종료 조건
다음
기능 종료
수업 종료
클래스 파일정보
희미한 양식 이름, 파일 이름, 파일 경로, 파일 크기, 파일 시작
비공개 하위 클래스_초기화
파일 이름 =
파일 경로 =
파일 크기 = 0
파일시작= 0
양식 이름 =
서브 끝
공용 함수 SaveAs(FullPath)
희미한 박사,ErrorChar,i
다른 이름으로 저장=1
Trim(fullpath)= 또는 FileSize=0, FileStart=0 또는 FileName=인 경우 함수를 종료합니다.
FileStart=0 또는 right(fullpath,1)=/이면 함수를 종료합니다.
dr=CreateObject(Adodb.Stream) 설정
dr.모드=3
dr.유형=1
닥터오픈
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.copyto dr,파일 크기
dr.SaveToFile FullPath,2
dr.닫기
dr=아무것도 설정하지 않음
다른 이름으로 저장=0
종료 기능
수업 종료
%>
<%
함수 sqlstr(데이터)
isnull(data)이 아니면
sqlstr='& 교체(데이터,','') &'
또 다른
sqlstr='& 데이터 &'
종료하면
종료 기능
%>
<%
세션.코드페이지=936
Server.ScriptTimeOut=600000
업로드=새 upload_5xsoft 설정
파일=upload.file(filexls) 설정
%>
<%
file.fileSize>0이면
파일 이름=연도(현재)&월(현재)&일(현재)&시(현재)&분(현재)&초(현재)
파일명=파일명+.
filenameend=file.filename
filenameshow=file.filename
파일 이름 끝=분할(파일 이름 끝,.)
filenameend(1)=xls인 경우
파일 이름=파일 이름&파일 이름end(1)
file.saveAs Server.mappath(업로드파일/&파일 이름)
또 다른
response.write 데이터 형식이 잘못되었습니다!
response.write <a href=file_upload.asp>반환
응답.끝()
종료하면
파일 설정 = 없음
또 다른
response.write 파일은 비워둘 수 없습니다!
response.write <a href=file_upload.asp>반환
응답.끝()
다음과 같은 경우 종료
업로드 설정 = 없음
'XLS 파일 업로드가 완료되었습니다. 다음으로 업로드된 XLS 파일에서 데이터를 읽어 SQL 데이터베이스에 씁니다.
strAddr=server.MapPath(업로드파일/&파일이름)
excelconn=server.createobject(adodb.connection) 설정
excelconn.open 공급자 = Microsoft.Jet.OLEDB.4.0; 데이터 원본 = +strAddr+;확장 속성='Excel 8.0;HDR=NO;IMEX=1'
rs=server.CreateObject(adodb.recordset) 설정
rs1=server.CreateObject(adodb.recordset) 설정
sql=[Sheet1$]에서 * 선택
rs.open SQL,excelconn,1,3
그렇지 않은 경우(rs.bof 및 rs.eof)
rs.movenext
rs.eof가 아닌 동안 수행
'응답.쓰기(rs(1))
'응답.끝()
sql1=멤버에서 * 선택
rs1.open sql1,conn,1,3
rs1.addnew
무작위화
사용자 이름=
Do While Len(사용자 이름)<8 ' 임의의 비밀번호 숫자
num1=CStr(Chr((57-48)*rnd+48)) '0~9
'num2=CStr(Chr((90-65)*rnd+65)) 'A~Z
num3=CStr(Chr((122-97)*rnd+97)) 'a~z
사용자 이름=사용자 이름&num1&num3
고리
rs1(사용자 이름)=사용자 이름
rs1(비밀번호)=bb0391ec1d7bda99'bamboo123456
rs(0)<>이면
rs1(회사)=rs(0)
종료하면
rs(1)<>이면
rs1(실명)=rs(1)
종료하면
rs(2)<>이면
rs1(성별)=성별n(rs(2))
종료하면
rs(3)<>이면
rs1(교수)=rs(3)
종료하면
rs(4)<>이면
rs1(전화)=rs(4)
종료하면
rs(5)<>이면
rs1(모바일)=rs(5)
종료하면
rs(6)<>이면
rs1(주소)=rs(6)
종료하면
rs(7)<>이면
rs1(지역)=getclassdname(rs(7),지역,cn)
종료하면
rs(8)<>이면
rs1(도시)=getclassdname(rs(8),지역,cn)
종료하면
rs(9)<>이면
rs1(팩스)=rs(9)
종료하면
rs(10)<>이면
rs1(컴타입)=컴타입m(rs(10))
종료하면
rs(11)<>이면
rs1(작업)=rs(11)
종료하면
rs1(통과)=1
rs1(활성화)=1
rs1(마지막 로그인 시간)=지금()
rs1.업데이트
RS1.닫기
rs.movenext
고리
종료하면
RS.닫기()
rs=아무것도 설정하지 않음
rs1=아무것도 설정하지 않음
엑셀콘.닫기()
excelconn=아무것도 설정하지 않음
연결.닫기()
conn=아무것도 설정하지 않음
함수 sexn(str)
케이스 문자열 선택
케이스 남성
섹스n=0
케이스 여성
섹스n=1
선택 종료
종료 기능
함수컴타입m(str)
케이스 문자열 선택
케이스 대나무 제품
컴타입=0
케이스 대나무 기계
컴타입=1
선택 종료
종료 기능
함수 getclassdname(str,테이블 이름,lang)
IsNumeric(id)이 아니면 함수 종료
set rs2=conn.execute(& 테이블 이름 및 '%&str&%'와 같은 클래스 이름에서 상위 1개 ID 선택)
그렇지 않은 경우 rs2.eof 그런 다음
만약 lang<> 그렇다면
lang=cn이면
getclassdname=getclassdname & rs2(0)
ElseIf lang=en 그러면
getclassdname=getclassdname & rs2(0)
종료 조건
종료 조건
또 다른
getclassdname=0
종료하면
RS2.닫기
기능 종료
%>
<테이블 너비=300 테두리=1 정렬=가운데 셀패딩=0 셀 간격=0 테두리색상=#CCCCCC>
<tr>
<th bordercolor=#F1F3F8 bgcolor=#999999 class=t 범위=행> </th>
</tr>
<tr>
<th class=t range=row>파일<% response.write (filenameshow) %>가져오기에 성공했습니다! </th>
</tr>
<tr>
<th class=t range=row><a href=javascript:self.close() class=t>창 닫기</a></th>
</tr>
<tr>
<th class=t range=row><a href=1122.asp class=t>반품</a></th>
</tr>
</table>