1. Dhanya K
  2. PowerBuilder
  3. Friday, 8 July 2022 04:58 AM UTC

Hello Team,

 

While exporting the report to CSV using saveasFormattedText, each data and heading of the resultset in CSV is coming within double quotes "". Also at the end, there is an extra comma. Could you please let me know how can i eliminate the extra comma in the CSV file.

 

Eg:

"Heading1","Heading2",

"Data1","Data2",

 

 

Thanks a lot in advance for your support

 

 

Dhanya K Accepted Answer Pending Moderation
  1. Friday, 8 July 2022 07:39 AM UTC
  2. PowerBuilder
  3. # 1

Thank you Andreas,

We had to use SaveasFormattedText as there was a requirement from the client to customize delimiter for CSV (Any other user defined special character instead of commas in CSV)

 

Comment
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Friday, 8 July 2022 07:00 AM UTC
  2. PowerBuilder
  3. # 2

SaveasFormattedText will add the separator character after the last column.

If this is the main issue you want to avoid you may test saveas like that:

<your datawindow>.saveas("<your filename>", CSV!, true, EncodingUTF8!)

This will have a similar output with:

<your datawindow>.saveasFormattedText("<your filename>", EncodingUTF8!, ",", "")

But saveas will show data values and not display values. So if your datawindow includes dropdowndatawindows or composite columns etc. and you want to save the displayed data you may need to modify your sql.

There is also another difference: saveasFormattedText will show header as it's displayed while saveas places column names as header columns.

Saveas allows you to provide an empty string for filename. In that case the user will be able to choose the filename and location where to save file.

Conclusion:

If you want to correct result of saveasFormattedText I think you will have to programmatically handle it. You may also open a support case for an enhancement in saveasFormattedText to make the separator character optional at the end of the line. But for enhancements there is no guarantee they will be implemented and in what time frame.

Andreas.

Comment
There are no comments made yet.
Dhanya K Accepted Answer Pending Moderation
  1. Friday, 8 July 2022 06:07 AM UTC
  2. PowerBuilder
  3. # 3

Thank you John for the quick response. "" - I agree with you. The last ending ',' is happening for all the reports. Even for the header, we have ',' at the end.

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 8 July 2022 05:49 AM UTC
  2. PowerBuilder
  3. # 4

Why not try looking at the Help for SaveAsFormattedText? The fourth argument is the quote character argument. If omitted a double-quote character is used to wrap values. As for the ending comma... is the last column of the last row Null? In other words, is this an EXTRA comma or the comma that gets placed between the next-to-last column and the last column?

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.