Vlisp向word里面的文本框写入数据
1 . 获取word进程对象
(setq Rtn (vlax-get-or-create-object "Word.Application"))
2 . 获取Documents对象
(setq doc (vlax-invoke-method
(vlax-get-property Rtn 'Documents)
'Open
wjm
))
3 . 获取Documents对象中的range对象
(setq Rge(vlax-invoke-method
doc
'Range
))
4 . 获取shapeRange对象
(setq Shapes(vlax-get-property
Rge
'shapeRange
))
5 . 获取shapeRange对象中每一个key的值[自己的理解]
(setq name (vlax-get-property a 'AlternativeText))
6 . 将当前的shape选中
(vlax-invoke-method a 'Select)
7 . 进程对象下的弹窗对象
(setq CheckBoxobj (vlax-get-property Rtn 'Selection))
8 . 给选中的对象复制
(vlax-put-property
CheckBoxobj
'Text
text
)
示例:
(defun $xiu-gai-bao-cun$(wjm data / checkboxobj doc name rge rtn shapes text )
(setq Rtn (vlax-get-or-create-object "Word.Application"))
(setq doc (vlax-invoke-method
(vlax-get-property Rtn 'Documents)
'Open
wjm
))
(setq Rge(vlax-invoke-method
doc
'Range
))
(setq Shapes(vlax-get-property
Rge
'shapeRange
))
(vlax-for a Shapes
(and
(setq name (vlax-get-property a 'AlternativeText))
(setq
text (vl-some (function (lambda (a)
(if (= name (cdr (assoc "name" a)))
(cdr (assoc "text" a))
)
)
)
data
)
) (progn
(vlax-invoke-method a 'Select)
(setq CheckBoxobj (vlax-get-property Rtn 'Selection))
(vlax-put-property
CheckBoxobj
'Text
text
))
)
)
(vlax-invoke-method doc "SaveAs2" )
(progn
(vlax-invoke-method
doc
'Close
)
(vl-catch-all-apply 'vlax-invoke-method (list Rtn 'Quit))
(gc)
)
)
(setq wjm "D:\\测试文件.doc");要写入的文件路径
(setq data (list (list (cons "name" "key1")
(cons "text" "张三"))
(list (cons "name" "key2")
(cons "text" "李四"))
))
($xiu-gai-bao-cun$ wjm data)
本帖最后由 kx820506 于 2024-7-9 08:09 编辑
我是新手,但是这个话题很感兴趣 有没有批量替换WORD里面文字的 感谢分享! tryhi 发表于 2024-7-9 11:48
有没有批量替换WORD里面文字的
目前没有 , 批量的就循环搞了;P kx820506 发表于 2024-7-9 07:54
我是新手,但是这个话题很感兴趣
我是小白欢迎大神指正:lol
页:
[1]