Example of using JS example to obtain Excel

Source: Internet
Author: User
<%
''
'*************************************** ******************
'Purpose: to obtain the Excel Data and insert it to the data records in the same time. The data records are successful and missing.
'Ingress entry:
'Back:
'*************************************** ******************
Function getexcel ()
Dim Conn
Dim strconn
Dim rs
Dim SQL
File = ""
Set conn = server. Createobject ("ADODB. Connection ")
Strconn = "driver = {Microsoft Excel Driver (*. xls)}; DBQ =" & server. mappath ("excel_data.xls ")
''Strconn = "provider = Microsoft. Jet. oledb.4.0; Data source=dd.xls; extended properties = Excel 8.0"
Conn. Open strconn
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * from [sheet1 $]"
Rs. Open SQL, Conn, 2, 2
''Then, use the field name in Excel and check whether the field sequence is correct.
For I = 0 to Rs. Fields. Count-1
File_head = file_head & RS (I). Name
Next
''Response. Write file_head
If trim (file_head) <> "This version uses the single-digit category description the retention period of the specified category name is classified as" then"
Response. Write "<script language = 'javascript '> alert !! ') </SCRIPT>"
Exit Function
End if
''Retrieve information in Excel
Do while not Rs. EOF
''Insert the retrieved data into the Oracle database
For I = 0 to Rs. Fields. Count-1
Edition = RS (0)
File_code = RS (2) + RS (3) + RS (4) + RS (5)
File_name = RS (9)
Kindincludesc = RS (6)
Kind2_desc = RS (7)
Kind3_desc = RS (8)
Kind4_desc = RS (9)
Save_year = RS (10)
File_unit = RS (1)
Com_file_code = RS (11)
''===================================================== ==========
Checed_ SQL = "select nvl (file_case,'') file_case from odm67 where edition = '"& trim (Edition) &"' and file_code = '"& trim (file_code) &"'"
If mobjdb. opensql (checed_ SQL) then
If mobjdb. isempty then
File_case = "0001"
Case_desc = "general case"
Ins_ SQL = ""
Ins_ SQL = ins_ SQL & "insert into odm67 (" & vbcrlf
Ins_ SQL = ins_ SQL & "edition, file_code, file_case," & vbcrlf
Ins_ SQL = ins_ SQL & "case_desc, crt_user, crt_date," & vbcrlf
Ins_ SQL = ins_ SQL & "crt_time, mdf_user, mdf_date, mdf_time)" & vbcrlf
Ins_ SQL = ins_ SQL & "values (" & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (Edition) & "', '" & trim (file_code) & "'," & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (file_case) & "', '" & trim (case_desc) & "'," & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (Session ("user_id") & "', '" & trim (today) & "'," & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (nowtime) & "', '" & trim (Session ("user_id") & "'," & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (today) & "', '" & trim (nowtime )&"')"
Call mobjdb. execsql (ins_ SQL)
End if
End if
''===================================================== ==========
Ins_ SQL = ""
Ins_ SQL = ins_ SQL & "insert into odm61 (" & vbcrlf
Ins_ SQL = ins_ SQL & "edition, file_code, file_name, kind1_desc," & vbcrlf
Ins_ SQL = ins_ SQL & "kind2_desc, kind3_desc, kind4_desc, save_year," & vbcrlf
Ins_ SQL = ins_ SQL & "file_unit, com_file_code, crt_user, crt_date," & vbcrlf
Ins_ SQL = ins_ SQL & "crt_time, mdf_user, mdf_date, mdf_time)" & vbcrlf
Ins_ SQL = ins_ SQL & "values (" & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (Edition) & "', '" & trim (file_code) & "'," & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (file_name) & "', '" & trim (kindshortdesc) & "'," & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (kind2_desc) & "', '" & trim (kind3_desc) & "'," & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (kind4_desc) & "', '" & trim (save_year) & "'," & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (file_unit) & "', '" & trim (com_file_code) & "'," & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (Session ("user_id") & "', '" & trim (today) & "'," & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (nowtime) & "', '" & trim (Session ("user_id") & "'," & vbcrlf
Ins_ SQL = ins_ SQL & "'" & trim (today) & "', '" & trim (nowtime )&"')"
''Response. Write ins_ SQL & "<br>"
If mobjdb. execsql (ins_ SQL) then
Incount = incount + 1
Else
Nocount = nocount + 1
File = file & today & "" & nowtime & "& edition &" "& file_code & vbcrlf
End if
Exit
Next
Rs. movenext
Loop
Rs. Close
Set rs = nothing
Conn. Close
Set strconn = nothing
If file <> "" then
Call createfolder ()
Call setfile (file)
Strpath = server. mappath ("excel_data.xls ")
Call deletefolder (strpath)
File = ""
End if

End Function
'*************************************** ******************
'Purpose: to create a specified object. If the object exists, the object is not created and the object is appended with another object.
'Appended input: file: number of data to be appended
'Back:
'*************************************** ******************
Function setfile (file)
File_path = "C: \ log \ od60err. log"
Set fstemp = server. Createobject ("scripting. FileSystemObject ")
If (fstemp. fileexists (file_path) then
Else
Set filetemp = fstemp. createtextfile (file_path, true)
Filetemp. writeline "missing metadata"
Filetemp. Close
End if
'''Append the loss information opentextfile
Set filetemp = fstemp. opentextfile (file_path, 8, true)
Filetemp. writeline File
Filetemp. Close
Set filetemp = nothing
Set fstemp = nothing
End Function
'*************************************** ******************
'Purpose: to create a specified file region. If the file exists, it is not created.
'Ingress entry:
'Back:
'*************************************** ******************
Function createfolder ()
Dim FSO, F
Folder = "C: \ log"
Set FSO = Createobject ("scripting. FileSystemObject ")
If FSO. folderexists (folder) then
Else
Set F = FSO. createfolder (folder)
Createfolderdemo = f. Path
End if
End Function
'*************************************** ******************
'Purpose: to remove the objects in the upper limit,
'Ingress inbound: The ingress of the Upload File
'Back:
'*************************************** ******************
Function deletefolder (filepath)
Dim FSO, F
Folder = "excel_data.xls"
Set FSO = Createobject ("scripting. FileSystemObject ")
''Response. Write FSO. fileexists (filepath)
If FSO. fileexists (filepath) then
FSO. deletefile filepath
End if
End Function
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.