06-26-2015 04:52 AM
Hello,
I have made an SubVI which inserts a value into a specific value into a column and row on a excel spreadsheet.
This did the job fine, up until I ran my main VI, where some of my other subVIs complained about excel being open. So I added in the workbook close and application quit invoke nodes.
This brings me on to the problem. With these nodes added, it does not save the added data. I'm stumped for ideas of why it will not save. It also it prompts me to save each time it runs the VI, which is not ideal when the code is intended to run many times.
It might be worth noting that the file is saved as a CSV
Save me please?
Cheers,
Oliver
Solved! Go to Solution.
06-26-2015 10:20 AM
06-26-2015 05:07 PM
I can't help you with ActiveX -- I used to use it, but since NI revamped the Report Generation Toolkit (4 years ago? longer?), I find it so much easier to use the RGT, which is now included in the base version of LabVIEW 2014 (so you should have access to it).
I think this does what you want.
Following along the Error Line, the first Function opens Excel, handing it the Workbook you specify. Note you can choose to have Excel open "minimized" (so you don't see it). The next function makes Tues_06 the Active Worksheet. The third function is Excel Easy Table, which puts a 2D Table in the Worksheet at a specified location -- more on this in the next paragraph. Then comes Save Report, using the same filename (so it does an overwrite), followed by Dispose Report, which closes Excel. This should take about a tenth of a second (or maybe less).
The stuff above gets the String and Location ready. Excel Easy Table needs a "Table", and you have a "Cell". Simply pass it through Build Array twice to turn it into a 2D "Table" consisting of a single "Cell". The next line creates the "Excel Location", given as a zero-offset X, Y cluster. I assume your "Column" input is the "A" of the cell address "A1", while your Row is the Excel Row number (i.e. 1 is the first row). I turn this into a string in the form "A1", pass it to Excel Get Excel Location to get the X and Y parameters, bundle these into an X, Y cluster, and had this location to Excel Easy Table. Note that if you are using a Numeric (as you are) for the Row, you should probably force it to start at 1, as there is no cell A0.
An added benefit of this method (besides the fact that it works!) is that it does not require a dual-screen monitor setup to view.
Bob Schor
06-27-2015 12:01 AM
06-29-2015 03:26 AM
You've made my life much easier by making me aware of the report generation toolkit. I agree that it is much easier doing it this way
Many Thanks,
Oliver
06-29-2015 12:43 PM
Don't thank me, thank NI. When I started using LabVIEW to read/write Excel, I was using LabVIEW 7.0, which had a RGT, but it was, shall we say, "Version 1". I ended up learning more about ActiveX and Excel "internals" than I wanted to know. When the Object-based RGT came out a few years later, it made my life a whole lot easier ...
BS