01-10-2025 08:57 AM
Thanks for clarifying. You would be surprised how many people call any and all form of spreadsheet data an Excel file. We waste a lot of time just to find out they actually mean a simple CSV file. That's why we ask specific questions. Also terms like "live" mean real-time to us
So, sounds like you have Excel (.xls or .xlsx) file(s) that have a table of XY data and you want to create a basic Excel XY graph of that data in Excel either right next to your table or on another tab?
As I said in my other post, you can create a graph with the report generator toolkit, but there are no functions in the toolkit to open an existing .xlsx file, add the graph, and then save it with the graph.
The toolkit always starts with opening a new Excel file and then helps you add things (tables, text, graphs, pics) to it. That means you will have to:
1) Read the file first and extract your XY data
2) Store it in an array
3) Create a new Excel report
4) Put the graph and whatever else you want into the new file.
This may seem clunky, and there is probably a way to do the whole process using the ActiveX functions through LabVIEW Invoke and Property nodes, but that is above my Excel/ActiveX skill level.
Make sure you have the Report Gen Toolkit installed and take a look at the example I referenced before. Try using the Read Spreadsheet VI in the FileIO palette to read your XY data into a 2D array.
This is pretty easy, but not trivial. If you're new to LabVIEW don't hesitate to ask for help. We prefer to help others learn LabVIEW rather than just doing the work for them, but will be happy to provide some example code if you get stuck...
01-10-2025 12:29 PM
This can be done with ActiveX as was already specified. It's a bit tricky but if you have the report generation toolkit you can skip the first part to open Excel and get the reference to the worksheet. The attached vi shows you how it can be done, I leave you the part to save the file and close Excel after adding the chart.
Ben
01-10-2025 12:39 PM - edited 01-10-2025 12:41 PM
Very nice! I thought it would be at least twice as much code but this is not bad at all. I code in C#/.NET too, so it wouldn't hurt me to dive in and learn some of this.
Kudos for you!
01-10-2025 08:48 PM
There is an apparently little-known input to the "Create Report" function in the RGT.
@Nyquist noted "you can create a graph with the report generator toolkit, but there are no functions in the toolkit to open an existing .xlsx file, add the graph, and then save it with the graph."
If you look at the inputs to Create Report, the fourth left input, "template (empty)" is described as
template (Report Generation Toolkit) specifies a path to a Word document or Excel worksheet that acts as a report template. Enter the path to an existing Word document or Excel worksheet to open and edit an existing report for a template. The VI ignores this input for HTML reports.
A decade ago, I posted a "Revised Generate Excel Report Example" on this Forum (you can find it by searching this Forum -- it should pop up before you finish typing "Excel"). It shows how to make the Data Plot in Excel (try it!). I wasn't using Templates back then, but I do use them now.
There are functions in the RGT that can let you handle multiple WorkSheets. If you have an Excel Workbook whose first WorkSheet has data, you can help yourself by designing the input Excel Workbook/Worksheet such that the data are in a "known place". You do not necessarily need to know how many rows have data (there is a function that helps you find the end of the data).
Bob Schor
P.S. -- generally, I'm generally able to do what I need using the tools LabVIEW provides, including the RGT for Excel, as LabVIEW (generally) tracks changes in Microsoft software. However, I recently hit a couple of snags. One is Windows 11, the other is some changes in how NI organizes the functions and libraries that support the RGT. Bottom line -- I'm having trouble using the RGT in an environment consisting of LabVIEW 2024 Q3 (64-bit) running on Windows 11. I've stumbled upon what seems to be a known (to NI) bug in the RGT "Addon" routines. [I'm trying to fix this, have made a little progress, but it's not yet working ...]. I should note that Windows 10 and LabVIEW 2021 works fine.
01-13-2025 08:53 AM
I have used the template option before, but I got the impression that the OP probably has a bunch of files that have XY data in a table that he wants to add a chart of that data to. Editing the file in-place makes it easy to automate that task for batch processing.
P.S.: I totally agree on the RGT. I've been screwed by changes in Excel before which broke all my Production code, so I now always save data to a simple CSV file and then process that afterward with a separate program dedicated to report generation. I also choose HTML rather than Excel whenever I can to avoid being bitten by M$ making changes to Excel or ActiveX as much as possible.