masterlong 发表于 2013-4-10 01:06
G斑真是牛得一塌糊涂啊
还有两个问题再请教一下
;;复制Excel整个表单示例代码:By Gu_xl
- (defun c:tt (/ XLSFILE XLAPP SH1 SHEETS I FLAG SH2)
- (cond
- ((not
- (setq xlsfile (getfiled "打开Excel文件" "test.xls" "xls" 4))
- )
- )
- ((VL-CATCH-ALL-ERROR-P
- (setq xlapp (VL-CATCH-ALL-APPLY
- 'vlax-get-or-create-object
- (list "Excel.Application")
- )
- )
- )
- (alert "不能创建EXCEL应用程序")
- )
- (t
- (vlax-invoke-method
- (vlax-get-property xlapp 'WorkBooks)
- 'Open
- xlsfile
- )
- (if (not
- (VL-CATCH-ALL-ERROR-P
- (setq sh1
- (VL-CATCH-ALL-APPLY
- 'vlax-get-property
- (list
- (setq sheets
- (vlax-get-property Xlapp "sheets")
- )
- 'item
- "Sheet1" ;_ 要复制的表单,具体名称可自己修改
- )
- )
- )
- )
- )
- (progn
- ;;复制整个表单内容
- (vlax-invoke-method sh1 'copy sh1)
- (setq i 0
- flag t
- )
- (vlax-for sh sheets
- (if flag
- (if (equal sh sh1)
- (setq flag nil)
- (setq i (1+ i))
- )
- )
- )
- (setq sh2 (vlax-get-property sheets 'item i)) ;_ 取得复制后的表单
- (vlax-put-property sh2 'name "NewSheetAA") ;_ 修改复制后的表单名称
- )
- )
- (vlax-invoke-method
- (vlax-get-property Xlapp "ActiveWorkbook")
- "Save"
- ) ;_ 存盘
- (vla-put-visible xlapp 1) ;_ 显示Excel
- (vlax-release-object Xlapp) ;_ 释放内存
- )
- )
- (princ)
- )
|