Showing results for 
Search instead for 
Did you mean: 

Write to Excel but keep destination Format

simple question (I hope), I am using the report generation toolkit to write some information to cells in Excel.  Everything is working great except the formatting.  My workbook requires that the text in certain cells look a particular way.  But when LV writes to a cell it gets rid of the cell formatting.  I know there are VIs that will allow me to alter the formatting of the cell.  But is there a way to just tell LV to use the destination's format?

0 Kudos
Message 1 of 3

It would be easier to help with an actual example. The best one being the actual VI you are using attached to your comment so others can test it. I am using LabVIEW 2015 and I don't know what changes there might be with my version of the Generation Toolkit and yours.


If you are using something like the Append Table to, reading the Detailed help told me that, for example, if you want to keep the cell size as it is, you have to specify -1 as the value for column width.


Append Table to is the only one I have used to write text in Excel  so far and I don't remember it messing up with something like the font for example.

Andeagon - LabVIEW 2015
0 Kudos
Message 2 of 3

I actually think I have the "Solution" to your situation, and even have tested it using a "Revised Generate Excel Report" post I made to this Forum eight years ago.


Here's the deal -- when you generate data in an Excel Spreadsheet the "usual way", by typing numbers into a cell, Excel essentially formats the data "as you type it".  So if one cell has "8", and the cell below has "8.1", and the one below that has "8.12345", "what you typed" will be "what you get".


Once you have those data, however, you can choose to display them by changing the format of the cells.  For example, you might want every float (for appearances sake) to show one number after the decimal point, resulting in "8.0", "8.1", and *8.1".  Note that only changes the appearance of the data.


So how to you make this happen when you use the RGT to save data in Excel?  You need to create a blank "Template" that has cells requiring a specific format (like numbers with one digit of precision) to have the Cell Format set appropriately.  Now you use a not-widely-discussed "Feature" of the RGT ""Create Report" (formerly "New Report") function, namely the Template input. where you wire your prepared Excel "Template" Workbook that has the appropriate cells formatted as you require.  Again, note that the data shown in the cells might have more precision than is displayed, but that's just how Excel works.  Like "having your cake, and eating it, too".


Of course, the other way to do this is to "adjust your data to fit the "rules of the Workbook" -- if you know the data should only have two digits past the decimal point, you can add additional "rounding functions" to your LabVIEW code and "throw away" the "unwanted precision", but I, personally, don't like throwing away data ("hiding" it is preferable, in my humble opinion).


Bob Schor

0 Kudos
Message 3 of 3