From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write to spreadsheat file

LV 2014

 

Experimenting with write to spreadsheet file, substep of larger project. 

 

The problem seems to be the type of excel file. What file extension does "write to spreadsheet" want to see? I tried two ways that seem most likely. Each time I made a pre-existing excel file. Before running the vi, I pointed the file path to the excel file. I tried .xlsx and .xls

 

.xlsx extension I cannot reopen the file after running the vi. It says the "file or file format is invalid". 

 

.xls extension, I can open the file after running the vi, but there is a warning that says "The file you are trying to open [file name], is in a different file format than specified by the extension".  Or, there is no warning when I open the file, but there is no data saved either. 

 

Is there a preferred file extension? 

 

Eventually I want to save thermocouple data from a 9211 4 Ch TC input, in a cDAQ single slot chassis. 

Is write to spreadsheet a good way to log data. I've seen examples with "write to measurement file". I ran into trouble there, so wanted to avoid blue "helper" vi's. 

0 Kudos
Message 1 of 9
(2,936 Views)

Forget Excel. Write to Spreadsheet File.vi creates a tab-delimited TEXT file which can be read and interpreted by most spreadsheet programs, including the one I told you to forget. Write to Spreadsheet File does not care what extension you attach to the filename or whether you use no extension at all. Extensions are used by operating systems to associate files with applications. 

 

So when you put the .xls extension on a tab-delimited text file, the OS will tell Excel to open the file. Excel is able to interpret the contents of the file as data to put into a spreadsheet, but it also knows that the file is not in the Microsoft-defined .xls format. That is why you get the warning.

 

What do you really want to do with the file after writing the file with Write to Spreadsheet File.vi? Do you want to double-click the file and expect Excel to open it and not give you a warning?

 

Lynn

0 Kudos
Message 2 of 9
(2,921 Views)

Hi Carmen,

 

If you want to use Spreadsheet functions, better to pass .CSV files with comma/Tab/other (as you wish).

If you want to write data into Excel then use Report Generation Tool kit/ActiveX.

Munna
0 Kudos
Message 3 of 9
(2,908 Views)

And don't give a file name in Write to Spreadsheet file an .xls or .xlsx extension.  Because then you are just lying about what type of file it is.  While, like Lynn said, Excel knows how to open it, it is NOT an Excel file and you are just deceiving users into thinking it is an Excel file.

0 Kudos
Message 4 of 9
(2,894 Views)

This is an extremely common mistake.  Just use a txt extension and leave the delimiter as a tab.  You can always right-click on the file and do Open With->Excel.


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
0 Kudos
Message 5 of 9
(2,859 Views)

Thanks for replies everyone. 

I should have mentioned I'm using LV 2014 Base. It doesn't have the Report Generation toolkit. 

 

Yes, my dream is to double click and open the file in Excel. 

 

I did more reading in the help under File I/O. I'm still discovering where all the help, examples, and tips and tricks are. 

In LV Help, Contents, Fundamentals, File I/O, Spreadsheet Files, Creating Spreadsheet Files, it says: 

Note  For Microsoft Excel files (.xlsx), use the Write to Measurement File Express VI to save the dynamic data you acquire to an Excel file.

 

So maybe I should just get with the dynamic data type (some have called evil) and the Express VI, if it gets me to where I can double click the file open? I think there is an example. 

 

I'm also going to need to open and close the file. It will save data for up to a year or more. And we'll access the file for short periods during data collection. One saved temperature per day. Will the Express VI allow me to close the file so we can open it? 

 

 

 

 

 

 

 

 

 

 

0 Kudos
Message 6 of 9
(2,828 Views)

Hi Carmen

I apologize if I misunderstood any information on this thread. I would like to mention that the “evil” thing about Express VIs is usually related to the fact that you don’t actually have too much control over what is going on inside it. Express VIs like “Write to measurement file”, do perform everything from opening the file, writing the information to the file, and closing the file, which can result in a really inefficient code, depending on the way you use the VI. If you intend to write data only once in a day, I don’t think it is going to be a problem.

 So, I think that the answer to the question “Will the Express VI allow me to close the file so we can open it? Would be, yes, the express VI is supposed to leave the file closed after executing.

Regards

Wen R

0 Kudos
Message 7 of 9
(2,812 Views)

You can right click on the Express VI and pick Open Front Panel to see what it is doing under the hood.  I tried doing that on my end, but for some reason, it just keeps freezing up LabVIEW and never finishes creating the subVI I can open.

0 Kudos
Message 8 of 9
(2,802 Views)

@OriolesFan wrote:

You can right click on the Express VI and pick Open Front Panel to see what it is doing under the hood.  I tried doing that on my end, but for some reason, it just keeps freezing up LabVIEW and never finishes creating the subVI I can open.


I managed to do that a while ago.  You do NOT want to see the mess that is in there to create an xlsx file.


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
0 Kudos
Message 9 of 9
(2,788 Views)