LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble writing excel column titles in my measurement file.

Solved!
Go to solution

I have tried to look here on the forums how to title my columns in excel but none of the solutions seem to work. I tried maybe 5 or 6 different ways to get this to work and either it only writes the titles or it only writes the measurement data. I have two columns I'd like to title and this is the approach I though would work best but it doesn't Untitled6.png

0 Kudos
Message 1 of 22
(4,020 Views)

Does it have to be an Excel file? Or is a csv file OK too?

For CSV, you can use a whole collection of nodes that give you more control over what you're writing.

 

Alternatively, if you have the TDM Excel Plugin installed, you could save a TDM or TDMS file and that would include the headers.

I wasn't able to get the headers into Excel using this Express VI with a brief attempt.

 

I would like to point out there's a File Dialog Express VI if you want to prompt for the file path, and if you don't, you could just use a Path constant on the block diagram instead of the entire first loop.

If you want to wait until you press start, you could try the following:

Example_VI_BD.png

This uses an Event Structure.


GCentral
0 Kudos
Message 2 of 22
(3,897 Views)

If Csv can be opened in Microsoft Excel without or with little additional setup that might be an option. I thought about the tdms route, it's a good idea but I don't want to have to make all the people reading these have to get the plugin.

0 Kudos
Message 3 of 22
(3,883 Views)

Well first thing is you need to forget about the "Express VI's" those things were made for those 2 hour LabVIEW Seminars sales pitches just to show people like your manger how fast you can just throw something together in LabVIEW.

 

But for any "real" application they are useless.

 

I would start with something like this:

File1.png

========================
=== Engineer Ambiguously ===
========================
Message 4 of 22
(3,880 Views)

Excel will open a CSV without any additional steps.

When you close it prompts you a bunch to change to a different format (like xslx) if you make changes though, since CSV doesn't preserve some Excel-specific things (like column width, text fonts and colours, etc), which can be a bit annoying... (the prompting - I don't generally care about the column widths and so on).

 

You can probably find examples with the Example Finder, but a key VI to get you started might be this one: Write Delimited Spreadsheet VI. This is a higher-level VI that basically contains the Array To Spreadsheet String Function. In either case it seems you'll need to first write a line with the headers you want, so you can use Write to Text File for that, keeping the same separator (comma for csv, tab for tab-separated variables, either will open in Excel, LabVIEW defaults to tab for some reason...).

 

According to this documentation, you can also look at the following examples specifically:

Refer to the Tab-Delimited Data project in the labview\examples\File IO\Spreadsheet\Tab-Delimited Data directory for an example of streaming data to spreadsheet files. This example uses the Array to Spreadsheet String function which converts data of one data type to a spreadsheet string and writes the string to a file.

Refer to the Buffered Stream to Tab-Delimited Text File VI in the labview\examples\File IO\Spreadsheet\Tab-Delimited Data directory for an example of buffering data when streaming data to spreadsheet files.

 

Edit: RTSLVU beat me to demonstrate using the Write Delimited Spreadsheet node (twice, to add headers the first time) to write some data.


GCentral
0 Kudos
Message 5 of 22
(3,878 Views)

I'd like to use write deliminated spreadsheet however, it doesn't to my knowledge have the abilities that the write measurement file vi has. The timestamping, appending file, automatically detecting if the file exists and making a new one which is really handy. Is there any easy way to do that with the "Write Deliminated Spreadsheet" VI?

0 Kudos
Message 6 of 22
(3,869 Views)

Not all in one place...

You can use Create file with incrementing suffix to get a new file, appending will be automatic if you keep the reference open, but for timestamps you'd have to create your own array.

 

You can either use Format into String in a loop and write line by line in any format you'd like, or you could have the relative time as a double array with your data and then put the starting time/date and the top, for example.


GCentral
0 Kudos
Message 7 of 22
(3,865 Views)

If you need a time stamp then record the time when you take your measurement and put it in the data file, don't rely on Express VI's to do your work.

 

What if timing is critical? A few tenths of a second can make a huge difference. Using the Express VI you only have the time the data was written to the file, NOT the time the data was actually acquired.

 

Try this VI I made years ago for every time you write your data: It will append a timestamp to the first column, and add one when the data is written if you don't supply a timestamp when the data is acquired.

.TimetoFile.png

 

BTW: Don't freak out when you see this timestamp looks like a long number.... That's what a raw unformulated timestamp looks like...

 

Simply highlight the column in Excel and select "Format Column" from the pop-up menu and then select the time format you want to see.

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 22
(3,861 Views)

Could you link this VI?

0 Kudos
Message 9 of 22
(3,851 Views)

What version of LV are you using?

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 10 of 22
(3,831 Views)