10
45
35
初露锋芒
使用道具 举报
114
1万
中流砥柱
1
1069
1050
(defun readrow (xlsheet rownum / c1 cel cels celvalue cols r1 rowdata xlrange xlrow) (vlax-invoke-method xlsheet "Activate") ;optional (setq xlrange (vlax-get-property xlsheet "UsedRange")) (setq xlrow (vlax-variant-value (vlax-get-property (vlax-get-property xlrange "Rows") "Item" rownum))) (setq cols (vlax-get-property (vlax-get-property xlrange "Columns") "Count")) (vlax-invoke-method xlrange "Activate") ;optional (vlax-invoke-method xlrange "Select") ;optional (setq cels (vlax-get-property xlsheet "Cells")) (setq r1 rownum ; given row numberc1 1 ; initial column number in row) (while (<= c1 cols) (setq cel (vlax-variant-value (vlax-get-property cels "Item" ;; row number : (vlax-make-variant r1 vlax-vblong) ;; column number : (vlax-make-variant c1 vlax-vblong)))) (setq celvalue (vlax-variant-value (vlax-get-property cel "Value2"))) (setq rowdata (cons (vl-princ-to-string celvalue) rowdata)) (setq c1 (1+ c1 ))) (reverse rowdata) )(defun readcolumn (xlsheet colnum / c1 cel cels celvalue columndata r1 rows xlrange xlrow) (vlax-invoke-method xlsheet "Activate") ;optional (setq xlrange (vlax-get-property xlsheet "UsedRange")) (setq xlrow (vlax-variant-value (vlax-get-property (vlax-get-property xlrange "Rows") "Item" colnum))) (setq rows (vlax-get-property (vlax-get-property xlrange "Rows") "Count")) (vlax-invoke-method xlrange "Activate") ;optional (vlax-invoke-method xlrange "Select") ;optional (setq cels (vlax-get-property xlsheet "Cells")) (setq r1 1 ; initial row number in columnc1 colnum ; given column number) (while (<= r1 rows) (setq cel (vlax-variant-value (vlax-get-property cels "Item" ;; row number : (vlax-make-variant r1 vlax-vblong) ;; column number : (vlax-make-variant c1 vlax-vblong)))) (setq celvalue (vlax-variant-value (vlax-get-property cel "Value2"))) (setq columndata (cons (vl-princ-to-string celvalue) columndata)) (setq r1 (1+ r1 ))) (reverse columndata) );; Usage :(defun C:GRD (/ *error* C1 Cel Cels Celvalue Colnum Datalist Excelapp Filepath Findrang Findrow Lastcell R1 Rownum Sht Shtnum Wbk) (defun *error* (msg) ;; close workbook w/o saving changes (vl-catch-all-apply 'vlax-invoke-method (list Wbk "Close") ) ;; quit Excel (vl-catch-all-apply 'vlax-invoke-method (list ExcelApp "Quit") )