Search the Community
Showing results for tags 'getexcel'.
-
Using GetExcel to read data from multiple sheets
teebro posted a topic in AutoLISP, Visual LISP & DCL
Hi Everyone, I'm new to AutoCAD lisp and have a couple of questions regarding GetExcel from the GetExcel.lsp functions. I am generating several tables using data from an excel spreadsheet. The spreadsheet contains several "Sheets" and a new table will be generated from each sheet. It will be unknown how many "Sheets" the excel spreadsheet will have. I do not see any easy way to find out how many sheets are in the spreadsheet so I wrote a function that will call GetExcel and compare cell "A1" with a known value. This value should be in cell "A1" for all used sheets. My problem is that if a blank sheet is not added as the last sheet my function will fail. I do not know a lot about the GetExcel code but it appears that if a particular sheet is requested and is not in the spreadsheet the function returns the sheet that corresponds to the looped sheet number. For example if a spreadsheet has 3 sheets and you request "Sheet4" it returns the data from "Sheet1". The idea was for the LISP routine to call GetExcel with successive "Sheet" numbers, test "A1" for a particular value, if the value was expected then save the *exceldata@ array to a new variable to get the next sheet. I was also under the impression that the "GetExcel" function opened the excel file, grabbed the data and closed it. When GetExcel is called multiple times a popup is presented prompting the user to "Close all excel spreadsheets to continue". When "OK" is pressed the function works as expected. I'm probably not using the GetExcel code as it was intended but maybe someone can help me out. I have posted some code that I was initially testing with to get the number of sheets in the spreadsheet. TIA (defun GetSheetCount ( excelfile / count continue ) (setq count 1) (setq continue 1) (while (= continue 1) (progn (getexcel excelfile (strcat "Sheet" (rtos count 2 0)) "A1") (if (= (car (car *exceldata@)) "Section Title") (progn (setq count (1+ count)) ) (setq continue (1- continue)) ) ) ) (1- count) )- 3 replies
-
- getexcel
- excel to autocad
-
(and 1 more)
Tagged with: