LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems writin to spreadsheet

Solved!
Go to solution

Hello again. I am playing with a serial device and trying to get it to write data to a .csv file. I have attached my little test piece. I am able to get it to write however, all it writes is "0", when I am watching the device change values. I am trying to figure out how to get the actual data to write on the spreadsheets and, insttead of them filling one collumn, I would rather it spread them across the row. Thank you

0 Kudos
Message 1 of 17
(4,347 Views)

no code attached


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 17
(4,343 Views)

Crud, sorry about that. Here it is

0 Kudos
Message 3 of 17
(4,334 Views)

Also, if I may, I would like to confirm I am using the correct Vi for the data collection. I would like to have it load the data onto an Excel spreadsheet that has headers on it all ready. For example, along the top row I would like it to already have text that labels each column, such as "Voltage", "Capacitance", and "Displacement". The way I planned on doing it was to have the test results populate the cells below each column of a certain spreadsheet and then have the technician perform a "save as" so that the template, if you will, always remains the same. The challenge is making sure the operator doesn't save my template, with their test reults on it. Thank you

0 Kudos
Message 4 of 17
(4,305 Views)

Just to clarify some terminology, "Excel" and "Spreadsheet" are not the same thing.  LabVIEW's Write to Spreadsheet function writes a character-delimited (default = tab, usual "alternate" choice = comma) text file.  If commas are used as the delimiter and the extension is ".csv", then Microsoft Excel can open this file and display it as through it were an Excel Workbook (.xls or .xlsx format).

 

I tend to use "real Excel" and to read/write .xlsx files, using the Report Generation Toolkit.  However, in recent weeks, I've played with Write to Spreadsheet, and it actually has some useful features that can probably help you out.

 

First, it is easy to have this function simply write the Column Headers first.  Before you enter your loop, open the File you want to use as your output file, create a 1D array of the column headers, and feed it to Write to Spreadsheet, but with the Append to File input False.  This creates what you are calling your Template.  Now when you write inside the loop with Append to File = True, the data rows will appear just below the Header Row, what I think you want.

 

Bob Schor

Message 5 of 17
(4,290 Views)

Hmmmm, not exactly sure what you are saying. Are you saying I should open the write to spreadsheet file before I  begin my loop execution, write to it, close it, then when the loop executes open it again and write my data to it? I am trying to establish a visual as to how I will create the Vi doing this. I will try, thank you.

0 Kudos
Message 6 of 17
(4,283 Views)

Your code for writing to a file works correctly, it must be your serial acqusition code that is getting all zeros.  I took your example and replaced the serial acquisition piece with a piece that generates a random number.  Your code has no problem writing these numbers to file.

Message 7 of 17
(4,277 Views)

When I use my NI Instrument Simulator it also writes to it. However, when I use the LCR meter it continues to put "0" in all the rows. On the front panel it shows what the LCR is inputing to the LV is correct, but on the spreadsheet, no such luck.

0 Kudos
Message 8 of 17
(4,270 Views)

I still have not figured out how to do what you are suggesting, about the header. I did find the reason I was only getting "0"s. On the write to spreadsheet I had to change the format to "%d" as opposed to "%.3f", the default. Reading the help section on this sub Vi leads me to believe the default setting should have worked alson So when I run it now I get "5.67E-07", for example. As far as a header, I am still trying to build something I think you are saying.

0 Kudos
Message 9 of 17
(4,258 Views)
Solution
Accepted by topic author ceilingwalker

I'm sorry my attempt to write clearly failed so badly.  Here is a Snippet that writes a Spreadsheet (and reads it back to show you what has been written).  The Data are 5 rows of 3 columns of random numbers.  The Spreadsheet has a Header Row with Column 1, Column 2, and Column 3, and the data are written a row at a time to the same Spreadsheet.  There is a For Loop with an index of 5 that is the "Generate and Save the Data" loop -- it could be a While loop controlled by a Stop Control.  The 3-indexed For loop before entering the Acquisition Loop is to generate and write the three-column Header Row.  When we exit the Acquisition Loop, we read the Spreadsheet to be sure it did what we wanted it to do.

 

So my question is, did you try to get this to work?  You should have been able to whip up this little demo program yourself.  If you are having trouble with something in LabVIEW (like figuring out how Write to Spreadsheet works), it is much easier (not to mention faster, and more fun) to not try to debug it inside a much larger routine where lots of other things are going on.  Write a tiny demo program (such as shown below) that just tests what you are trying to understand.  If it doesn't work, read the LabVIEW Help, experiment with settings, and if you need to go to the Forum, post the little Demo routine.

Spreadsheet with header.png

 

When I went to post this Snippet, I forgot that I'd answered a similar question in the Forums about two weeks ago.  There I included how to do this to an Excel Workbook, as well as a LabVIEW "Spreadsheet".  Here it is (very similar, of course ...).

Spreadsheet with header.png

Hmm -- looks like I forgot to put the File Specification in the Write-to-Spreadsheet part of this example ...

 

Bob Schor

 

Message 10 of 17
(4,244 Views)