| Author |
Message |
kozmos
Guest
|
Posted:
Thu Apr 07, 2005 6:23 pm Post subject:
ACAD_TABLE to Excel |
|
|
We can use "paste special" to import an Excel spreadsheet into AutoCAD 2005+ as ACAD_TABLE, is it possible to export an existing ACAD_TABLE directly into Excel?
|
|
| Back to top |
|
 |
Dann
Guest
|
Posted:
Thu Apr 07, 2005 7:20 pm Post subject:
Re: ACAD_TABLE to Excel |
|
|
Here is something I threw together to show how it can be done.
I have other examples to show how to format cells also.
(defun C:tbl2xl (/ ent obj)
(vl-load-com)
(setq ent (car (entsel)))
(setq obj (vlax-ename->vla-object ent))
(if (not (= (vla-get-ObjectName obj) "AcDbTable"))
(princ "\nObject selected is not a Table! ")
(gettablesize obj)
)
(princ)
)
(defun gettablesize (Tobj / #columns #rows)
(setq #columns (vla-get-Columns Tobj))
(setq #rows (vla-get-Rows Tobj))
(table2excel Tobj #columns #rows)
)
(defun table2excel (tableobj #columns #rows)
(setq sheet (getexcel))
(setq row 1)
(setq col 65)
(setq cols 0)
(setq rows 0)
(repeat #rows
(repeat #columns
(setq
ccel (xlp-get-range sheet (strcat (chr col) (rtos row 2 0)))
)
(setq cval (vlax-invoke-method tableobj 'GetText rows cols))
(xlp-put-Value ccel cval)
(setq cols (+ cols 1))
(setq col (+ col 1))
)
(setq cols 0)
(setq col 65)
(setq row (+ row 1))
(setq rows (+ rows 1))
)
; (vlax-release-object xl)
)
;;(getexcel) Created by Dann Brower 2005
;;Open Excel and Excel Table file
;;Returns the current Sheet of the new Excel workbook to the
;;program that calls (getExcel)
(defun getexcel
(/ exc_obj exc_path exc_version tbl_File tbl workbook sheet)
(vl-load-com)
(setq exc_obj (vlax-get-or-create-object "Excel.Application"))
(if exc_obj
(progn
(vla-put-Visible exc_obj T)
(setq exc_path (vlax-get-property exc_obj 'Path)
exc_version (vlax-get-property exc_obj 'Version)
)
(if (= exc_version "8.0")
(setq tbl_File "Excel8.olb")
(if (= exc_version "9.0")
(setq tbl_File "Excel9.olb")
(if (= exc_version "10.0")
(setq tbl_File "Excel10.olb")
(setq tbl_File "Excel.exe")
)
)
)
(setq tbl (strcat exc_path "\\" tbl_File))
(if (null xlm-open)
(vlax-import-type-library
:tlb-filename tbl ;Table
:methods-prefix "xlm-" ;methods
:properties-prefix "xlp-" ;properties
:constants-prefix "xlc-" ;constants
)
)
(setq
workbook (vlax-invoke-method
(vlax-get exc_obj "Workbooks")
'add
)
sheet (vlax-get exc_obj "ActiveSheet")
)
)
(princ " *Excel Application Not Found* ")
)
sheet
) |
|
| Back to top |
|
 |
Tim Decker
Guest
|
Posted:
Thu Apr 07, 2005 9:05 pm Post subject:
Re: ACAD_TABLE to Excel |
|
|
OMG, that is so awesome, I have been trying to import spreadsheets for so
long. I'm so happy I think I am going to cry. WOOT!!!
|
|
| Back to top |
|
 |
dopeybob435
Joined: 17 Aug 2006
Posts: 1
|
Posted:
Thu Aug 17, 2006 5:02 pm Post subject:
|
|
|
| this looks like it would work well for 2005 and above, by chance would you know something that would work for 2004 by chance? |
|
| Back to top |
|
 |
PARKSUYEONG
Joined: 08 Aug 2006
Posts: 1
Location: South Korea
|
Posted:
Wed Aug 30, 2006 3:56 am Post subject:
running program. |
|
|
Thx for good program. But I have a question for this program.....
When I ran this in ACAD, I encountered an error....
"VLA-OBJECT"
How can I use this program properly..
For reference, I use an Acad2006,7 |
|
| Back to top |
|
 |
|
|
|
|