how to make New lines in a cell using phpexcel

后端 未结 5 521
故里飘歌
故里飘歌 2020-12-08 09:32

i have problem with php excel,

i want to make new line in one cell but i can\'t, i have tried using \\n or
but itsn\'t work. this my code:

<         


        
相关标签:
5条回答
  • 2020-12-08 09:42

    Improved answer based on Ravin and others

    $objPHPExcel
      ->getActiveSheet()
      ->setCellValue('H5', "Hello".PHP_EOL." World");
    
    $objPHPExcel
      ->getActiveSheet()
      ->getStyle('H5')
      ->getAlignment()
      ->setWrapText(true);
    
    0 讨论(0)
  • 2020-12-08 09:48
    $objPHPExcel->getActiveSheet()->setCellValue('H5', "Hello\nWorld");
    $objPHPExcel->getActiveSheet()->getStyle('H5')->getAlignment()->setWrapText(true);
    

    Works for me...

    You should always use double quotes when you add escape sequences in a PHP string.

    0 讨论(0)
  • 2020-12-08 09:51

    We can set for the default style, so don't need to specify for each cell range:
    $objPHPExcel->getDefaultStyle()->getAlignment()->setWrapText(true);

    0 讨论(0)
  • 2020-12-08 09:54

    To achieve next line but same cell forxcel export, this is the simplest solution.

    <tr>
        <td style="wrap-text: true">
            Test
            <br />
            Test2
        </td>
    </tr>
    
    0 讨论(0)
  • 2020-12-08 09:58

    you should use 'r' to break into new line into excel with php

    and use double quotes when you add escape sequences in a PHP string.

      $objPHPExcel->getActiveSheet()->setCellValue('H5', "Hello\r World");
      $objPHPExcel->getActiveSheet()->getStyle('H5')->getAlignment()->setWrapText(true);
    
    0 讨论(0)
提交回复
热议问题