theisland 发表于 2015-12-21 12:45:03

求高手修改小程序

原帖子地址:http://bbs.mjtd.com/thread-170340-1-1.html
最佳答案提供者:Linhay
现在发现因为excel不能同时打开2个同名的文件,所以我把每个项目的“工程材料统计”表格名字变成“工程材料统计-项目1”、“工程材料统计-项目2”……等,请高手帮我把这个程序调整成可以识别文件名通配符的模式

(defun c:001(/ path filename)
(setq path (getvar "DWGPREFIX"))
(setq filename (strcat path "工程材料统计.xls"));比如这一行中的文件名能不能写成“工程材料统计*.xls”?
(DSX-Open-Excel-Exist filename "show")
)

(defun DSX-Open-Excel-Exist (xfile dmode / appsession)
(princ "\n打开 Excel 电子表格文件...")
(cond
( (setq fn (findfile xfile))
(cond
( (setq appsession (vlax-get-or-create-object "Excel.Application"))
(vlax-invoke-method
(vlax-get-property appsession 'WorkBooks)
'Open fn
)
(if (= (strcase dmode) "SHOW")
(vla-put-visible appsession 1)
(vla-put-visible appsession 0)
)
)
)
)
( T (alert (strcat "\n不能找到指定的文件: " xfile)) )
)
appsession
)


Linhay 发表于 2015-12-21 12:45:04

theisland 发表于 2015-12-22 17:11 static/image/common/back.gif
哈哈,老朋友来了!刚试了,怎么没反应呢?

我自己测试了没问题的,你检查一下你的文件扩展名是xls还是xlsx,或者替换一下下面这句
(setq filelist (vl-directory-files path "工程材料统计*.xls*"))

Linhay 发表于 2015-12-21 15:09:37

(defun c:001(/ path filename filelist)
(vl-load-com)
(setq path (getvar "DWGPREFIX"))
(setq filelist (vl-directory-files path "工程材料统计*.xls"))
(foreach n filelist
(setq filename n)
(DSX-Open-Excel-Exist filename "show")
)
)

(defun DSX-Open-Excel-Exist (xfile dmode / appsession)
(princ "\n打开 Excel 电子表格文件...")
(cond
( (setq fn (findfile xfile))
(cond
( (setq appsession (vlax-get-or-create-object "Excel.Application"))
(vlax-invoke-method
(vlax-get-property appsession 'WorkBooks)
'Open fn
)
(if (= (strcase dmode) "SHOW")
(vla-put-visible appsession 1)
(vla-put-visible appsession 0)
)
)
)
)
( T (alert (strcat "\n不能找到指定的文件: " xfile)) )
)
appsession
)

theisland 发表于 2015-12-22 17:10:53

Linhay 发表于 2015-12-21 15:09 static/image/common/back.gif
(defun c:001(/ path filename filelist)
(vl-load-com)
(setq path (getvar "DWGPREFIX"))


哈哈,老朋友来了!我刚试了,没反应呢

theisland 发表于 2015-12-22 17:11:30

Linhay 发表于 2015-12-21 15:09 static/image/common/back.gif
(defun c:001(/ path filename filelist)
(vl-load-com)
(setq path (getvar "DWGPREFIX"))


哈哈,老朋友来了!刚试了,怎么没反应呢?

theisland 发表于 2015-12-23 16:05:48

Linhay 发表于 2015-12-21 15:09 static/image/common/back.gif
(defun c:001(/ path filename filelist)
(vl-load-com)
(setq path (getvar "DWGPREFIX"))


搞定了,非常感谢!
页: [1]
查看完整版本: 求高手修改小程序