Like devitg.
1st yes I wrote a export any table direct to excel. Its a super simple version with no bells and whistles.
2nd if I was to loop it for all layouts, can the tables be written to 1 excel worksheet or do you want 1 excel but multiple worksheets. Or each in a seperate Excel ??
3rd this is becoming a custom request so maybe a donation is in order.
; simple table to excel
; expects Title header and data
; BY Alanh Jan 2022
; do not have excel open
; simple table to excel
; expects Title header and data
; BY Alanh Jan 2022
; do not have excel open
(defun c:tab2excel ( / x y z AH:putcell Ah:opennew number2alpha obj cols row)
(defun AH:putcell (cellname val1 / )
(setq myRange (vlax-get-property (vlax-get-property myxl "ActiveSheet") "Range" cellname))
(vlax-put-property myRange 'Value2 val1)
)
(defun AH:opennew ( / )
(if (= (setq myxl (vlax-get-object "Excel.Application") ) nil)
(setq myxl (vlax-get-or-create-object "excel.Application"))
)
(vla-put-visible myXL :vlax-true)
(vlax-put-property myxl 'ScreenUpdating :vlax-true)
(vlax-put-property myXL 'DisplayAlerts :vlax-true)
)
; Number2Alpha - Converts Number into Alpha string
; Function By: Gilles Chanteau from Marseille, France
; Arguments: 1
; Num# = Number to convert
; Syntax example: (Number2Alpha 731) = "ABC"
;-------------------------------------------------------------------------------
(defun Number2Alpha (Num# / Val#)
(if (< Num# 27)
(chr (+ 64 Num#))
(if (= 0 (setq Val# (rem Num# 26)))
(strcat (Number2Alpha (1- (/ Num# 26))) "Z")
(strcat (Number2Alpha (/ Num# 26)) (chr (+ 64 Val#)))
)
)
);defun Number2Alpha
(AH:opennew)
(vlax-invoke-method (vlax-get-property myXL 'WorkBooks) 'Add)
(setq obj (vlax-ename->vla-object (car (entsel "Pick table "))))
(setq cols (vla-get-columns obj))
(setq rows (vla-get-rows obj))
(alert (strcat (rtos rows 2 0) " rows " (rtos cols 2 0) " columns \n will now send to excel "))
(AH:putcell "A1" (vla-getText Obj 0 0 ))
(setq x 1 y 1 z 2)
(repeat cols
(AH:putcell (strcat (Number2Alpha x) (rtos z 2 0)) (vla-getText Obj y (- x 1) ))
(setq x (1+ x))
)
(setq y 2 )
(repeat (- rows 2)
(setq x 1 )
(repeat cols
(AH:putcell (strcat (Number2Alpha x) (rtos z 2 0)) (vla-getText Obj y (- x 1) ))
(setq x (1+ x) )
)
(setq y (1+ y) )
)
(vlax-release-object myXL)
(alert "Please save the excel and close if you want to import another table ")
(princ)
)
(c:tab2excel)