cadman2009 Posted December 13, 2009 Share Posted December 13, 2009 Hi friends How I can put each excel column to linear array ? How I can put each excel raw to linear array ? for example 10 row and 4 column Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 13, 2009 Share Posted December 13, 2009 VBA or LISP? For LISP see here: http://web2.airmail.net/terrycad/LISP/GetExcel.lsp http://www.theswamp.org/index.php?topic=10101.0 Lee Quote Link to comment Share on other sites More sharing options...
cadman2009 Posted December 13, 2009 Author Share Posted December 13, 2009 VBA or LISP? For LISP see here: http://web2.airmail.net/terrycad/LISP/GetExcel.lsp http://www.theswamp.org/index.php?topic=10101.0 Lee Thanks Mr.Lee I read these files , they are very detailed and will solve my problem. Mr.Lee I can read a lisp file but I'm not a lisp programmer , I 've started lisp programming since two week ago but now I can combine these lisp file with a vba cod or convert them . thanks you very much and have a good time . Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 13, 2009 Share Posted December 13, 2009 Thanks Mr.LeeI read these files , they are very detailed and will solve my problem. Mr.Lee I can read a lisp file but I'm not a lisp programmer , I 've started lisp programming since two week ago but now I can combine these lisp file with a vba cod or convert them . thanks you very much and have a good time . Hmm... I think they would need to be re-written into VBA... not converted - no easy (or quick) task. Quote Link to comment Share on other sites More sharing options...
fixo Posted December 13, 2009 Share Posted December 13, 2009 Hi friendsHow I can put each excel column to linear array ? How I can put each excel raw to linear array ? for example 10 row and 4 column Another way (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 number c1 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 column c1 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") ) ;; clean up of memory (mapcar (function (lambda (x) (vl-catch-all-apply (function (lambda () (if (not (vlax-object-released-p x)) (vlax-release-object x) ) ) )))) (list Cel LastCell Cels FindRow FindRang Sht Wbk ExcelApp) ) (setq Cel nil LastCell nil Cels nil FindRow nil FindRang nil Sht nil Wbk nil ExcelApp nil ) (gc) (gc) (princ) ) (setq FilePath (getfiled "Select Excel file to read data:" (getvar "dwgprefix") "xls" 16 ) ) (initget 6) (setq ShtNum (getint "\nEnter a sheet number <1>: ")) (if (not ShtNum) (setq ShtNum 1)) (initget 6) (setq RowNum (getint "\nEnter a row number <1>: ")) (if (not RowNum) (setq RowNum 1)) (initget 6) (setq ColNum (getint "\nEnter a column number <1>: ")) (if (not ColNum) (setq ColNum 1)) (setq ExcelApp (vlax-get-or-create-object "Excel.Application")) (vla-put-visible ExcelApp :vlax-true) ;or :vlax-false for invisible mode (setq Wbk (vl-catch-all-apply 'vla-open (list (vlax-get-property ExcelApp "WorkBooks") FilePath))) (setq Sht (vl-catch-all-apply 'vlax-get-property (list (vlax-get-property Wbk "Sheets") "Item" ShtNum))) (vlax-invoke-method Sht "Activate") (setq rowlist (readrow Sht RowNum)) (setq columnlist (readcolumn Sht ColNum)) (princ "\nRow data: ") (print rowlist) (princ "\nColumn data: ") (print columnlist) ;; --> work here with this data after (*error* "") (princ) ) (vl-load-com) ~'J'~ Quote Link to comment Share on other sites More sharing options...
fixo Posted December 13, 2009 Share Posted December 13, 2009 ...vba code or convert them . Here is VBA example ~'J'~ ReadExcel.zip Quote Link to comment Share on other sites More sharing options...
cadman2009 Posted December 16, 2009 Author Share Posted December 16, 2009 Here is VBA example ~'J'~ Thanks dear fixo I changed your code and now I can read an excel file that have 7 column and 1420 row , when it worked correctly and finished my project , put it after your code . another time , I thanks very much from you and Mr Lee for your good codes . Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 16, 2009 Share Posted December 16, 2009 You're welcome CadMan Quote Link to comment Share on other sites More sharing options...
fixo Posted December 16, 2009 Share Posted December 16, 2009 Thanks dear fixoI changed your code and now I can read an excel file that have 7 column and 1420 row , when it worked correctly and finished my project , put it after your code . another time , I thanks very much from you and Mr Lee for your good codes . You're welcome Cheers ~'J'~ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.