Skip to main content
Question

I am writing some tabular data to a text file using the CSV writer. How do I get my attribute names or column headings to align with my attribute values in a right justified manner or padding left?


benadei
Participant
Forum|alt.badge.img+3

 I have used @PadLeft(@Format(%.3f,@Value(FLOW)), 8) in an earlier attribute manager in the workspace to format the values to three decimal places and pad left. My output data and workspace are as shown below:2023-11-07_11-58-272023-11-07_11-59-02

2 replies

hkingsbury
Celebrity
Forum|alt.badge.img+54
  • Celebrity
  • November 7, 2023

A CSV file uses a common delimiter to separate columns (usually a comma, can be any other char, in your case looks like a tab) and a new line to signify rows. Its purpose is to be machine readable, not necessarily human readable.

If you try to make it human readable by adding extra space etc, then you begin to change values and the schema of the file, for example, I have the below data, its comma separated and as you can see it doesn't line up

f1,f2,f3
value1,value2,value3
name,something a bit longer,date

But treating it as a csv, it correctly splits the field names into 'f1', 'f2', 'f3' and the rows into 'value1', 'value2' etc

 

However, if I now go and adjust it to make it look a bit nice to a human, I start to really change the data

f1,     f2,                     f3
value1, value2,                 value3
name,   something a bit longer, date

the first field name is fine, 'f1', however i've introduced a bunch of spaces into the field name for the second field, so that now reads as '    f2' (four spaces at the start). That is not the same as 'f2'. Similar goes for the third field (now has 21 spaces in front)

 

This also applies to the data rows, the second field in row 1 now reads as ' value2' (begins with one space). The second field of row 2 now reads as '  something a bit longer' (begins with two spaces).

 

If the data needs to be as CSV, then the best option is to not introduce any padding in an effort to 'format' the output, but to instead open the CSV in something like Excel where it conforms to a tabular structure


benadei
Participant
Forum|alt.badge.img+3
  • Author
  • Participant
  • November 7, 2023

Yes, I used a tab in writing the CSV output. Thanks for your response!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings