create new line in cell

Topics: Developer Forum, Project Management Forum
Dec 10, 2012 at 7:41 PM

Hello,

I have data that I would like to add to one cell in an excel worksheet. I would like there to be a blank line in between data entries in the same cell, but I am having trouble figuring out how to do this. I've been googling and testing different methods for a couple weeks now, but I have not found a solution that works for me. Can anyone help???

Coordinator
Dec 11, 2012 at 10:05 PM
Edited Dec 11, 2012 at 10:15 PM

"\n"; set cell to autowrap, and set row height to -1

$objPHPExcel->getActiveSheet()->setCellValue('A8',"Hello\nWorld"); 
$objPHPExcel->getActiveSheet()->getRowDimension(8)->setRowHeight(-1); 
$objPHPExcel->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true);

 

Dec 12, 2012 at 4:13 PM

Thanks for the quick response!

I was missing the setRowHeight line it turns out, but now its all working! Thank you!

Now, the other cells in the same row are vertically aligned at the bottom. Is there a way to set a cell to vertically align in the middle?

Coordinator
Dec 12, 2012 at 10:37 PM

$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);