create an excel table

create an excel table

E.S.7.9
Advocate Advocate
974 Views
1 Reply
Message 1 of 2

create an excel table

E.S.7.9
Advocate
Advocate

hi everybody

 

 

 

i have texts in my drawing which i have to tranfer them to excel and formulate them , so in this case is there any way to do it via lisp ? 

 

here is what i want to do :

 

  • i want to , specify excel column name ( for example "A") , and  select text values one by one and send them all to A column one under the other on excel ,sorting by selection order
  • and fafter i repeat it several times for different columns ( for example "B" and "C" ) i wanna create a formula to D column ( example : (A+B)*C )

it seems diffucult request 😃

 

if anyone has similar code , can you share with me , pls. ? 

 

thank you 

0 Likes
Accepted solutions (1)
975 Views
1 Reply
Reply (1)
Message 2 of 2

3wood
Advisor
Advisor
Accepted solution

You can try following method, which writes selected contents into rows in a csv file, then transposes it in Excel as columns.

1. Use the code below to record your Column name and text selections as a csv file. Acturally it prompts "Enter Row Name:" instead of "Enter Column Name:"

2. Open the csv file in Excel. It is in the same directory and same file name as current drawing.

3. Select whole rows by selecting the Row Numbers in Excel, press Ctrl+C.

4. Switch to a new Tab in Excel.

5. Select same number of COLUMNS, then Paste -> Transpose

 

Codes:

(defun C:PKUP2CSV (/ fn1 f1 str1 C1 Mark-1)
  ;| By 3wood 2016/06/14
     Enter multiple Row name following by selection of text objects for row contents to save it as a csv file
     with the same file name and directory as current drawing.
  |;
  (setq fn1 (strcat (getvar "DWGPREFIX") (vl-string-right-trim ".dwg" (getvar "DWGNAME")) ".csv"))
  (setq Mark-1 nil)
  (while (and (setq str1 (getstring T "\nEnter Row name:")) (not (eq str1 "")))
    (While (setq C1 (car(entsel "\nPick up cell content:")))
      (setq C1 (entget C1))
      (if (eq (cdr (assoc 0 C1)) "TEXT")
	(setq str1 (strcat str1 ",\"" (cdr (assoc 1 C1)) "\""))
	(princ "\nSelection is not a TEXT object.")
	)
      )
    (setq f1 (if (not Mark-1) (open fn1 "w") (open fn1 "a")))
    (setq Mark-1 T)
    (write-line str1 f1)
    (close f1)
    )
  )

 

 

Step 2:

pkup02.JPG

 

Step 3:

pkup03.JPG

 

Step 4:

pkup04.JPG

0 Likes