想做以下功能:
将excel表里某个sheet的数据批量导入到access数据库的某个表里面,数据结构一致的,怎么实现?
------解决方案--------------------
下面代码存为f_excel.srf导入到你的PBL里
参数:需要导入EXCEL数据的数据窗口名
- C/C++ code
$PBExportHeader$f_excel.srfglobal type f_excel from function_objectend typeforward prototypesglobal subroutine f_excel (datawindow idw_dw)end prototypesglobal subroutine f_excel (datawindow idw_dw);string path,filenameinteger value,resultvalue = GetFileOpenName("Select File",path,filename,"xls","xls Files (*.xls),*.xls,Text Files (*.TXT),*.TXT,DBF Files (*.DBF),*.DBF")if value<>1 then returnif 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) string ls_copy int i if ObjExcel.ActiveSheet.Cells.Copy = true then ObjExcel.Application.Visible = false idw_dw.SetTransObject(SQLCA) i = idw_dw.ImportClipboard(2) //将系统剪切版上的内容粘贴到数据窗口中,其中2为起始行参数 Clipboard("") //清空剪切版上的内容 ObjExcel.Quit() ObjExcel.DisconnectObject() //断开与OLE的连接 Destroy ObjExcel else messagebox("提示","您的EXCEL不支持此功能,请检查EXCEL版本,建议使用OFFICE-EXCEL") end ifend 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 ifend subroutine
------解决方案--------------------
在ObjExcel.Workbooks.Open(path)后面加上:
ObjExcel.activeworkbook.sheets("sheet2").select
选择指定的sheet