Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data from Exel

Status
Not open for further replies.

zliazmei

Structural
Feb 5, 2002
97
Hi everybody,

I am wondering, is there any way to extrude data from Exel file and to use it in my lisp routine??

Please help

Zmei
 
Replies continue below

Recommended for you

Dear zliazmei,
There is some facilites lets you extract data from Excel and use it in AutoCAD. I will check it for you and if I find the way, I will let you know about it.
:)
Farzad
 
Hi,
I dont know if this will be of any use, but you can generate scripts from excel spreadsheets using scriptsheets.com scriptwriter(and its free).
Peter
 
Here is an excerpt from a Bill Kramer article at Autodesk:

;; Point A
;; A scroll from the Wizard's Lab.
;;
;; Bill Kramer 2002
;;
;; Interface with Excel Worksheet
;;
;; Global Variables
;; xL - Object reference to EXCEL instance
;; myXLWbs - Object reference to EXCEL work books
;; myXLWb1 - Object reference to Work book #1
;; myXLShs - Object reference to Sheets in Work book
;; myXLSh1 - Object reference to Sheet 1
;; myXLNms - Object reference to list of named cells
;;
(vl-load-com)
;
;;-----------------------------------------------
;; Open link to EXCEL spreadsheet, use existing
;; instance of EXCEL if one exists otherwise
;; load EXCEL and then open the file supplied
;; as the variable xLFile.
;;
(defun Link_2_Excel (xLFile)
(setq xL ;Attempt to open existing or create new Excel instance
(vlax-get-or-create-object "Excel.Application"))
(if xL ;;success?
(progn
(if (and xLFile (findfile xLFile)) ;;Was a file name supplied?
(progn
;;
;; We have the application object, now we need to tunnel
;; down into a work book.
;;
(if (null xl-open) ;;Check to see if type library defined
;;It is not, import the type library for EXCEL
(vlax-import-type-library
:tlb-filename "C:/Program Files/Microsoft Office/Office/Excel8.olb"
:methods-prefix "xL-"
:properties-prefix "xLp-"
:constants-prefix "xLc-"))
;;
;; Now dig into the EXCEL object
(setq myXLWbs (vlax-get xL "Workbooks") ;workbooks
myXLWb1 (xl-open myXLWbs xLFile) ;open a workbook
myXLShs (vlax-get myXLWb1 "Sheets") ;worksheets
myXLSh1 (xlp-get-item myXLShs "Sheet1") ;worksheet number 1
myXLNms (vlax-get myXLWb1 "Names") ;get reserve names
)
)
)
)
)
xL ;;return the object reference
)
;;----------------------------------------
;; Given a name that represents a variable in the EXCEL spreadsheet,
;; send the value in VAL to EXCEL.
;;
;; Note that the linkage to EXCEL MUST be determined before calling
;; this function!
;;
(defun Update_Variable (Varname ;;Variable name
Val ;;Value to write to spreadsheet
/
TMP ;;Named object reference
Rng) ;;Range in spreadsheet (location)
(setq TMP
(vl-catch-all-apply ;;Catch errors if they happen
'vla-item ;;Get the name from the names collection
(list
myXLNMS ;;collection of names from Link_2_Excel
VarName)))
(if (and ;;No errors and item found?
(not (vl-catch-all-error-p TMP))
(setq Loc1 (vlax-get TMP "Value")))
(progn ;;yes, get the range of the named item and update the value
(setq Rng (xlp-get-range Sh1 Loc1))
(xlp-put-value Rng Val)
)
)
)
;;-----------------------------------------------
;; Close the EXCEL spread sheet after saving it.
;;
(defun Close_XL (SaveFileName)
(xl-saveas myXLSh1 SaveFileName)
(xl-close myXLWb1)
)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor