esam 发表于 2022-7-5 16:12:12

表中的自动求和单元格

大家好
我正在寻找lisp,它可以通过单击我想要的单元格来计算单元格的总和。
 
我有很多表,我必须为每一列求和
 
对每一张桌子都这样做是很困难的
 
一些开放??!!
 
对不起我的英语

BIGAL 发表于 2022-7-5 16:20:25

谷歌应该找到一个答案,但如果你想通过lisp在单元格上求和,你可以得到表格的最后一行数,然后问下有多少间隙,并在该单元格中加入求和函数。我没有答案,但肯定有人会的。
 
很确定这是类似于vla get rows是在表的底部。需要标题信息,还需要从总行中减去。我会检查单元格中的值,这样就可以得到真正的最后一个值,但需要检查所有列。如果输入的行号大于表,则添加行,然后添加总和公式。

esam 发表于 2022-7-5 16:26:39

谢谢你。
 
还有其他想法吗

SLW210 发表于 2022-7-5 16:34:50

我将你的帖子转移到AutoLISP、Visual LISP和DCL论坛。

maratovich 发表于 2022-7-5 16:39:33

试试看。
但这不是lisp,不是vba。这个程序。
SumTable。拉链

BIGAL 发表于 2022-7-5 16:52:05

有一点时间,所以我想我会有一个Lisp程序,虽然信贷李安布罗修斯得到细胞选择。
 
只需选择要求和的列单元格顶部,这是非常多的版本1,因为我可以看到接下来的几个问题。
 
我确信使用entsel可以更好地处理pick单元格。
 

;; Example shows how to pick a single table cell on screen and change its value.
;; This example demonstrates the ActiveX properties/methods HitTest,
;; GetCellType, GetText and SetText.
;; original code by Lee Ambrosius 2015

(defun SelectTableCell ( / pick vHeight vWidth lwrLeft uprRight vector
                                          SS_TABLES cnt eMaxcellValueOrg)

;; Ask the user for a point on screen
(if (/= (setq pick (vlax-3d-point (getpoint "\nSelect Cell to START sum from: "))) nil)
   (progn

   ;; Get the corners of the screen display to build our selection set
   (setq vHeight (getvar "viewsize"))
   (setq vWidth (* (/ (nth 0 (getvar "screensize")) (nth 1 (getvar "screensize"))) vHeight))

   (setq lwrLeft (list (- (nth 0 (getvar "viewctr")) (/ vWidth 2)) (- (nth 1 (getvar "viewctr")) (/ vHeight2)) 0))
   (setq uprRight (list (+ (nth 0 (getvar "viewctr")) (/ vWidth 2)) (+ (nth 1 (getvar "viewctr")) (/ vHeight2)) 0))

   ;; Get the current display orientation
   (setq vector (vlax-make-safearray vlax-vbDouble '(0 . 2)))
   (vlax-safearray-fill vector '(1 1 1))
   (setq vector (vlax-make-variant vector))
   
   ;; Select all the table objects visible on screen
   (if (setq SS_TABLES (ssget "C" lwrleft uprright (list (cons 0 "ACAD_TABLE"))))
       (progn

         (setq cnt 0
               eMax (sslength SS_TABLES)
         )

         ;; Step through all the items in the selection set
         (while (> eMax cnt)
         ;; Geta table object from the selection set
         (setq tableObj (vlax-ename->vla-object (ssname SS_TABLES cnt)))

         ;; Return values for what cell was picked in
         (setq row 0
               col 0)

         ;; Below is also a sample to see if a valid cell is picked
         ;; (vla-select table pick vector vector 5 5 :vlax-false 'row 'col)
   
         ;; Check to see if a valid cell was picked
         (if (= (vla-hittest tableObj pick vector 'row 'col) :vlax-true)
             (progn

               ;; Get out of the loop
               (setq cnt (1+ eMax))

               ;; Check to see what the Cell Type is (Text or Block)
               (if (= (vla-GetCellType tableObj row col) acTextCell)
                                 ;; Let's get the value out exit with row - col
                   (setq cnt eMax)
                )
             )
         )
         (setq cnt (1+ cnt))
         )
       )
   )
   )
)
(princ)
) ; defun

; A is chr 65

(defun addsum-table ( / tableObj row rows col cols )
(SelectTableCell)
(setq rows (vla-get-rows tableobj))
(setq cols (vla-get-columns tableobj))
(alert (strcat (rtos rows 2 0) " " (rtos cols 2 0)))
(vla-InsertRows tableobj rows (vla-GetRowHeight tableobj (1- rows)) 2);; 3 number of rows
(setq rows (- (vla-get-rows tableobj)1 ))
; do a re alpha row column here
(SETQ ALPHA (CHR (+ 65 COL )))
(setq ans (strcat "=sum" "(" ALPHA (RTOS ROW 2 0) ":"ALPHA (RTOS ROWS 2 0) ")"))
(vla-settext tableobj rows col ans)
)

(addsum-table)

esam 发表于 2022-7-5 16:57:43

我想把所有列相加到“TOTAL”下面的单元格中
该表不总是7行,它可以是任意数量的行

esam 发表于 2022-7-5 17:03:39

这很好。但我希望它是autocad的,而不是外部窗口
把总和写在我想要的单元格里

maratovich 发表于 2022-7-5 17:08:03

esam指定您正在联系的人。
阅读此线程,它可以方便地快速修复:
http://www.cadtutor.net/forum/showthread.php?101028-这段代码真正的成本是多少

BIGAL 发表于 2022-7-5 17:14:04

以撒你看过我贴的吗?
页: [1]
查看完整版本: 表中的自动求和单元格