本帖最后由 yshf 于 2011-10-29 12:35 编辑
1、 (vla-put-visible Xlobj 1) 的一行右括号是多余的
2、将 (vla-put-visible Xlobj 1) 移动到 (setq XLobj(vlax-create-object"Excel.Application"))行的下面一行
3、其余如下:

- (defun C:sjk()
-
- (vl-load-com)
-
- (if (not (findfile (setq exlib "C:\\Program files\\Microsoft office\\Office12\\Excel.exe")))
- (if (not (findfile (setq exlib "C:\\Program files\\Microsoft office\\Office10\\Excel.exe")))
- (if (not (findfile (setq exlib "C:\\Program files\\Microsoft office\\Office11\\Excel.exe")))
- (vl-exit-with-error "不能引入Excel类型库!")
- )
- )
- )
- (if(null MX-acos)
- (vlax-import-type-library
- :tlb-filename exlib
- :methods-prefix "MX-"
- :properties-prefix "MX-"
- :constants-prefix "MX-"
- )
-
- )
- (setq XLobj (vlax-create-object "Excel.Application"))
- (vla-put-visible Xlobj :vlax-true)
- (vlax-invoke-Method(vlax-get-Property XLobj'Workbooks)'Open filename)
- (setq filename"f:\\1.xls")
- (setq sheetobj(MX-get-activesheet XLobj))
- (setq cells(MX-get-cells sheetobj))
- (setq cell-1-2 (vlax-variant-value(MX-get-value-sheetobj-1-2)))
- (princ"\nCELL-1-2=")(princ cell-1-2)
- (vlax-invoke-method XLobj 'QUIT)
- (vlax-release-object XLobj)
- (setq XLobj nil)
- (princ)
- )
|