Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to display newline(cl_abap_char_utilities=>newline) using XML?

Former Member
0 Kudos

I have concern regarding the use of cl_abap_char_utilities=>newline converted to XML.

the newline (ALT+Enter) in a cell is not displayed in the excel attachment. instead it is viewed as:

"text1, text2".

I was hoping the resulting output in a particular cell would be:

text1

text2

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

Based on your latest comments, you are using XMLSS, not OLE (and you are generating XMLSS via the ABAP iXML classes). In XML, all "space-like" characters (space, newline, tab...) are interpreted by default as one space. If you want to pass the actual values, you must use their equivalent "character entity references":

16 REPLIES 16

raymond_giuseppi
Active Contributor

Did you set the cell's IsTextWrapped style to true

worksheet.Cell.Style.WrapText=true;

0 Kudos

Hi Raymond Giuseppi,

Thanks for your reply by the way.

0 Kudos

Hi Raymond Giuseppi,

I'm not sure where to insert that kind of code in abap. Are you referring to wraptext? could you provide some psuedocode? I tried something like this (below) in my code. but it is still not working.

r_format = l_document->create_simple_element( name = 'Alignment' parent = r_style ).
r_format->set_attribute_ns( name = 'Vertical' prefix = 'ss' value = 'Center' ).
r_format->set_attribute_ns( name = 'WrapText' prefix = 'ss' value = '1' ).

0 Kudos

This code is not OLE, it's XMLSS ! (aka XML 2003 for Excel)

0 Kudos

I was more thinking to something like (some test perform you should)

SET PROPERTY OF ole_cells/rows/columns 'WrapText' = 1.

0 Kudos

Hi Raymond Giuseppi & Sandra Rossi. Apologies, I got confused between the two. But anyway, thanks for your big help.

0 Kudos

Could you please communicate the solution if you have found it?

0 Kudos

Well when I tried to apply the character entity reference for newline. It is still not interpreted by the xml. I think I found another thread (https://archive.sap.com/discussions/thread/3380973) that has the similar problem. They just did some workaround regarding this. Another option I'm looking at is with the use abap2xlsx. But I'm still learning this approach. I'll try to provide another feedback about this, if it worked.

So without reference to OLE2, but building an Excel XML file, you could try to

Create a style like

in Workbook, Styles
<Style ss:ID="ZMultiLine"> 
  <Alignment ss:Vertical="Bottom" ss:WrapText="1"/>
</Style>

Use it in the Cell

<Cell ss:StyleID="ZMultiLine">
  <Data ss:Type="String">First Line&XXX;Second Line&XXX;Last Line</Data>
</Cell>

Where XXX is for #10 (else your browser will replace it with line feed)

0 Kudos

I'll get back to you as soon as I've tried and tested this. thank you Raymond Giuseppi.

HI Raymond Giuseppi, I have tried this. But I'm still not getting the expected output. The character entity reference for newline ( & #10;) is still not interpreted properly. But it's ok, I think I found the approach i'm looking for. Thank you.

Sandra_Rossi
Active Contributor

Based on your latest comments, you are using XMLSS, not OLE (and you are generating XMLSS via the ABAP iXML classes). In XML, all "space-like" characters (space, newline, tab...) are interpreted by default as one space. If you want to pass the actual values, you must use their equivalent "character entity references":

To do "Line 1& #10;Line 2":

  data = lo_doc->create_simple_element( name = 'Data' parent = cell ).

  text = lo_doc->create_text( ).
  text->set_value( value = 'Line 1' ).
  data->append_child( text ).

  ref = lo_doc->create_entity_ref( name = '#10' ).
  data->append_child( ref ).

  text = lo_doc->create_text( ).
  text->set_value( value = 'Line 2' ).
  data->append_child( text ).

great! it worked. Thanks a lot Sandra Rossi.

0 Kudos

If it is multiple lines like Ex 10 lines how the functionality will work code please

OwenLiu
Product and Topic Expert
Product and Topic Expert

Thanks for coming to SAP Community for answers. Please post your question as a new question here:
https://answers.sap.com/questions/ask.htmlSince you're new in asking questions here, check out our tutorial about asking and answering questions (if you haven't already), as it provides tips for preparing questions more effectively, that draw responses from our members. Please note, that your post here won't be answered.

Best Regards,
Owen Liu