LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble writing excel column titles in my measurement file.

Solved!
Go to solution

2019 demo

0 Kudos
Message 11 of 22
(835 Views)

Okay I am going to attach two versions of this VI. 

 

  1. "Write to xls file with timestamp.vi"
    1. This one uses the "File Path" wire. It works but has one caveat.
    2. The data file is NOT locked by Windows when the program is running. So this means if anyone or another program opens the file between LabVIEW writes. The next time LV tries to access the file, LV will get an sharing violation error and crash your program if you are not handling errors gracefully.
  2. "Write to xls file timestamp ref.vi"
    1. With this you have to use the "Open/Create/Replace File" primitive first to open the data file and pass the File Reference instead of the File Path.
    2. This has the benefit of  locking the data file while LabVIEW has it open. This will prevent sharing violations if someone tries to look at the data file while LV has it open.
    3. You can still look at the file but Windows will tell you it is in use and offer to open a copy instead.
    4. Don't forget to close the file before you exit your program!

The VI that passes the reference is the one you should use.

========================
=== Engineer Ambiguously ===
========================
Message 12 of 22
(831 Views)

Unfortunately, "Write Deliminated Spreadsheet" Doesn't work as it doesn't put the titles in and it only writes the first two measurements in and then stops for some reason. Here is what I got for output. It was supposed to list many rows but there's only one and the two titles didn't get written either. Might just forgo the titles for now.

0 Kudos
Message 13 of 22
(818 Views)

You are doing it wrong!

 

I do this all the time here's some ideas...

 

  1. Open a file
  2. Write column headers
  3. Enter acquisition loop
  4. Acquire data
  5. Write it to the file
  6. Goto 4 until acquisition is completed
  7. Close data file
  8. Exit
========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 14 of 22
(813 Views)

I have tried that before but it didn't work properly. Is there a way to convert strings to signals? I tried using Decimal String To Number and it compiled alright but never wrote the strings to the spreadsheet.

0 Kudos
Message 15 of 22
(809 Views)
Solution
Accepted by topic author crash_override

Here is an example of what I do:

I open the file and write my headers basically at the same time...

OpenCapture.PNG

Notice I use the Open or create file primitive then pass the reference to write to text file primitive to write the headers.

========================
=== Engineer Ambiguously ===
========================
Message 16 of 22
(797 Views)

That will put them all in different columns of the excel file? I just got word that I have to do this in csv and not excel so now I have to figure that out instead.

0 Kudos
Message 17 of 22
(794 Views)
Solution
Accepted by topic author crash_override

This creates a TAB delimited file, if you want comma delimited (csv) then swap the Tab constant for a comma.

 

But yes this will put each header in a column

 

BTW: that's what the "delimiter" does, when Excel or any modern spreadsheet program opens the file it uses the delimiter to make columns.

========================
=== Engineer Ambiguously ===
========================
Message 18 of 22
(792 Views)

Thank you, I didn't know that's how it worked, thanks for clearing it up and for the examples.

0 Kudos
Message 19 of 22
(781 Views)

BTW: I prefer TAB delimited because it puts the data in columns even using Notepad to view the data file. That makes it easier to read compared to a .csv file that scrunches everything together when you look at the file in a text editor. 

========================
=== Engineer Ambiguously ===
========================
Message 20 of 22
(734 Views)