Author Topic: Export table to excel  (Read 2609 times)

0 Members and 1 Guest are viewing this topic.

Fabricio28

  • Swamp Rat
  • Posts: 670
Export table to excel
« on: January 08, 2015, 08:44:42 AM »
Hi guys,
I have a table in my project in autocad, but that table is design by line and text. It isn't a table command from autocad.

My question is...
Can I export the texts to excel?

Thank in advance

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Export table to excel
« Reply #1 on: January 08, 2015, 08:53:29 AM »
use data exchange.....and export out only the text values...it should work as expected
Be your Best


Michael Farrell
http://primeservicesglobal.com/

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Export table to excel
« Reply #2 on: January 08, 2015, 09:13:40 AM »
I'm attaching a example...

I wanna put that information in excel file.

Regards

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Export table to excel
« Reply #3 on: January 08, 2015, 10:17:31 AM »
Be your Best


Michael Farrell
http://primeservicesglobal.com/

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Export table to excel
« Reply #4 on: January 08, 2015, 11:28:44 AM »
Thank mjfarrell,

Regards  :-D

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Export table to excel
« Reply #5 on: January 08, 2015, 12:06:28 PM »
Here is another to export to CSV.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:txt2csv (/ _foo e el f file fo fz i l out ss tmp x y z)
  2.   ;; ronjonp
  3.   (defun _foo (s) (vl-string-left-trim " " (strcat (vl-string-right-trim " " s) ",")))
  4.   (if (setq ss (ssget '((0 . "text"))))
  5.     (progn (repeat (setq i (sslength ss))
  6.         (setq e (ssname ss (setq i (1- i))))
  7.         (setq el (entget e))
  8.         (and (> (cdr (assoc 40 el)) fz) (setq fz (cdr (assoc 40 el))))
  9.         (setq l (cons (list (cdr (assoc 10 el)) (cdr (assoc 1 el))) l))
  10.       )
  11.       (setq l (vl-sort l '(lambda (y1 y2) (> (cadar y1) (cadar y2)))))
  12.       (while (setq y (cadr (caar l)))
  13.         (setq tmp (vl-remove-if-not '(lambda (a) (equal y (cadr (car a)) fz)) l))
  14.         (setq out (cons (vl-sort tmp '(lambda (x1 x2) (< (caar x1) (caar x2)))) out))
  15.         (mapcar '(lambda (x) (setq l (vl-remove x l))) tmp)
  16.       )
  17.       (setq file
  18.         (mapcar '(lambda (x) (apply 'strcat (mapcar '(lambda (z) (_foo z)) (mapcar 'cadr x))))
  19.            (reverse out)
  20.         )
  21.       )
  22.       (setq f (strcat (getvar 'dwgprefix) "TXT2CSV.csv"))
  23.       (setq fo (open f "w"))
  24.       (mapcar '(lambda (x) (write-line (vl-string-right-trim "," x) fo)) file)
  25.       (close fo)
  26.       (alert f)
  27.     )
  28.   )
  29.   (princ)
  30. )
« Last Edit: January 08, 2015, 12:41:05 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Export table to excel
« Reply #6 on: January 08, 2015, 01:48:47 PM »
Here is another to export to CSV.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:txt2csv (/ _foo e el f file fo fz i l out ss tmp x y z)
  2.   ;; ronjonp
  3.   (defun _foo (s) (vl-string-left-trim " " (strcat (vl-string-right-trim " " s) ",")))
  4.   (if (setq ss (ssget '((0 . "text"))))
  5.     (progn (repeat (setq i (sslength ss))
  6.         (setq e (ssname ss (setq i (1- i))))
  7.         (setq el (entget e))
  8.         (and (> (cdr (assoc 40 el)) fz) (setq fz (cdr (assoc 40 el))))
  9.         (setq l (cons (list (cdr (assoc 10 el)) (cdr (assoc 1 el))) l))
  10.       )
  11.       (setq l (vl-sort l '(lambda (y1 y2) (> (cadar y1) (cadar y2)))))
  12.       (while (setq y (cadr (caar l)))
  13.         (setq tmp (vl-remove-if-not '(lambda (a) (equal y (cadr (car a)) fz)) l))
  14.         (setq out (cons (vl-sort tmp '(lambda (x1 x2) (< (caar x1) (caar x2)))) out))
  15.         (mapcar '(lambda (x) (setq l (vl-remove x l))) tmp)
  16.       )
  17.       (setq file
  18.         (mapcar '(lambda (x) (apply 'strcat (mapcar '(lambda (z) (_foo z)) (mapcar 'cadr x))))
  19.            (reverse out)
  20.         )
  21.       )
  22.       (setq f (strcat (getvar 'dwgprefix) "TXT2CSV.csv"))
  23.       (setq fo (open f "w"))
  24.       (mapcar '(lambda (x) (write-line (vl-string-right-trim "," x) fo)) file)
  25.       (close fo)
  26.       (alert f)
  27.     )
  28.   )
  29.   (princ)
  30. )

Thank you my friend ronjonp!!  :-D



ronjonp

  • Needs a day job
  • Posts: 7533
Re: Export table to excel
« Reply #7 on: January 08, 2015, 02:00:05 PM »
Glad to help  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC