Hi everybody,
I need to read a DB2 file and create a CSV file from it.
This is not a problem so far - but I have to read several lines of text in a loop and then I have to output them in a single CSV cell. However, the text should not be written as a long text, but after each line a line break should be issued, so that Excel can recognize it when the CSV file is displayed.
How do you do this? I either always get a line feed that doesn't stay in the cell, but breaks the whole CSV line and ruins everything - or none at all?
I tried ( a little bit simplified here) - but this onley leads to
#LineFeed := (10).AsUnicodeString /* Hex 0A */
Select Fields(#TEXT) From_File(TEXTBSL0) With_Key(#SMHMANDAN "1") Io_Status(#IO$STS) Io_Error(*NEXT) Val_Error(*NEXT)
#CSV_CELL_TEXT += #LineFeed.AsNativeString + #TEXT'
Endselect
But that only confuses Excel.
Do you know how to do this with RDMLX?
Many thanks in advance,
Joerg
Creating CSV and line feed in a cell
-
Joerg Hamacher
- Posts: 120
- Joined: Thu Feb 11, 2016 12:01 am
Re: Creating CSV and line feed in a cell
Hi Joerg
From this post
https://stackoverflow.com/questions/566 ... -csv-files
I like the idea of doing that in excel, then save it as csv to see how it implements it.
But looks like you will need to manually create the csv strings as I don't expect the transform file builtin to be able to generate it that way.
You can also consider as an alternative to write to excel file directly using LANSA integrator service.
From this post
https://stackoverflow.com/questions/566 ... -csv-files
I like the idea of doing that in excel, then save it as csv to see how it implements it.
But looks like you will need to manually create the csv strings as I don't expect the transform file builtin to be able to generate it that way.
You can also consider as an alternative to write to excel file directly using LANSA integrator service.
-
Joerg Hamacher
- Posts: 120
- Joined: Thu Feb 11, 2016 12:01 am
Re: Creating CSV and line feed in a cell
Hi Dino,
thank you.
I found out from one of the comments in your link that it obviously only works if a semicolon is used as the column separator. The customer has specified that we should use | as the separator.
In addition, the entire text should be placed in quotation marks so that LineFeed is processed cleanly.
I now create every CSV line as a string, using semicolon as separator - and the linefeed in the text cell is now programmed like this:
Define_Com Class(#prim_dc.UnicodeString) Name(#DoubleQuote)
Define_Com Class(#prim_dc.UnicodeString) Name(#LineFeed)
#LineFeed := (10).AsUnicodeString
#DoubleQuote := (34).AsUnicodeString
#CSV_CELL_TEXT := #DoubleQuote.AsNativeString + #TEXT1 + #LineFeed.AsNativeString + #TEXT2 + + #LineFeed.AsNativeString + #TEXT3 + #DoubleQuote.AsNativeString
and it looks like this is fine for CSV / Excel.
Hope it is for the customer, too...
Best regards,
Joerg
thank you.
I found out from one of the comments in your link that it obviously only works if a semicolon is used as the column separator. The customer has specified that we should use | as the separator.
In addition, the entire text should be placed in quotation marks so that LineFeed is processed cleanly.
I now create every CSV line as a string, using semicolon as separator - and the linefeed in the text cell is now programmed like this:
Define_Com Class(#prim_dc.UnicodeString) Name(#DoubleQuote)
Define_Com Class(#prim_dc.UnicodeString) Name(#LineFeed)
#LineFeed := (10).AsUnicodeString
#DoubleQuote := (34).AsUnicodeString
#CSV_CELL_TEXT := #DoubleQuote.AsNativeString + #TEXT1 + #LineFeed.AsNativeString + #TEXT2 + + #LineFeed.AsNativeString + #TEXT3 + #DoubleQuote.AsNativeString
and it looks like this is fine for CSV / Excel.
Hope it is for the customer, too...
Best regards,
Joerg