Menu

How to insert a line break?

Help
Anonymous
2010-12-22
2013-04-24
  • Anonymous

    Anonymous - 2010-12-22

    Hi!
    First of all, thank you for the excel writer. It's great.
    Now I am trying to inset a string with a line break:

    $sheet->writeString(1,1,"Line1 \r\n Line 2");
    

    But the string appears as one line.
    So how to insert a line break?

     
  • primordius

    primordius - 2010-12-22

    I suppose line breaks are sometimes needed.
    Here is how to convert windows carriage returns. ( \r\n )
    Unix style will be slightly different. ( \n )

    $value = "Line1 \r\n Line2";
    str_replace( "\r\n" ,  "
" , $value );
    $sheet->writeString(1 , 1 , $value );
    
     
  • Anonymous

    Anonymous - 2011-01-27

    I just tested this small piece of code. What I get in the resulting XML is that the & is converted into an html entity. So you get something like

    ..... 
.....
    

    but not a line break!

     
  • primordius

    primordius - 2011-02-16

    Hmm… I think I know why this is happening.
    Oversight on my part, for sure.

    I will fix the issue and upload a new version.

     
  • primordius

    primordius - 2011-02-17

    I updated the code and released a small bug fix version.
    CR and New Lines ( "\r\n" and "\n" ) are converted to XML version line breaks.
    No need to add "
" to the code as I suggested before.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.