Lee Mac Posted December 14, 2008 Share Posted December 14, 2008 This thread is solely in response to an original thread posted by Gazzalp, which needed the extraction of various data to an excel spreadsheet. But I am intrigued, as I too do not know the first thing about writing data to external programs such as Excel. If, for instance, one has variables: var1, var2, var3; can one write the values of these variables to various cells in an Excel Sheet? or lines in a Txt doc? And if so, how? Help & advice is always appreciated. Quote Link to comment Share on other sites More sharing options...
fuccaro Posted December 14, 2008 Share Posted December 14, 2008 The simplest way is to write in text files. First define and open a file for writing: (setq file (open "my_file.txt" "w")) Now you can write into it, just convert the data to be written into string: (write-line (rtos var1) file) when finished, close the file (close file) Better see in AutoLISP help file the commands Open, Close, Write-char, Write-line, print, ... Also Getfiled worth a look Sometimes I write in the same way but in files with extension CSV instead of TXT. Those files can be opened in Excel. Just be carefull to write a comma in the file to separate two neighbor data. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 14, 2008 Author Share Posted December 14, 2008 I have created a test txt file in a known directory, and have used your example to write the line to the text file. but, after closing the file using (close "file"), and manually opening the file myself, nothing seems to be written... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 14, 2008 Author Share Posted December 14, 2008 Don't mind me, I just didn't include the filename in the (write-line parenthesis... As usual, more coffee needed... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 14, 2008 Author Share Posted December 14, 2008 Thanks for all your help Fuccaro, the LISP is working perfectly - the csv file is a good option, and I see what you mean about commas! Quote Link to comment Share on other sites More sharing options...
fuccaro Posted December 15, 2008 Share Posted December 15, 2008 Glad to see an other happy man! Quote Link to comment Share on other sites More sharing options...
VVA Posted December 15, 2008 Share Posted December 15, 2008 For record in Excel look functions XLS and XLSF Quote Link to comment Share on other sites More sharing options...
David Bethel Posted December 15, 2008 Share Posted December 15, 2008 Lee Mac, You may also want to think about exporting in an AutoLisp list format (setq x 45 y 50 z 55) (setq wf (open "mydata.dat" "w")) (write-line "(setq mydata '(" wf) (foreach v '(x y z) (princ "(" wf) (prin1 v wf) (princ (strcat " . " (rtos (eval v) 2 ")") wf) (write-line "" wf)) (write-line "))" wf) (close wf) Then you access it later by using the (load) function Command: (load "mydata.dat") Command: !mydata ((X . 45.0) (Y . 50.0) (Z . 55.0)) (assoc 'x mydata) (cdr (assoc 'x mydata)) This is very similar to a XML file but in AutoLISPs list format. -David Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 15, 2008 Author Share Posted December 15, 2008 Thanks David, thats very clever. Quote Link to comment Share on other sites More sharing options...
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.