LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write 2D data array to spreadsheet with good alignment

Solved!
Go to solution

Using "write to spreadsheet file" function to write 2D array,   I always have the problem that headers cannot align well wiith the data. See attached snapshot please (There are 7 column headers.)

 

data alignment with headers.PNG

 

 

WT

LV2013sp1

0 Kudos
Message 1 of 8
(5,019 Views)
Solution
Accepted by weitong

The default field delimiter is a tab. The data values in the second and third columns appear to have more characters than the default spacing of a tab. This results in the tabs between those columns occuring farther to the right than in the header. I suspect that if you read the file as text and display it with '\' Codes display mode on a string indicator, you will find the same number of tabs (delimiters) in the header row as in the data rows.  The data has 12 or 13 characters as formatted (or fewer where trailing zeros are suppressed).

 

Format the data as fixed field widths. You cannot do this with Write to Spreadsheet File.vi. You will need to use string functions to perform the conversions and formatting and then use Write to Text File.vi.

 

Or change the tab spacing in the program you are using to display the results.  If the tabs were about 15-18 spaces apart, you wuold not see the problem.

 

Lynn

Message 2 of 8
(5,007 Views)
Solution
Accepted by weitong

Plain text display cannot handle tabs very well.

 

You can take the spreadsheet file and open it in e.g. excel and it will all look great. Spreadsheet files have no formatting information, just row and column delimiters.

 

If you want to create nicely formatted report files in LabVIEW, use the report generation tools and pick an output file format that is suitable for what you want to display (e.g. html).

 

If you want to display your data in a plain text indicator, you would need to do two things:

  • use a fixed-width font (e.g. courier)
  • Format all fields with a fixed widh of padding characters.

For a tabular front panel indicator, you should use a table. You can write the header strings into the table header.

Message 3 of 8
(4,992 Views)

Thanks to both of you.

 

WT

LV2013sp1

0 Kudos
Message 4 of 8
(4,964 Views)

Hello Lynn,

 

I have met the same problem, do you know how to change the tab spacing?

 

Best Regard

0 Kudos
Message 5 of 8
(4,370 Views)

Hi LLX,

 

tab spacing is set in the text editor you use to view the text file!

(Each text editor may use it's own definition for the equation 1 tab = x spaces, but I usually use tab = 8 spaces…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 8
(4,366 Views)

@TUDarmstadtLLX wrote:

Hello Lynn,

 

I have met the same problem, do you know how to change the tab spacing?

 

Best Regard

Don't start futzing with your text editor. 

 

Use a spreadsheet program to view the files, like MS Office Excel ($$$) or Open Office Calc (free).

 

Spreadsheet programs will import a Tab or Comma deliminated text file and put all the data in nice neat columns for you.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 7 of 8
(4,349 Views)

Hi RTSLVU,

 

it's a real problem when people start to create double posts like LLX did

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 8
(4,344 Views)