LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

simple example to write data to excel sheet

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.

 

0 Kudos
Message 1 of 6
(6,064 Views)

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

0 Kudos
Message 2 of 6
(6,051 Views)
I can't look at your VI right now but all that you need is Write to Spreadsheet File or a Write to Measurement File. Simple enough that you don't really need an example - the function can be the only thing on the block diagram (aside from the data).

Please make sure you have context help turned on. For simple questions like the path input and new path output, the help will explain everything. Simply, the path input is where you want the file saved. If you don't use a control or constant for the path, you will get a pop-up dialog asking for the path. The output then is then the selected path.
0 Kudos
Message 3 of 6
(6,049 Views)

Hi Lynn,

Thanks for the quick reply.I gave path to your vi for the file ex1.xlsx but it is showing this error

 

Excel_error.png     

 Is this something wrong with my MS_Excel or do I need to modify anything.

Thanks in Advance.

0 Kudos
Message 4 of 6
(6,035 Views)

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

0 Kudos
Message 5 of 6
(6,026 Views)

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.

0 Kudos
Message 6 of 6
(6,004 Views)