Excel データを SQL Server にインポートする ASP のコードは少し複雑なので、必要に応じて調べてください。次のようにコードをコピーします。
<form action=insert.asp method=post enctype=multipart/form-data name=form1 onSubmit=b1_onclick()>
<table width=500 border=1 align=center cellpadding=0 cellpacing=0>
<tr>
<tdcolspan=2 bgcolor=#999999 class=t>ファイルを選択
</td>
</tr>
<tr>
<td Colspan=2 class=t> </td>
</tr>
<tr>
<td width=126 class=t>ファイルの選択 (Excel)
</td>
<td width=368 class=t><label>
<入力名=filexls タイプ=ファイルサイズ=35>
</label></td>
</tr>
<tr>
<td Colspan=2 class=t>
<ラベル>
<入力タイプ=送信名=送信値=データのインポート>
</label>
<a href=1122.asp class=t>戻る</a>
</td>
</tr>
</テーブル>
</form>
<!--#include virtual=/inc/clsdbctrl.asp-->
<!--#include virtual=/inc/function.asp-->
<%
薄暗いアップファイル_5xSoft_Stream
クラスアップロード_5xSoft
dim フォーム、ファイル、バージョン
プライベートサブクラス_初期化
dim iStart、iFileNameStart、iFileNameEnd、iEnd、vbEnter、iFormStart、iFormEnd、ファイル
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
バージョン=Ren Xiang の特別アップロード プログラム
Request.TotalBytes<1 の場合は Sub を終了します
set Form=CreateObject(Scripting.Dictionary)
set 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=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
iStart=inString(iFormStart,name=)
iEnd=inString(iStart+6,)
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,filename=)
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
それ以外
mFileSize=0
終了する場合
ファイル=新しいファイル情報を設定します
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=フォーム名
file.add mFormName、ファイル
それ以外
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
iEnd>iStart の場合
mFormValue=subString(iStart+4,iEnd-iStart-4)
それ以外
mFormValue=
終了する場合
form.Add mFormName、mFormValue
終了する場合
iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
曲がります
エンドサブ
プライベート関数 subString(theStart,theLen)
ディミ、C、ステンプ
upfile_5xSoft_Stream.Position=theStart-1
ステンプ=
for i=1 から theLen
upfile_5xSoft_Stream.EOS の場合は終了します
c=ascB(upfile_5xSoft_Stream.Read(1))
c > 127 の場合
upfile_5xSoft_Stream.EOS の場合は終了します
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
i=i+1
それ以外
stemp=stemp&Chr(c)
終了の場合
次
サブ文字列=温度
終了機能
プライベート関数 inString(theStart,varStr)
薄暗い i、j、bt、theLen、str
文字列=0
Str=toByte(varStr)
theLen=LenB(Str)
for 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 の場合
inString=0
終了
終了する場合
if AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
文字列=0
出口
終了する場合
次
if InString<>0 then 関数を終了
終了する場合
次
終了機能
プライベートサブクラス_Terminate
form.RemoveAll
file.RemoveAll
フォーム=何も設定しない
ファイル=何も設定しない
upfile_5xSoft_Stream.close
set upfile_5xSoft_Stream=なし
エンドサブ
プライベート関数 GetFilePath(FullPath)
フルパス <> の場合
GetFilePath = left(FullPath,InStrRev(FullPath, /))
それ以外
GetFilePath =
終了の場合
終了機能
プライベート関数 GetFileName(FullPath)
フルパス <> の場合
GetFileName = Mid(FullPath,InStrRev(FullPath, /)+1)
それ以外
GetFileName =
終了の場合
終了機能
プライベート関数 toByte(Str)
ディム i、iCode、c、iLow、iHigh
toByte=
i=1 の場合、Len(Str) まで
c=mid(Str,i,1)
iCode =Asc(c)
iCode<0 の場合、iCode = iCode + 65535
iCode > 255 の場合
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB(&H&iLow) & chrB(&H&iHigh)
それ以外
toByte = toByte & chrB(AscB(c))
終了の場合
次
終了機能
終了クラス
クラスファイル情報
dim フォーム名、ファイル名、ファイルパス、ファイルサイズ、ファイル開始
プライベートサブクラス_初期化
ファイル名 =
ファイルパス =
ファイルサイズ = 0
ファイル開始= 0
フォーム名 =
エンドサブ
パブリック関数 SaveAs(FullPath)
dim dr、ErrorChar、i
名前を付けて保存=1
トリム(フルパス)= または FileSize=0 または FileStart=0 または FileName= の場合、関数を終了します
FileStart=0 または right(fullpath,1)=/ の場合、関数を終了します
set dr=CreateObject(Adodb.Stream)
博士モード=3
dr.Type=1
ドクターオープン
upfile_5xSoft_Stream.position=ファイル開始-1
upfile_5xSoft_Stream.dr にコピー、ファイルサイズ
dr.SaveToFile フルパス、2
ドクタークローズ
dr=何も設定しない
名前を付けて保存=0
終了関数
終了クラス
%>
<%
関数 sqlstr(データ)
isnull(data) でない場合は、
sqlstr='& replace(データ,','') &'
それ以外
sqlstr='& データ &'
終了する場合
終了関数
%>
<%
セッション.コードページ=936
Server.ScriptTimeOut=600000
アップロード=新しいupload_5xsoftを設定します
set file=upload.file(filexls)
%>
<%
file.fileSize>0 の場合
ファイル名=年(現在)&月(現在)&日(現在)&時間(現在)&分(現在)&秒(現在)
ファイル名=ファイル名+。
ファイル名終了=ファイル.ファイル名
ファイル名表示=ファイル.ファイル名
filenameend=split(filenameend,.)
filenameend(1)=xls の場合
ファイル名=ファイル名&ファイル名終了(1)
file.saveAs Server.mappath(uploadfiles/&ファイル名)
それ以外
応答.write データ形式が間違っています!
response.write <a href=file_upload.asp>return
応答.end()
終了する場合
ファイル=何も設定しない
それ以外
response.write ファイルを空にすることはできません。
response.write <a href=file_upload.asp>return
応答.end()
次の場合に終了
アップロード = なしを設定します
'XLS ファイルのアップロードが完了しました。次に、アップロードされた XLS ファイルからデータを読み取り、SQL データベースに書き込みます。
strAddr=server.MapPath(アップロードファイル/&ファイル名)
set Excelconn=server.createobject(adodb.connection)
Excelconn.open プロバイダ = Microsoft.Jet.OLEDB.4.0; データ ソース = +strAddr+;拡張プロパティ = 'Excel 8.0;HDR=NO;IMEX=1'
set rs=server.CreateObject(adodb.recordset)
set rs1=server.CreateObject(adodb.recordset)
sql=select * from [Sheet1$]
rs.open SQL、Excelconn、1、3
そうでない場合 (rs.bof および rs.eof)
rs.movenext
rs.eof ではないときに実行します
'response.Write(rs(1))
'response.End()
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
if rs(0)<> then
rs1(会社)=rs(0)
終了する場合
if rs(1)<> then
rs1(本名)=rs(1)
終了する場合
if rs(2)<> then
rs1(性別)=sexn(rs(2))
終了する場合
if rs(3)<> then
rs1(教授)=rs(3)
終了する場合
if rs(4)<> then
rs1(電話)=rs(4)
終了する場合
if rs(5)<> then
rs1(モバイル)=rs(5)
終了する場合
if rs(6)<> then
rs1(アドレス)=rs(6)
終了する場合
if rs(7)<> then
rs1(エリア)=getclassdname(rs(7),エリア,cn)
終了する場合
if rs(8)<> then
rs1(都市)=getclassdname(rs(8),エリア,cn)
終了する場合
if rs(9)<> then
rs1(ファックス)=rs(9)
終了する場合
if rs(10)<> then
rs1(comtype)=comtypem(rs(10))
終了する場合
if rs(11)<> then
rs1(操作)=rs(11)
終了する場合
rs1(合格)=1
rs1(アクティブ化)=1
rs1(最終ログイン時間)=now()
rs1.アップデート
rs1.close
rs.movenext
ループ
終了する場合
rs.close()
rs=何も設定しない
rs1=何も設定しない
Excelconn.Close()
Excelconn=何も設定しない
conn.close()
conn=何も設定しない
関数 sexn(str)
大文字と小文字の文字列を選択
男性の場合
セックスn=0
ケース女性
セックスn=1
エンドセレクト
終了関数
関数comtypem(str)
大文字と小文字の文字列を選択
ケース竹製品
comtypem=0
ケース竹機械
comtypem=1
エンドセレクト
終了関数
関数 getclassdname(str,tablename,lang)
IsNumeric(id) でない場合は関数を終了する
set rs2=conn.execute (上位 1 つの ID を選択 & テーブル名 & クラス名は '%&str&%' など)
rs2.eof ではない場合
If lang<> then
lang=cn の場合
getclassdname=getclassdname & rs2(0)
ElseIf lang=en then
getclassdname=getclassdname & rs2(0)
終了の場合
終了の場合
それ以外
getclassdname=0
終了する場合
rs2.close
終了機能
%>
<table width=300 border=1 align=center cellpadding=0 cellpacing=0 bordercolor=#CCCCCC>
<tr>
<th bordercolor=#F1F3F8 bgcolor=#999999 class=tscope=row> </th>
</tr>
<tr>
<th class=tscope=row>ファイル<%response.write (filenameshow) %>インポートに成功しました。 </th>
</tr>
<tr>
<th class=tscope=row><a href=javascript:self.close() class=t>ウィンドウを閉じる</a></th>
</tr>
<tr>
<th class=tscope=row><a href=1122.asp class=t>戻る</a></th>
</tr>
</テーブル>