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