Showing results for 
Search instead for 
Did you mean: 

Getting excel data into a formatted report.



I have a program that writes data collected to an Excel spread sheet as a single string with formatting characters,( ‘\’ codes). The unformatted data looks like this. 


Raw Data.PNG




 Now the challenge is to format the Excel sheet into a finished report. I would like to do this using a template. I have not had much luck using the report generation tool kit.


I would like it to look like this. 

Formatted Data.PNG


I would like to open the template, append the line of text containing ‘\’ code,  starting at A,1.



0 Kudos
Message 1 of 8

Hi, you should do the following steps, one after another inside a sequence structure:


1. Use the "New" inside the excel toolkit, to open the template. In the report type input, just create a constant with "excel", and in the template input, just give it the path to the excel template file location. Connect the "report out" to the following instructions.


2. Use the "Excel easy" inside the excel toolkit, to write to the desired position inside the excel file. The "Report in" input should be connected to the report out output of the new report from step 1. The "Text" input is a string with the data. The "start" and "end" intpus, should be the same in order to write in a single cell, this is the position row and column (it is a cluster).


3. Once you finish writing, you should save with the "Save report to" inside the toolkit. If you provide the same path from step 1, the file will be overwritten, if not it will create a new excel file, and you can keep your template with no modification.


4. Finally close the report, by using the "Dispose"


In conclusion, you should use a sequence structure with 3 frames: one for step 1, one for step 2 and one for steps 3 and 4.


Take a look at the attached VI, this is an example in spanish. Is just a little more complex than explained above, but it has a bit more functionalities you could study. If you are not interested in all the VI, just take a look at the sequence.



0 Kudos
Message 2 of 8

There are a number of examples of how to write formatted Excel Reports that ship with LabVIEW.  A Revised Example that I know well can be found here.


I agree with the reply by RubenVasquez on how to use a Template -- any existing Excel file that you specify as a Template file will be opened when you do a New Report (if you don't specify a Template, a blank Excel Workbook will be opened).  At the time you save the Report (using Save Report to File), you specify the name of the Output File, which can be the same as the Template (overwriting it) or different (allowing you to use the Template for another Report).


I do not agree that you should use a three-frame Sequence structure to do this -- the proper use of the Error Line is a much better way of specifying the "sequence" of your code (as shown in the referenced Examples).


Something that you might consider is doing what is illustrated in the "Revised Example" cited in the first paragraph -- rather than try to parse a Template or write specific lines of text or data in specific cells, it may be easier to write your Report entirely with the RGT, including the row and column headers, spacing the entries "as you go".  This is particularly useful when you might not know, in advance, how many rows and/or columns an entry will occupy, and thus where the next entry should be placed.


Bob Schor

0 Kudos
Message 3 of 8

@jrhappe wrote:

 I have not had much luck using the report generation tool kit.


Please post your code that generates the report, so that we might find the unlucky part of your code Smiley Happy

CLA // LabVIEW 2016 // BALUG // Unofficial Forum Rules and Guidelines
0 Kudos
Message 4 of 8

I highly recommend the XLR8 addon toolkit  for this type of formatting.


Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
Message 5 of 8

Thank you for all the help so far. This is the test program I have been playing with. The problem appears to be that the Excel Easy Text .vi will not handle the '\' code.


Here the text code if it does not come through the snippet, (first time posting one).


@Gregory wrote:

@jrhappe wrote:

 I have not had much luck using the report generation tool kit.


Please post your code that generates the report, so that we might find the unlucky part of your code Smiley Happy

Template Test.png



0 Kudos
Message 6 of 8

The template is attached below. 

0 Kudos
Message 7 of 8

You may be going about this in the "wrong way".  I copied your String into a Text File, then opened it with LabVIEW and read it -- it created a long string with embedded \s, \t, and \r characters.  I used three Search and Replace String functions to replace them respectively with a Space Character, a Tab Character, and an End-of-Line Constant.  I then noticed that I essentially had a Tab-Delimited String, so I then passed it through the SpreadSheet String to Array function and got the following:

SpreadSheet Array.png

Looks pretty close, right?  In fact, if you took this array and wrote it using Write Delimited Spreadsheet to a file with the extension ".csv", you could open it with Excel (which "knows how" to open Comma-Delimited-Values files, and, indeed, hijacks the extension to give it an Excel-like icon).  You could also (probably) use the RGT, instead, to write out this entire array as a true .xlsx file, ignoring the need for a Template (since you have almost everything in this file).


There is, however, one "gotcha" -- see the cell in the lower left corner?  It starts with \n, meaning that a few of your strings use \r for EOL, some use \r\n (and leave an "orphan" \n over), and some may use \n by itself.  This makes the parsing a little trickier, but that I leave as an Exercise for the Original Poster ...


Bob Schor


0 Kudos
Message 8 of 8