ACAD_TABLE to Excel

Discussion in 'AutoCAD' started by kozmos, Apr 7, 2005.

  1. kozmos

    kozmos Guest

    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?
     
    kozmos, Apr 7, 2005
    #1
  2. kozmos

    Dann Guest

    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
    )
     
    Dann, Apr 7, 2005
    #2
  3. kozmos

    Tim Decker Guest

    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!!!
     
    Tim Decker, Apr 7, 2005
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.