明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3918|回复: 12

[已解答] lisp控制word插入图片问题

[复制链接]
发表于 2014-3-9 08:59:39 | 显示全部楼层 |阅读模式
如题,主要是函数不会用,lisp接VBA用法还不会,VBA更是没怎么看过。代码如下:
  1. (defun c:tt()
  2.   (vl-load-com)
  3.   (if (null MW-accept) (jinn-get-word-Lib))
  4.   (jinn-get-word-object)
  5.   (setq range (MW-get-range lastpgobj))   
  6.   (MW-addpicture "c:\\1.jpg"  range)
  7.   (MW-put-bold range 0)
  8.   (setq filename "c:\\wordtest1.doc")
  9.   (vlax-invoke-method docobj "Saveas" filename nil nil nil nil nil nil)
  10.   )

  11. (defun jinn-get-word-Lib()
  12.   (setq office:dir "C:\\Program Files\\Microsoft Office\\")
  13.   (cond
  14.     ((setq mwlib (findfile (strcat office:dir "office\\" "MSWord8.olb"))))
  15.     ((setq mwlib (findfile (strcat office:dir "office\\" "MSWord9.olb"))))
  16.     ((setq mwlib (findfile (strcat office:dir "office\\" "MSWord.olb"))))
  17.     ((setq mwlib (findfile (strcat office:dir "office10\\" "MSWord.olb"))))
  18.     ((setq mwlib (findfile (strcat office:dir "office12\\" "MSWord.olb"))))
  19.     ((setq mwlib (findfile (strcat office:dir "office14\\" "MSWord.olb"))))
  20.     (t (setq mwlib nil))
  21.     )
  22.   (if mwlib
  23.     (vlax-import-type-library
  24.       :tlb-filename mwlib
  25.       :methods-prefix "MW-"
  26.       :properties-prefix "MW-"
  27.       :constants-prefix "MW-"
  28.       )
  29.     (alert "Word typelib 文件不存在")
  30.    )
  31. )

  32. (defun jinn-get-word-object()
  33.   (setq WordObj (vlax-create-object "Word.Application"))
  34.   (vla-put-visible WordObj 1)
  35.   (setq docs (vlax-get-property WordObj 'documents))
  36.   (setq docobj (vlax-invoke-method docs 'Add))
  37.   (setq pgobj (MW-get-paragraphs docobj))
  38.   (setq lastpgobj (MW-get-last pgobj))  
  39.   )


以上代码是从书上抄袭来的,还算能看懂。
应该是  (MW-addpicture "c:\\1.jpg"  range)这一句出错了吧,运行时返回 错误: 参数类型错误: VLA-OBJECT "c:\\1.jpg"
请教大神们,这个函数怎么用呢。。。


发表于 2019-4-1 11:53:14 | 显示全部楼层
本帖最后由 caddog 于 2019-4-1 12:43 编辑
    复制代码

  1. (setq v-selection (mswp-get-Selection msw))
  2. (setq v-insertPic (mswp-get-InlineShapes v-selection))
  3. (setq inlineShapeObj (mswm-AddPicture  v-insertPic $fn-pic1 :vlax-false :vlax-true));_插入图片
  4. (mswp-put-height inlineShapeObj 594.95);_图片高
  5. (mswp-put-Width inlineShapeObj 841.6);_图片宽
  6. ;;;以下设置图片的 版式
  7. (setq inlineShapeObj (mswm-ConvertToShape inlineShapeObj))
  8. (setq inlineShapeObj-format (mswp-get-WrapFormat inlineShapeObj))
  9. (mswp-put-type inlineShapeObj-format 0)
发表于 2019-3-31 21:16:29 | 显示全部楼层
发表于 2019-3-31 21:15:49 | 显示全部楼层
如何改变插入JPG的高度?
 楼主| 发表于 2014-3-9 10:00:49 | 显示全部楼层
VBA函数方法如下

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2014-3-9 18:38:35 | 显示全部楼层
这。。。等了一天没人回答。。。是太简单了,不屑于吗。。。
发表于 2014-3-10 09:04:02 | 显示全部楼层
从书上抄袭来的,我怎么没有看过这本书?楼主,介绍一下嘛
 楼主| 发表于 2014-3-10 09:05:42 | 显示全部楼层
本帖最后由 sheoh 于 2014-3-10 09:13 编辑
xiaxiang 发表于 2014-3-10 09:04
从书上抄袭来的,我怎么没有看过这本书?楼主,介绍一下嘛

AutoCAD完全应用指南啊。。。论坛里常出现的。。好像是翔虹什么的。。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2014-3-10 09:07:23 | 显示全部楼层
xiaxiang 发表于 2014-3-10 09:04
从书上抄袭来的,我怎么没有看过这本书?楼主,介绍一下嘛

我这个问题能帮我解答吗。。。[em0]
发表于 2014-3-10 09:44:25 | 显示全部楼层
sheoh 发表于 2014-3-10 09:07
我这个问题能帮我解答吗。。。

(vlax-invoke (vlax-get-property docobj 'InlineShapes) 'AddPicture "c:\\1.jpg" :vlax-false :vlax-false range)
 楼主| 发表于 2014-3-10 09:47:13 | 显示全部楼层
Gu_xl 发表于 2014-3-10 09:44
(vlax-invoke (vlax-get-property docobj 'InlineShapes) 'AddPicture "c:\\1.jpg" :vlax-false :vlax-fa ...

终于等到G版了!  多谢!我对G版的崇拜犹如滔滔江水连绵不断。。。
发表于 2014-3-10 10:03:56 | 显示全部楼层
sheoh 发表于 2014-3-10 09:47
终于等到G版了!  多谢!我对G版的崇拜犹如滔滔江水连绵不断。。。

函数如何使用,你二楼图片提供的VBA方法已经说明的非常清楚了,只是你要把它转换为Lisp的active写法而已!
 楼主| 发表于 2014-3-10 10:19:26 | 显示全部楼层
本帖最后由 sheoh 于 2014-3-10 10:30 编辑
Gu_xl 发表于 2014-3-10 10:03
函数如何使用,你二楼图片提供的VBA方法已经说明的非常清楚了,只是你要把它转换为Lisp的active写法而已! ...

是的,这个刚接触,还不太懂。。。。多谢指导。。。而且这方面的内容论坛里好像没怎么看到,是不是在其他的哪个版块。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-19 02:53 , Processed in 0.188510 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表