明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1365|回复: 1

为什么创建excel的方法不一样啊

[复制链接]
发表于 2012-6-1 18:19:02 | 显示全部楼层 |阅读模式
(defun c:xl-test1()
  (vl-load-com)
  (if (equal nil msxl-acos)
    (vlax-import-type-library
        :tlb-filename        "C:\\Program Files\\Microsoft Office\\Office11\\Excel.exe"
:methods-prefix  "msxl-"
:properties-prefix  "msxl-"
:constants-prefix  "msxl-"
    )
  )
  (setq XLapp(vlax-get-object "Excel.Application"))
  (if (null XLapp)
      (setq XLapp (vlax-create-object "Excel.Application"))
  )
另一种方法是论坛上的
(Defun gxl-word-app-Init
       (/ OSVar GGG Olb8 Olb9 Olb10 TLB Out msg msg1 msg2)

    (setq msg  "\n 初始化微软Word "
         msg1 "\042初始化Word错误\042"
         msg2 (strcat
               "\042 警告"
               "\n ===="
               "\n 无法在您的计算机上检测到微软Word软件"
               "\n 如果您确认已经安装Word, 请发送电子邮"
               "\n 件到Gu_xl@sohu.com获取更多的解决方案\042"
              )
    )
  (if (null mswc-wd100Words)
    (progn
      (if (and (setq GGG
                    (vl-registry-read
                     "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Winword.EXE"
                     "Path"
                    )
              )
              (setq GGG (strcase (strcat GGG "Winword.EXE")))
         )
       (progn
         (foreach OSVar (list "SYSTEMROOT" "WINDIR"
                            "WINBOOTDIR"     "SYSTEMDRIVE"
                            "USERNAME"  "COMPUTERNAME"
                            "HOMEDRIVE"       "HOMEPATH"
                            "PROGRAMFILES"
                           )
           (if    (vl-string-search (strcat "%" OSVar "%") GGG)
             (setq GGG       (vl-string-subst
                       (strcase (getenv OSVar))
                      (strcat "%" OSVar "%")
                       GGG
                     )
             )
           )
        )
         (setq   Olb8  (findfile (vl-string-subst "MSWORD.OLB" "WINWORD.EXE" GGG))
         )
         (cond  ((= (vl-filename-base (vl-filename-directory GGG))
                  "OFFICE11"
               )
               (setq TLB Olb8
                     Out "2003"
               )
              )
  ((= (vl-filename-base (vl-filename-directory GGG))
                  "OFFICE12"
               )
               (setq TLB Olb8
                     Out "2007"
               )
              )
              (t (setq Out "Version Unknown"))
         )
         (if TLB
           (progn
             (princ (strcat MSG Out "..."))
             (vlax-import-type-library
              :tlb-filename    TLB               :methods-prefix
              "mswm-"             :properties-prefix
              "mswp-"             :constants-prefix "mswc-"
              )
           )
         )
       )
       (progn
         (if vldcl-msgbox
(vldcl-msgbox "x" msg1 msg2)
(alert (read msg2))
)
         (exit)
       )
      )
    )
  )  
mswc-wd100Words
)
;;;创建Word Application
;;;(setq wordapp (gxl-word-app-New 1))
(Defun gxl-word-app-New (UnHide / Rtn)
  (if (gxl-word-app-init)
    (progn
      (if (setq Rtn (vlax-get-or-create-object "Word.Application"))
       (progn
         (vlax-invoke-method
           (vlax-get-property Rtn 'Documents)
           'Add
         )
         (if UnHide
           (vla-put-visible Rtn :vlax-true)
           (vla-put-visible Rtn :vlax-false)
         )
       )
      )
    )
  )
  Rtn
)
;;;打开Word文件
;;;(setq wordapp (gxl-word-app-open (getfiled "选择文件" "" "doc" 0) 1))
(Defun gxl-word-app-open (DocFile UnHide /  Rtn)
  (setq DocFile (strcase DocFile))
  (if (null (wcmatch DocFile "*.DOC"))
    (setq DocFile (strcat DocFile ".DOC"))
  )
  (if (and (findfile DocFile)
          (setq Rtn (vlax-get-or-create-object "Word.Application"))
      )
    (progn
;|
      (vlax-invoke-method
       (vlax-get-property Rtn 'Documents)
(vla-get-Documents rtn)
       'Open
       DocFile
      )
      |;
      (mswm-open (vla-get-Documents rtn) DocFile)
      (if UnHide
       (vla-put-visible Rtn :vlax-true)
       (vla-put-visible Rtn :vlax-false)
      )
    )
  )
  Rtn
)
;;; (gxl-word-app-save (vla-get-ActiveDocument wordapp)) 保存word文档
(Defun gxl-word-app-save (DocObj)
  (mswm-Save DocObj)
)
这是我发现的不同 之处,希望有人可以为我解答


该贴已经同步到 YAOSHIWEI的微博
 楼主| 发表于 2012-6-1 18:22:13 | 显示全部楼层
我怎么感觉 不对啊是不是哪个地方有问题,上面那一个是我在书上看到的,下面那个是论坛上的,这两个有区别吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-22 03:57 , Processed in 0.182655 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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