PB导入EXCEL(XLS或XLSX)到数据窗口
// Description:两种方法进行//1、通过数组一行一行读入(定义数据有点麻烦)
//2、通过剪贴板直接
//方法一:
//====================================================================
String ls_path,ls_name
ls_path = "C:\Documents and Settings\Administrator.FLYSTONE\桌面\新建文件夹 (3)\test.xls"
dw_1.Reset() //clean DW
String a
Integer i,j,li_ret
//li_ret = GetFileopenName('选择XLS',ls_path,ls_name,"XLS","EXCEL (*.XLS),*.XLS")
li_ret = GetFileopenName('请选择EXCEL文件',ls_path,ls_name,"XLS","EXCEL (*.XLS;*.XLSX),*.XLS;*.XLSX")
if li_ret <> 1 then return
OLEObject ExcelServer
Int li_ConnectErr
ExcelServer = Create OLEObject
li_ConnectErr = ExcelServer.ConnectToNewObject( "excel.application" )
If li_ConnectErr < 0 Then
Choose Case li_ConnectErr
Case - 1
MessageBox('错误提示','无效的调用')
Case - 2
MessageBox('错误提示','类名没发现')
Case - 3
MessageBox('错误提示','对象不能创建')
Case - 4
MessageBox('错误提示','文件不能连接')
Case - 5
MessageBox('错误提示','不能连接现在的对象')
Case - 6
MessageBox('错误提示','文件无效')
Case - 7
MessageBox("错误提示","文件不存在或已经打开")
Case - 8
MessageBox("错误提示","服务器不能装载选择的文件")
Case - 9
MessageBox("错误提示","其他错误")
End Choose
Return
End If
ExcelServer.Workbooks.Open(ls_path,0,False)
//对XLS文件进行了改动以后,在关闭该文件时是否需要向用户提出警告:剪贴板提示信息。
ExcelServer.Application.DisplayAlerts = False
//选择sheets表
//ExcelServer.activeworkbook.worksheets("sheet2").Select()
Int li_rows,li_columns
li_rows = ExcelServer.ActiveSheet.UsedRange.Rows.Count //取得总行数
li_columns = ExcelServer.ActiveSheet.UsedRange.columns.Count //取得总行数
// # of columns in excel
//sle_2.Text = TRIM(STRING(li_rows))
// # of rows in excel
//sle_1.Text = STRING(li_columns)
//lole_sheet = ole_1.Application.ActiveWorkbook.WorkSheets //得到第当前work的第一个sheet
datetime ld_rq
string ls_jybz,ls_dkr,ls_dkbz,ls_billType
dec ld_je
long li_row
for i = 2 to li_rows
ld_rq = datetime(date(ExcelServer.ActiveSheet.Cells(i,1).value),time('00:00:00'))
ls_jybz = string(ExcelServer.ActiveSheet.Cells(i,2).value)
ld_je = dec(ExcelServer.ActiveSheet.Cells(i,3).value)
ls_dkr = string(ExcelServer.ActiveSheet.Cells(i,4).value)
ls_billType = string(ExcelServer.ActiveSheet.Cells(i,5).value)
li_row = dw_1.insertrow(0)
dw_1.setitem(li_row, 'rq',ld_rq)
dw_1.setitem(li_row, 'jybz',ls_jybz)
dw_1.setitem(li_row, 'je',ld_je)
dw_1.setitem(li_row, 'dkr',ls_dkr)
dw_1.setitem(li_row, 'dkbz',ls_dkbz)
dw_1.setitem(li_row, 'BillType',ls_billType)
next
//方法二:
string str_savename,named,s_grxh
int excelok,li_net
longli_count,i
oleobject excelserver
excelserver = create oleobject
excelok = excelserver.connecttonewobject("excel.application")
//检查返回值,以确保已成功地连接到了Excel
if excelok <> 0 then
messagebox("信息提示","连接EXCEL失败,请检查计算机中是否安装了EXCEL!")
return - 1
end if
li_net = GetFileOpenName("选择文件",str_savename,named,"xls","Excel文件(*.xls),*.xls")
if li_net > 0 then
if str_savename = "" then return - 1
dw_1.settransobject(sqlca)
dw_1.reset()
excelserver.workbooks.open(str_savename)
excelserver.activesheet.cells.copy
li_count = dw_1.importclipboard(2) //导入数据
clipboard("")
excelserver.quit()
excelserver.disconnectobject()
destroy excelserver
return 1
else
messagebox('信息提示','没有指定导入文件!')
return - 1
end if
页:
[1]