1币,求改一个代码
求改一个代码,统计文本输出到excel,可是是新建一个excel,能否改成输入到当前已经打开的excel(DEFUN C:TJWB(/ N SSSTR_LST LST_STR STR1 SHUL STRLST )
(defun initexcel ()
(setq appxls (vlax-get-or-create-object "excel.application")
xlsworkbooks (vlax-get-property appxls "workbooks")
newbook (vlax-invoke-method xlsworkbooks "add")
newsheet (vlax-get-property newbook "sheets")
newitem (vlax-get-property newsheet "item" 1)
xlscells (vlax-get-property newitem "cells")
)
(vla-put-visible appxls :vlax-true)
)
(defun endexcel ()
(vlax-release-object xlscells)
(vlax-release-object newitem)
(vlax-release-object newsheet)
(vlax-release-object newbook)
(vlax-release-object xlsworkbooks)
(vlax-release-object appxls)
)
(defun datacell (nurow col value)
(vlax-put-property xlscells "item" numrow col (vl-princ-to-string value))
)
(VL-LOAD-COM)
(SETQ SS(SSGET '((0 . "*TEXT"))))
(SETQ N 0)
(WHILE (< N (SSLENGTH SS))
(SETQ LST_STR (APPEND LST_STR (LIST(CDR(ASSOC 1 (ENTGET (SSNAME SS N)))))))
(SETQ N (1+ N))
)
(SETQ LST_STR (vl-sort LST_STR(function(lambda(x y) (<x y)))))
(SETQ STRLSTLEN (LENGTH LST_STR))
(WHILE LST_STR
(SETQ SHUL(-STRLSTLEN(LENGTH(SETQ LST_STR(VL-REMOVE (SETQ STR1 (CAR LST_STR))LST_STR)))))
(SETQ STRLST (APPEND STRLST (LIST(LIST STR1 SHUL))))
(SETQ STRLSTLEN (LENGTH LST_STR))
)
(SETQ STRLST (append (list (list "编号" "数量(个)"))STRLST ))
(initexcel)
(setq numrow 1 )
(setq i 0)
(repeat (length STRLST)
(SETQ txt (nth iSTRLST))
(datacell numrow (setq numcol 1) (car txt))
(datacell numrow (setq numcol 2) (cadr txt))
(setq i (1+ i) numrow (1+ numrow) )
)
(endexcel)
(princ)
)
输入到当前已经打开的excel的sheet中,有可能会覆盖有用的内容 zzyong00 发表于 2016-4-10 22:02 static/image/common/back.gif
输入到当前已经打开的excel的sheet中,有可能会覆盖有用的内容
能不能以我选定的单元格作为开始单元格
页:
[1]