07-28-2017 11:02 AM
Hello,
How do you go about creating a new excel workbook if one does not exist within LabVIEW. Currently, I have to manually create an excel file then copy that path into LabVIEW for the program to run. I wanted to generate a new Excel file within LabVIEW.
Thanks.
07-28-2017
11:17 AM
- last edited on
04-14-2025
03:45 PM
by
Content Cleaner
Well I have to say I have never used the LabVIEW report generation toolkit because it requires Word or Excel to be installed on the target machine to work. But this example (Excel Report - Conditionally Formatted Spreadsheet.vi) shows how to create a new Excel workbook.
I prefer the third party add-on XLR8 over the LabVIEW Excel toolkit.
07-28-2017 11:40 AM
Leave the template input of the first VI (New Report.vi) unwired, and it will create a new file.
Do use the template when you have specific formatting and named ranges that you want to insert into, but then you would make the save file name different so you don't overwrite it.
07-28-2017 01:18 PM - edited 07-28-2017 01:20 PM
Hello,
Is there a similar function for the Excel workbook creation like that in the "File IO" tab:
The situation that I would like to be in, is that if you can just type in a name in the file Location and the new file will be created. I tried the "Create File" from the File IO but I get an error, "Exception occured in Microsoft Office Excel: Excel cannot open the file 'NI_Excel_Tab.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file...". I have attached the updated code.
07-28-2017 02:13 PM
Not a single function, you would use 2 functions together:
But I don't see much advantage to creating a blank file rather than just saving it once it is populated.
07-28-2017 02:53 PM - edited 07-28-2017 02:56 PM
Here is one of my use case:
To generate a file name based on tests being carried out. Once the file is created (with an automatically generated name), data is taken and appended to the file until certain test conditions are met. That is, this loop can be accessed multiple times under the same filename condition. If at first, the file does not exist, it should be automatically created.
With the approach that you gave, can the above condition be satisfied?
Thanks,
hiNi.
07-28-2017 03:14 PM
Yes, I just keep the report in the shift register as you are doing. I would also keep track of the "next cell bottom left" if appending tables, to make sure you don't overwrite previous data. You could also use the "get last row" vi if you like.
If you don't need any fancy excel formatting, you could also use .csv files with the "write to spreadsheet / write delimited file" vis, which is what I usually do.
07-28-2017 04:42 PM
I am still having issues with generating a new excel file if one does not exist. Can you tell me how I can fix the attached code to generate a new excel workbook by just typing in a new name in the "File Location"? Not sure why I get the error code "7"?
Thanks,
hiNi.
07-28-2017 04:53 PM
If you wire the filename in as a template, it's going to use that file as a starting point. That's fine, if the file exists. If not, it should give you an error.
If the file does not exist, you should leave the terminal unwired, or use an empty path constant.
07-28-2017 05:00 PM
What function is that "anchor looking" icon? I have never used that before.