01-23-2023 05:18 PM
Good afternoon,
I am sort of new to LabVIEW and I am working on inserting data to an excel file. I am able to do so using the "Excel Easy Table.vi" and I am also able to format the excel sheet to my liking. I run into the issue where the cell data is larger than the column width, and I have tried looking for ways or VIs that would be able to change the width of the columns.
Is it possible to select the entire sheet and auto-size each column based on the size of the largest cell width in that column, like if I were to manually do it in the excel file myself and if so how would I manage to do this?
Or are there different ways to accomplish the issue I have encountered?
Solved! Go to Solution.
01-23-2023 07:36 PM
You absolutely can do this. The "trick" is that you need a little VBA code to "AutoFit" the columns you want (or I think you can do All Columns, and maybe All Cells, though this might be problematic). I'm not a VBA expert, but if you search the Web for something like "Excel fit column vba", you can probably find some code you can use.
Now look in LabVIEW, open Examples, and search for VBA. It shows you an example of a routine that includes the VBA code to manipulate a Word document, then shows the steps you use to run that macro against a Word file that you specify. Substitute Excel functions and calls, and put the code for the Excel VBA macro you want to run (from your Web search in paragraph 1) and run this code to adjust your Excel document.
Thanks for asking! I've used the RGT for many years, and largely "hand-tuned" the column widths for the data I expected. I never thought about automating it using AutoFit until you asked the Right Question.
Bob Schor
01-24-2023 02:14 AM
I wish it would be that easy the other way round. Just running some method or VI to auto-size a LabVIEW table to the cell content. Sure, there are ways, but not simple and with bad performance.
01-24-2023 10:47 AM
@MaSta wrote:
I wish it would be that easy the other way round. Just running some method or VI to auto-size a LabVIEW table to the cell content. Sure, there are ways, but not simple and with bad performance.
I agree (from my own experience sizing a String Indicator to fit the String I wanted to write into it) that it is not simple, but am not sure what you consider "bad performance". For a Table, you'd want to find the "widest entry" first, which depends on lots of factors, including the Font (two words in different fonts might have dif
'm surprised to hear that! I once wanted a String Indicator for a Top Level VI that would hold a 1-line "Message" (such as "Press the Go Button to Start" or "Please wait ...") that would size itsellarf to the String being displayed. I also wanted this "Message" to be able to have the font size and color, and Bold and Italic attributes, set for the Message. I couldn't find anything out there that was appealing, so wrote my own. It was a little "processing-intensive", but (as I recall) took a small fraction of a second (trivial, for a "static Message"). Didn't try doing this with a Table, but suspect it wouldn't be that difficult (nor time-intensive, once the Table contents have been written).
Bob Schor