Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make New lines in a cell using phpexcel

Tags:

php

phpexcel

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 <br /> but itsn't work. this my code:

$objPHPExcel->getActiveSheet()->setCellValue('H5', 'Hello\nWorld'); // i need this show in two line $objPHPExcel->getActiveSheet()->getStyle('H5')->getAlignment()->setWrapText(true); 

fyi: my format excel is xls not xlsx. many thanks :)

like image 314
bungdito Avatar asked May 11 '11 06:05

bungdito


People also ask

How do I add a new line in a cell in Excel using PHP?

Write a newline character "\n" in a cell (ALT+"Enter") In Microsoft Office Excel you get a line break in a cell by hitting ALT+"Enter". When you do that, it automatically turns on "wrap text" for the cell. Read more about formatting cells using getStyle() elsewhere.


1 Answers

$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.

like image 57
wimvds Avatar answered Oct 08 '22 05:10

wimvds