LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a new excel using an existing .xlsx template with each run/instance

The issue I am facing with this is that there is no new file created in the specified folder. Even the existing file does not have data added to it (though I have managed to do that separately, but that's not my desired outcome right now).

 

I want to use an existing .xlsx template, write data into its Sheet2 (to link to Sheet1) and save it as a new .xlsx file with a different filename (using datetime to differentiate). I'm using LabVIEW 2022 (32-bit). Apologies for any obvious mistakes, I'm fairly new to this software.

 

LVSnippet.jpg

 

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

To build a Path for a file, you should use the Build Path function.  I really dislike using a TimeStamp as a file name:  it gives you no clue what data the file contains, it is hard to sort, confusing to the eye to read, etc. 

 

To keep my files-of-the-same-type-of-information straight, I use the "Incrementing Suffix" function, which has (for my use) one tiny flaw -- if there are no files with the same name, it creates a file without a suffix.  I fix this by "wrapping" my own code around this function -- I create the file, and see if the "created name" is the same as the "starting name".  If so, I create it again (causing a name with the (001) sufffix to be generated) and delete the suffix-less name.  I don't remember, but you should probably close the un-suffixed file before deleting it.

Here's a Snippet:

Build Path + Incrementing Suffix.png

Bob Schor

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

@ashfeq :

Are you sure LV has the correct write privileges in the target folder? No error reported?


I replicated your code on my PC and the new file gets created correctly...


(yes, there are 'more elegant' ways of building a filepath 😉 )

0 Kudos
Message 3 of 9
(2,603 Views)

Things to check:

1. It automatic error handling turned on?  If not, then you will not see the error if the template file cannot be opened

2. Does the template document have a sheet 2?  If not, no data will be written

3. Single-step the code and see if your template has been opened, Sheet selected and data wriitten

4. Replace the hard-coded template name with a file path control and browse for the file.  This insures the path is correct.

5. Double-click the NI Excel VIs before running the program to see if the control values make sense

 

You named the image LVsnippet, but did not use the Edit -> Create VI Snippet to create it....

Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.0, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 4 of 9
(2,575 Views)

Thanks to all who replied,

 

I have managed to make some progress. Firstly, with the new changes I've made in reference to all your suggestions, I was able to create new .xlsx files with incrementing suffixes and removed the datetime naming as Bob suggested.

 

However, now, I am unable to open the excel file as it gives the error as attached in the image below. I don't think it is a problem with the permission for writing to the directory as I am able to create the files now, right?

 

Also, for Michael, I tried disabling the program from the 'Save file to report' till 'Dispose report' VIs. What it did was to write the array into Sheet2 of the original template excel 'LabViewTest'. Thanks for the help in creating a snippet! I've attached a proper one this time.

 

cd81b511-6c43-4eb1-9c96-f993f1e5bff2.png

 

testoutput.jpg

testoutput1.jpg

0 Kudos
Message 5 of 9
(2,545 Views)