Skip to Content

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

Sep 27, 2017 at 05:05 AM


avatar image

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:



10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Sandra Rossi Sep 27, 2017 at 11:47 AM

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":

jtdz2.png (8.0 kB)
q3i3m.png (11.9 kB)
Show 2 Share
10 |10000 characters needed characters left characters exceeded

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 ).<br>

great! it worked. Thanks a lot Sandra Rossi.

Raymond Giuseppi
Sep 27, 2017 at 06:14 AM

Did you set the cell's IsTextWrapped style to true

Show 10 Share
10 |10000 characters needed characters left characters exceeded

Hi Raymond Giuseppi,

Thanks for your reply by the way.


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

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

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' ).


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


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


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


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 ( 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"/>

Use it in the Cell

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

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


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.


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