LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

creating a 2d array of random numbers send to excel with headers

Hi.  I am trying to build a VI that creates a 2d array (3 rows and 100 columns) and writes the transposed data to a spreadsheet file.  The only kicker is I have to add headers to the spreadsheet.  I have figured out how to create the array and send it to the spreadsheet without headers, but I cannot figure out how to get the headers in there. 

0 Kudos
Message 1 of 12
(6,779 Views)

Are you trying to send the file to Excel, or write a text file that "looks like" a Spreadsheet?  For the former, use the Report Generation Toolkit.  Its Table output functions include headers.  For the latter, you should probably do two Writes, a 1D for the Header and a 2D for your data.

 

Bob Schor

0 Kudos
Message 2 of 12
(6,765 Views)

Hi Bob.  Trying to send it to Excel itself.  I have been using the write to spreadsheet block and saving it as a csv file and opening it in excel.

0 Kudos
Message 3 of 12
(6,758 Views)

Hrader are strings and you can't mix strings and double in an array.

You can convert the double to string before writing to the spreadsheet file.

Not that the Write to Spreadsheet vi it will create a text file, not an Excel file. To create an Excel file the report generation toolkit is the easyest way, the other way is to use ActiveX methods and properties.

 

add header.png

 

Ben64

0 Kudos
Message 4 of 12
(6,755 Views)

Here's how you would do it using the report generation toolkit.

Example_VI_BD.png

aputman
Message 5 of 12
(6,738 Views)

Actually, you can mix Reals and Strings, just not in the same Write to Spreadsheet call.  This was the solution that I had in mind:

Spreadsheet with header.png

Bob Schor

0 Kudos
Message 6 of 12
(6,712 Views)

Oops, didn't notice the error in the RGT solution -- forgot to take transpose of the array.  Just for fun, I also used the Append Table to Report function.

Spreadsheet with header.png

BS

0 Kudos
Message 7 of 12
(6,700 Views)

I actually need three headers.  One above each column (since it becomes 100 rows and 3 columns after transposing it).  I tried doing a string array and connecting it to a write spreadsheet and then connecting that to the write spreadsheet like you showed in this example and the headers did work in the first spreadsheet (I tested that on its own first), but when the second write to spreadsheet was connected the it wiped out the first one so only the numbers in the 100x3 array were displaying.

0 Kudos
Message 8 of 12
(6,672 Views)
It sounds like you simply did not configure the second write to append. Do you have context help on and food you look at it?
0 Kudos
Message 9 of 12
(6,661 Views)

That was the problem, thanks!

0 Kudos
Message 10 of 12
(6,650 Views)