MR MAN Posted December 28, 2008 Author Posted December 28, 2008 ANY HELP TO GET NAMES OF LAYOUTS FROM EXCEL CELLS? TAKE IN MIND DWG FILES HAVE 1 LAYOUT SO I NEED OPEN FILE RENAME LAYOUT FROM CELL A1 IN EXCEL FILE AND THEN SAVE AND CLOSE AND SO ON I CAN MAKE THE BATCH FILE BUT I NEED COMMAND LIKE LISP TO DO THAT? Quote
Lee Mac Posted December 28, 2008 Posted December 28, 2008 I would have thought one could just use "read-line" on an excel file, but this seems to just return "nil" on every iteration... not sure why? Quote
MR MAN Posted January 3, 2009 Author Posted January 3, 2009 Ok Can You Put It And We Will Find A Solution From Other Guys Let Us Think Together Quote
ASMI Posted January 3, 2009 Posted January 3, 2009 I would have thought one could just use "read-line" on an excel file, but this seems to just return "nil" on every iteration... not sure why? Because it isn't text file. You shoud use Visual LISP functions as (vlax-get-object, (vlax-create-object, (vlax-get-or-create-object to work with Excel or other applications which has COM interface. Quote
MR MAN Posted January 3, 2009 Author Posted January 3, 2009 Please Asmi Can You Explain More BY Add Simple Example Thanks For Help Quote
Lee Mac Posted January 3, 2009 Posted January 3, 2009 Because it isn't text file. You shoud use Visual LISP functions as (vlax-get-object, (vlax-create-object, (vlax-get-or-create-object to work with Excel or other applications which has COM interface. Ahh, again, Visual LISP is my downfall Quote
ASMI Posted January 4, 2009 Posted January 4, 2009 ok iam waiting guys JONEPOPE, are you assured that this example is really necessary to you? This really short example reads A1 value from *.xls file specified and show alert window: (defun c:extest1(/ eFile A1Value A1Range Workheet cFile Workbooks Excel) (vl-load-com) (if(setq eFile(getfiled "Select *.xls file" "" "xls" 4)) (progn (setq A1Value(vlax-variant-value(vlax-get-property (setq A1Range(vlax-get-property (setq Workheet(vlax-get-property (setq Worksheets(vlax-get-property (setq cFile(vlax-invoke-method (setq Workbooks(vlax-get-property (setq Excel(vlax-get-or-create-object "Excel.Application")) 'Workbooks)) 'Open eFile)) 'Worksheets)) 'Item 1)) 'Range "A1"))'Formula))) (alert(strcat eFile "\n" "A1 Value = " A1Value)) (vlax-release-object A1Range)(vlax-release-object Workheet)(vlax-release-object Worksheets) (vlax-invoke-method cFile 'Close)(vlax-release-object cFile) (vlax-invoke-method Excel 'Quit)(vlax-release-object Excel) ); end progn ); end if (princ) ); end of c:extest1 I hope you can rename your layouts now. Quote
Lee Mac Posted January 4, 2009 Posted January 4, 2009 Blimey ASMI, that is a surprisingly long amount of code to just read a cell from Excel! Quote
ASMI Posted January 4, 2009 Posted January 4, 2009 Blimey ASMI, that is a surprisingly long amount of code to just read a cell from Excel! In it there is nothing surprising because required to pass the way from root Excel object to a cell: Excel > Workbooks Collection > Workbook > Worksheets Collection > Worksheet > Cells Range > Cell > Value. As in every application with COM interface. To read or write any other quantity of cells over not much more code, should simply to add a loop. Quote
Lee Mac Posted January 4, 2009 Posted January 4, 2009 Oh, its just because I have never come across COM interfaces. Quote
MR MAN Posted January 5, 2009 Author Posted January 5, 2009 THANKS GUYS FOR HELP BUT I HAVE SMALL QUESTION FOR YOU ASMI IF I NEED TO FIXED PATH OF EXCEL FILE I TRY THAT (if(setq eFile(getfiled "Select *.xls file" "C:\MINE\W.XLS" "xls" 4)) BUT MENU STILL APPEAR I WANT IT DISAPPEAR AND TAKE MY EXCEL FILE DIRECTLY Quote
Lee Mac Posted January 5, 2009 Posted January 5, 2009 Just use: (open "...filepath" "r") In your case: (open "C:\\MINE\\W.XLS" "r") Quote
ASMI Posted January 5, 2009 Posted January 5, 2009 THANKS GUYS FOR HELP BUT I HAVE SMALL QUESTION FOR YOU ASMI IF I NEED TO FIXED PATH OF EXCEL FILE I TRY THAT (if(setq eFile(getfiled "Select *.xls file" "C:\MINE\W.XLS" "xls" 4)) BUT MENU STILL APPEAR I WANT IT DISAPPEAR AND TAKE MY EXCEL FILE DIRECTLY Change (if(setq eFile(getfiled "Select *.xls file" "C:\MINE\W.XLS" "xls" 4)) to (setq eFile "C:\\MINE\\W.XLS") Quote
MR MAN Posted January 5, 2009 Author Posted January 5, 2009 thank you very much asmi for your help and either you lee mac thanks guys for help Quote
MR MAN Posted January 6, 2009 Author Posted January 6, 2009 SORRY ASMI CAN YOU HELP ME IN THE FOLLOWING: WHEN I TRY MAKE ANOTHER LISP FOR CELL A2 BY USING YOUR LISP I REPLACE A1 AND ANY THING RELATED TO IT BY A2 AND SO ON BUT IT DOES NOT WORK ANY HELP FOR THAT Quote
CAB Posted January 6, 2009 Posted January 6, 2009 Here is some homework for you. http://cadtutor.net/forum/showpost.php?p=113667&postcount=8 Quote
CAB Posted January 6, 2009 Posted January 6, 2009 More stuff. ;------------------------------------------------------------------------------- ; Program Name: GetExcel.lsp ; Created By: Terry Miller (Email: terrycadd@yahoo.com) ; (URL: http://web2.airmail.net/terrycad) ; Date Created: 9-20-03 ; Function: Several functions to get and put values into Excel cells. ;------------------------------------------------------------------------------- ; Revision History ; Rev By Date Description ;------------------------------------------------------------------------------- ; 1 TM 9-20-03 Initial version ; 2 TM 8-20-07 Rewrote GetExcel.lsp and added several new sub-functions ; including ColumnRow, Alpha2Number and Number2Alpha written ; by Gilles Chanteau from Marseille, France. ; 3 TM 12-1-07 Added several sub-functions written by Gilles Chanteau ; including Cell-p, Row+n, and Column+n. Also added his ; revision of the PutCell function. ;------------------------------------------------------------------------------- ; Overview of Main functions ;------------------------------------------------------------------------------- ; GetExcel - Stores the values from an Excel spreadsheet into *ExcelData@ list ; Syntax: (GetExcel ExcelFile$ SheetName$ MaxRange$) ; Example: (GetExcel "C:\\Folder\\Filename.xls" "Sheet1" "L30") ; GetCell - Returns the cell value from the *ExcelData@ list ; Syntax: (GetCell Cell$) ; Example: (GetCell "H15") ; Function example of usage: ; (defun c:Get-Example () ; (GetExcel "C:\\Folder\\Filename.xls" "Sheet1" "L30");<-- Edit Filename.xls ; (GetCell "H21");Or you can just use the global *ExcelData@ list ; );defun ;------------------------------------------------------------------------------- ; OpenExcel - Opens an Excel spreadsheet ; Syntax: (OpenExcel ExcelFile$ SheetName$ Visible) ; Example: (OpenExcel "C:\\Folder\\Filename.xls" "Sheet1" nil) ; PutCell - Put values into Excel cells ; Syntax: (PutCell StartCell$ Data$) or (PutCell StartCell$ DataList@) ; Example: (PutCell "A1" (list "GP093" 58.5 17 "Base" "3'-6 1/4\"")) ; CloseExcel - Closes Excel session ; Syntax: (CloseExcel ExcelFile$) ; Example: (CloseExcel "C:\\Folder\\Filename.xls") ; Function example of usage: ; (defun c:Put-Example () ; (OpenExcel "C:\\Folder\\Filename.xls" "Sheet1" nil);<-- Edit Filename.xls ; (PutCell "A1" (list "GP093" 58.5 17 "Base" "3'-6 1/4\""));Repeat as required ; (CloseExcel "C:\\Folder\\Filename.xls");<-- Edit Filename.xls ; (princ) ; );defun Quote
CAB Posted January 6, 2009 Posted January 6, 2009 And more.... ;; http://www.jefferypsanders.com/autolisp_XL.html ;;;--- XL_GET.lsp - Function to retrieve data from a selected sheet ;;; inside an EXCEL workbook. ;;; ;;; ;;;--- Copyright 2005 by JefferyPSanders.com ;;; All rights reserved. ;;; ;;; ;;; ;;;--- Version 3.1 ;;; ;;; 4/12/04 Revision - Revised name of dialog box ;;; Revised order to search for excel Libraries ;;; 8/31/04 Revision - Revised the sort function for the chart routine. ;;; Added the ability to handle LOGICAL data from Excel. ;;; 3/31/05 Revision - Revamped the method of informing the user of progress. ;;; Fixed a bug with null text strings. ;;; 5/5/05 Revision - Added an error message when the DCL file is not found. ;;; ;;; ;;; ;;; ;;;--- Usage: (setq myList(XL_GET)) ;;; ;;;--- Returns a list in the form of: ;;; ;;; (list ;;; (list "A1" "cellValue") ;;; (list "B1" "cellValue") ;;; (list "C1" "cellValue") ;;; ) ;;; ;;;--- Example: ;;; ;;; (setq data(XL_GET)) - Would return the list of data from Excel. ;;; ;;; (cadr(assoc "C3" data)) - Would return the value for the cell ;;; at Column C Row 3 in the spreadSheet. Quote
CAB Posted January 6, 2009 Posted January 6, 2009 There everywhere:shock: http://forums.augi.com/showpost.php?p=593577&postcount=5 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.