Excel的数据导入到PB的DW中
Excel的数据导入到PB的DW中
//====================================================================
// Event:cb_1::clicked()
//--------------------------------------------------------------------
// Description:两种方法进行
//1、通过数组一行一行读入(定义数据有点麻烦)
//2、通过剪贴板直接
//网友自行选择用哪种方法
//--------------------------------------------------------------------
// Arguments:(None)
//--------------------------------------------------------------------
// Returns:
//--------------------------------------------------------------------
// Author: FlyStone Date: 2008-09-13 17:31:44 Sep
//--------------------------------------------------------------------
// Modify History:
//
//--------------------------------------------------------------------
// Copyright (C) 2007-008 Flystone Co.,Ltd! All rights reserved.
//====================================================================
String ls_path,ls_name
ls_path = "C:\Documents and Settings\Administrator.FLYSTONE\桌面\新建文件夹 (3)\test.xls"
dw_1.Reset() //clean DW
String a[1000,1000]
Integer i,j,li_ret
//li_ret = GetFileopenName('选择XLS',ls_path,ls_name,"XLS","EXCEL (*.XLS;*.XLSX),*.XLS;*.XLSX")
li_ret = GetFileopenName('选择XLS',ls_path,ls_name,"XLS","EXCEL (*.XLS),*.XLS")
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[1] //得到第当前work的第一个sheet
for i = 1 to li_rows
dw_1.insertrow(0)
for j = 1 to li_columns
a[i,j] = string(ExcelServer.ActiveSheet.Cells(i,j).value)
dw_1.Setitem(i,j,a[i,j])
end for
end for
//方法二,利用剪贴板
ExcelServer.ActiveSheet.cells.Copy
dw_1.ImportClipboard(2) //导入数据需要标题
ExcelServer.Application.activeworkbook.Close(False)
ExcelServer.Application.quit()
ExcelServer.DisconnectObject()