Exchange Forum > Beta Testing Forum
GetExcel for Excel and AutoCAD applications.
Page 1 of 4
1 2 3 4
GetExcel for Excel and AutoCAD applications.

#1

Terry Cadd
Join Date:
09-10-2007
GetExcel is a general purpose function for (Excel to AutoCAD) and (AutoCAD to Excel) applications. Special credit to Gilles Chanteau from Marseille, France for his sub-functions ColumnRow, Alpha2Number and Number2Alpha. The syntax for the functions are easy to follow and include documentation of the conditions of each argument in the function headings.
Here are two examples for getting data from and putting data into Excel files.
 
Get Example:
Code:
(defun c:Get-Example ( )
  (GetExcel "C:\\Folder\\Filename.xls" "Sheet1" "L30");<-- Edit Filename.xls
  ;Syntax: (GetExcel ExcelFile$ SheetName$ MaxRange$)
  (GetCell "H21");Or you can just use the global *ExcelData@ list
  ;Syntax: (GetCell CellName$)
);defun
Put Example:
Code:
(defun c:Put-Example ( )
  (OpenExcel "C:\\Folder\\Filename.xls" "Sheet1" nil);<-- Edit Filename.xls
  ;Syntax:  (OpenExcel ExcelFile$ SheetName$ Visible)
  (PutCell "A1" (list "GP093" 58.5 17 "Base" "3'-6 1/4\""));Repeat as required
  ;Syntax:  (PutCell StartCell$ Data$) or (PutCell StartCell$ DataList@)
  (CloseExcel "C:\\Folder\\Filename.xls");<-- Edit Filename.xls
  ;Syntax:  (CloseExcel ExcelFile$)
  (princ)
);defun
Beta test it and tell me what you think.
Terry
 
Here's the link for the lastest version of GetExcel.lsp:
http://web2.airmail.net/terrycad/LISP/GetExcel.lsp
GetExcel for Excel and AutoCAD applications.

#2

Cricket
Join Date:
08-30-2007
I test your program here at work using the get-example and put-example sample with my code and work very well. Very nice.
GetExcel for Excel and AutoCAD applications.

#3

JPS
Join Date:
10-06-2007
Terry,
 
Looks good! I did not have any problems. I tested with AutoCAD 2007 and Excel 2003.
 
JPS
GetExcel for Excel and AutoCAD applications.

#4

Terry Cadd
Join Date:
09-10-2007
The GetExcel.lsp file has been recently revised. I have added several sub-functions written by Gile including Cell-p, Row+n, and Column+n. I also added his revision of the PutCell function. You can download the latest version from this thread.
GetExcel for Excel and AutoCAD applications.

#5

Danubiana
Join Date:
01-29-2008
Hi Terry,
 
There is a problem when I try to open an Excel file (data base linked at start)
Not update and when I try to open another excel files....all are hiden.
Closing the .dwg....all are OK...back....
I have EXCELL RAPORTS who use .csv file, update to open.
1.How can I use this RAPORTS directly from autocad?
2. .xlt (excel template) are available?
 
And do not forget...you are the best!
GetExcel for Excel and AutoCAD applications.

#6

Terry Cadd
Join Date:
09-10-2007
I am not familiar with the RAPORTS program. So I can't help you with that.
Note in the following section of the code in GetExcel.lsp
that it is checking to see if you have or recently had an Excel application opened.
Before you select the OK button in the alert message dialog,
toggle to any Excel application that may be opened and save you work and exit.
This program takes full control over Excel and opens and closes it
per the code specified by your programming request.
Note: The files are saved as *.xls and it only reads *.xls file also.
 
Code:
(if (setq *ExcelApp% (vlax-get-object "Excel.Application"))
  (progn
    (alert "Close all Excel spreadsheets to continue!")
    (vlax-release-object *ExcelApp%)(gc)
  );progn
);if
GetExcel for Excel and AutoCAD applications.

#7

Danubiana
Join Date:
01-29-2008
I have many blocks who are exported as .csv files(attribute extractions)
I have excel templates who use these .csv, they are fill automatically with values at the same time opened.(EXCEL OPEN DATA BASES)
That means an EXCEL "Raport" open another file, a csv one.
So I have a shortcut at this template (xlt) on desktop.
example:
1 export to csv
2 minimize AutoCAD
3 open from shortcut this XLT
(who open the csv)
All together means a single command, but I have this problem.
If Excel file is a xls file....the same....it do not want to open a another file..
...the tree do not want another branch
...how I can do it?
GetExcel for Excel and AutoCAD applications.

#8

Terry Cadd
Join Date:
09-10-2007
Danubiana,
I hadn't considered CSV files for the GetExcel.lsp program so I didn't test it. This afternoon I decided to just try it and see what happens. It will work with CSV files also. My apologies!
Terry
 
Code:
Here's an example to get information from a CSV file:
(GetExcel "C:\\Temp\\TestExcel.csv" nil "L25")
(GetCell "A25") = "OSB-Z1"
 
Here's an example to put information into a CSV file:
(OpenExcel "C:\\Temp\\TestExcel.csv" nil nil)
(PutCell "L1" "Test")
(CloseExcel "C:\\Temp\\TestExcel.csv")
GetExcel for Excel and AutoCAD applications.

#9

Danubiana
Join Date:
01-29-2008
Hi Terry,
I need a shortcut who open an EXCEL file (xls or xlt)....not csv
My EXCEL file (reports) open a data base (.csv file) when they are opened.
With your code I can not open an excel file who need to open a data base source(csv).
My REPORTS file at starting open another files.
Your code opens a XL file, it's OK, but if these XL need for data links...open a blank XL....
An XL file can contain many links (data, internet links...)
I think AutoCAD is the problem...until now I didn't see a situation when AutoCAD let a total control of the application opened.
Let see your idea
GetExcel for Excel and AutoCAD applications.

#10

Terry Cadd
Join Date:
09-10-2007
Hi,
Were you able to get it working at all, as per the few example lines I provided? As far as I recall, it only works on one open worksheet at a time.
Terry
 
Here is an example of a list of lists to put into Excel:
Code:
(defun c:TestExcel (/ DataInfo@ DataList@ Index#)
  (setq DataInfo@
    (list
      (list "NameA1" "PriceB1" "ProducerC1" "DimensionD1")
      (list "NameA2" "PriceB2" "ProducerC2" "DimensionD2")
      (list "NameA3" "PriceB3" "ProducerC3" "DimensionD3")
      (list "NameA4" "PriceB4" "ProducerC4" "DimensionD4")
      (list "NameA5" "PriceB5" "ProducerC5" "DimensionD5")
    );list
  );setq
  (OpenExcel nil nil nil);See note below.
  (setq Index# 1)
  (foreach DataList@ DataInfo@
    (setq CellName$ (strcat "A" (itoa Index#)));= A1 A2 A3 etc.
    (PutCell CellName$ DataList@)
    (setq Index# (1+ Index#))
  );foreach
  (CloseExcel "C:\\Temp\\TestExcel.xls")
  (princ)
);defun c:TestExcel
;Note: If the file C:\Temp\TestExcel.xls exist,
;then use (OpenExcel "C:\\Temp\\TestExcel.xls" nil nil)
Page 1 of 4
1 2 3 4