- ;;表快速输出 XLS
- (defun ls2xls (lst / _List:getRC XD::Excel:i2ColNo excel bks acBook sht rc cells range)
- (defun XD::Excel:i2ColNo (a / l _i2ColNo)
- (defun _i2ColNo (num / lst)
- (cond
- ((<= 1 num 26) (setq lst (cons num lst)))
- ((> num 26) (setq lst (append (_i2ColNo (/ num 26)) (list (rem num 26)))))
- (t lst)
- ) lst
- )
- (if (and (>= (setq a (fix (abs a))) 1)
- (setq l (_i2ColNo a))
- )
- (apply 'strcat (mapcar '(lambda (x) (chr (+ 64 x))) l))
- )
- )
- (setq excel (vlax-get-or-create-object "Excel.Application"))
- (vla-put-visible excel :vlax-true)
- (setq bks (vlax-get excel 'workbooks)
- acBook (vlax-invoke bks 'Add)
- sht (vlax-get excel 'ActiveSheet)
- rc (strcat "A1:"
- (xd::excel:i2ColNo (apply 'max (mapcar 'length lst)))
- (itoa (length lst))
- )
- cells (vlax-get sht 'cells)
- range (vlax-get-property cells 'Range rc)
- )
- (vlax-put-property range 'value2
- (vlax-safearray-fill
- (vlax-make-safearray
- vlax-vbstring
- (cons 1 (length lst))
- (cons 1 (length (car lst)))
- )
- lst
- )
- )
- ;(vlax-put-property (vlax-get-property sht "Range" "A:A") "ColumnWidth" 20);列宽20
- ;(vlax-put-property (vlax-get-property sht "Range" "1:1") "RowHeight" 30);行高30
- )
|