global type gf_import_excel from function_object
end type
forward prototypes
global subroutine gf_import_excel (datawindow idw_dw)
end prototypes
global subroutine gf_import_excel (datawindow idw_dw);string path,filename
integer value,result
value = GetFileOpenName("Select File",path,filename,"xls","xls Files (*.xls),*.xls,Text Files (*.TXT),*.TXT,DBF Files (*.DBF),*.DBF")
if value<>1 then return
if right(path,3)='xls' or right(path,3)='XLS' then
OLEObject ObjExcel
ObjExcel = CREATE OLEObject
result = ObjExcel.ConnectToNewObject( "excel.application")
if result <> 0 then
messagebox("信息提示","连接EXCEL失败,请检查计算机中是否安装了EXCEL!")
Return
else
ObjExcel.Workbooks.Open(path) //ls_rj是文件的路径
ObjExcel.ActiveSheet.Cells.Copy
ObjExcel.Application.Visible = false
idw_dw.SetTransObject(SQLCA)
idw_dw.ImportClipboard(2) //将系统剪切版上的内容粘贴到数据窗口中,其中2为起始行参数
Clipboard("") //请空剪切版上的内容
ObjExcel.Quit()
ObjExcel.DisconnectObject() //断开与OLE的连接
Destroy ObjExcel
end if
elseif right(path,3)='txt' or right(path,3)='TXT' then
idw_dw.importfile(path,2)
elseif right(path,3)='dbf' or right(path,3)='DBF' then
idw_dw.importfile(path,1)
end if
end subroutine