Jump to content

Excel to Cad


cadman2009

Recommended Posts

 

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 .

Link to comment
Share on other sites

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 .

 

Hmm... I think they would need to be re-written into VBA... not converted - no easy (or quick) task.

Link to comment
Share on other sites

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

 

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'~

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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 .

 

You're welcome

Cheers :)

 

~'J'~

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...