11-10-2013 01:50 PM
Hi everyone,
I am new to labview.I am trying to write a data to excel in labview2011 and searched in the forum for the similar posts and found so many that seemed too complicated for me.One of them is http://forums.ni.com/t5/LabVIEW/Need-simple-example-for-writing-to-Excel/td-p/277411/page/5
I tried as attached in the vi but confused with the file path and new file path as I didn't understood them.
Can someone post a simple vi to write data to excel spreadsheet.
Thanks.
11-10-2013 02:58 PM
Your VI should be writing a file which Excel can open. Write to Spreadsheet File.vi writes a tab-delimited text file. Almost any program can open such files.
File path is an input. Please look at the detailed help for Write to Spreadsheet File.vi.(With the Context help window shown, click on the link at the bottom of the window to open the Detailed Help). It specifies that if file path is empty, then a file dialog will pop up. If a valid path is wired to the input, the data will be written to the file.
New file path is an output. Its value will be the path to the file written. If Cancel was selected by the user in the file dialog, the output will be Not a Path. Not a Path is a special value of the path datatype which indicates that no valid path is present.
I modified your VI in two ways. First I added Wait (ms) so that it runs ~ 1 time per second. Without the wait it will run as fast as possible. In your VI the speed will be limited by how fast the OS can open/write/close a file - except that it asks the user for a file path each time. Second I added a shift register. This passes data from the output of one iteration of the loop to the input of the next iteration. It is initialized (left side of loop) with an Empty Path constant, so that on the first iteration the VI prompts for a file path. The new file path output is wired to the shift register terminal on the right side of the loop. On the second (and all subsequent) iterations the same file path chosen by the user on the first iteration is used without the file dialog.
Lynn
11-10-2013 03:02 PM
11-10-2013 04:22 PM - edited 11-10-2013 04:23 PM
Hi Lynn,
Thanks for the quick reply.I gave path to your vi for the file ex1.xlsx but it is showing this error
Is this something wrong with my MS_Excel or do I need to modify anything.
Thanks in Advance.
11-10-2013 04:33 PM
Try calling it a text file, extension = .txt
Excel can open text files. The file created by the VI is NOT in .xlsx format and that may have confused Excel. I do not have Excel to test it.
Lynn
11-10-2013 10:36 PM
The Report Generation Toolkit provides "hooks" that allow LabVIEW to read from and write to Excel Workbooks. However, if you are "new to LabVIEW", starting by trying to interface with Excel is a challenging way to begin! Do you have the rest of the code developed? You can always write a "Simulate Reading from Excel" VI that "makes up" the data you hope to get from Excel, and use this to develop the rest of your application. Once you have this, it should be simple to illustrate the calls to the Report Generation functions to do the Excel I/O you need.