PB import Excel files

Source: Internet
Author: User

Int li_row, li_rowcount
Int li_xlsrow, li_xlsrowcount
Int li_connect, li_ret
String ls_path, ls_filename
String ls_class, ls_id, ls_name
String ls_xblimit, ls_lxlimit
String ls_pym
Oleobject excelserver

Li_ret = getfileopenname ('select an Excel file', ls_path, ls_filename, "xls", "Excel (*. xls; *. XLSX), *. xls; *. XLSX ")
If li_ret <> 1 then return-1

F_prompt ("connecting to excel. application ")
Excelserver = create oleobject
/* Connect to the Excel Service */
Li_connect = excelserver. connecttonewobject ("Excel. application ")
If li_connect <0 then
MessageBox ("prompt! "," An error occurred while connecting to the Excel. application! ")
Return-1
End if

F_prompt ("Open Excel document ")
Excelserver. workbooks. Open (ls_path)
/* Whether to warn the user when closing the file. */
Excelserver. application. displayalerts = false

Excelserver. activeworkbook. worksheets (2). Select ()
Li_xlsrowcount = excelserver. activesheet. usedrange. Rows. Count

If li_xlsrowcount <= 0 then return-1
For li_xlsrow = 1 to li_xlsrowcount
Yield ()
F_prompt ("import" + ls_id + "-" + ls_name)
Ls_class = string (excelserver. activesheet. cells (li_xlsrow, 1). value)
Ls_id = string (excelserver. activesheet. cells (li_xlsrow, 2). value)
Ls_name = string (excelserver. activesheet. cells (li_xlsrow, 3). value)
Ls_xblimit = string (excelserver. activesheet. cells (li_xlsrow, 4). value)
Ls_lxlimit = string (excelserver. activesheet. cells (li_xlsrow, 5). value)
Ls_pym = f_getpy (ls_name)

Li_row = dw_import.insertrow (0)
Dw_import.setitem (li_row, 'class', ls_class)
Dw_import.setitem (li_row, 'id', ls_id)
Dw_import.setitem (li_row, 'name', ls_name)
Dw_import.setitem (li_row, 'xblimit ', ls_xblimit)
Dw_import.setitem (li_row, 'lxlimit ', ls_lxlimit)
Dw_import.setitem (li_row, 'pym', ls_pym)
Next
F_prompt ("Close Excel document ")
Excelserver. activeworkbook. Close ()
Excelserver. Quit ()
Excelserver. disconnectobject ()
Destroy excelserver
F_prompt ("")
MessageBox ("prompt", "Import complete! ")

Return 1

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.