求哪位大神给个读取EXCEL文件指定单元格内容的函数
本帖最后由 lifuq1979 于 2017-11-20 21:21 编辑求哪位大神给个读取EXCEL文件指定单元格内容的程序,通用函数更好,EXCEL版本2016,谢谢!!!
找到一个帖子
[求助(已解决)]用lisp读取Excel文件中指定单元格的数据
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=75453&fromuid=7322308
(出处: 明经CAD社区)
(defun Excel-Get-data ( / xfile cell ADOCONNECT ADORECORDSET ConnectionString lst Sheet-name source cell-tmp cell-value)
;指定单元格的数据
(defun Excel-Get-CellValue (Sheet-name cell)
(setq source (strcat "SELECT * FROM [" Sheet-name cell":" cell "]"))
(vlax-invoke-methodADORecordset "Open" source ADOConnect 1 3 nil)
(setq cell-tmp (vlax-safearray->list (vlax-variant-value (vlax-invoke-method ADORecordset "GetRows" 1))))
(vlax-variant-value (car (car cell-tmp)))
)
(setq xfile (getfiled "打开法兰计算文件" "" "xls" 8))
(setq ADOConnect (vlax-get-or-create-object "ADODB.Connection"))
(setq ADORecordset (vlax-get-or-create-object "ADODB.Recordset"))
(setq ConnectionString (strcat "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" xfile ";Extended Properties=;Excel 8.0;HDR=No" ))
(if (not
(vl-catch-all-error-p
(vl-catch-all-apply
(function vlax-invoke-method)
(list ADOConnect "Open" ConnectionString"admin" "" nil)
)
)
)
(progn
(setq lst
(vlax-safearray->list
(vlax-variant-value
(vlax-invoke-method (vlax-invoke-method ADOConnect "OpenSchema" 4 ) "GetRows" 1)
)
)
)
(setq Sheet-name (vlax-variant-value (car (caddr lst))));确定"第一个"工作表的名称
(setq cell-value (Excel-Get-CellValue Sheet-name "H16"));H16单元格
(vlax-invoke-method ADORecordset "Close")
(vlax-invoke-method ADOConnect "Close")
)
(progn
(princ "\n打开Excel数据文件出错")
(vl-catch-all-apply 'vlax-invoke-method (list ADOConnect "Close"))
(setq cell-value nil)
)
)
(vlax-release-object ADORecordset)
(vlax-release-object ADOConnect)
cell-value
)
运行出现----; 错误: Automation 错误。 Microsoft Jet
数据库引擎找不到对象''111$'D4:D4'。请确定对象是否存在,并正确地写出它的名称和路
径。
这是什么原因,是与EXCEL版本有关吗???
新手一枚,我用的是打开l工作簿,然后获取值得j = ExcelApp.Application.GetOpenFileName(FileFilter:="选择排图用的转序单 ,*.xlsx; *.xlsm; *.xlsb;*.xls") (xlr_get_excel_rangeEXCEL对象 单元格区域)获得EXCEL数据
需要小一个人工具支持
页:
[1]