Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel set same properties, content etc on multiple sheets at once

Is there anyway to set the same properties (colors, row height, alignments) and content (hear names) for all sheets at once with PHPExcel? How?

Thank you.

like image 711
Francisc Avatar asked Dec 22 '10 13:12

Francisc


1 Answers

If you're creating all those sheets yourself. Set the properties for the first sheet that you create, then clone that sheet and attach the new clone back to the same workbook. This should copy all existing cell data and style information from the original worksheet.

//  Create a new PHPExcel object with a single sheet
$objPHPExcel = new PHPExcel();

//  Set any styles here against the currently active sheet in $objPHPExcel

//  Get the current sheet with all its newly-set style properties
$objWorkSheetBase = $objPHPExcel->getSheet();

//  Create a clone of the current sheet, with all its style properties
$objWorkSheet1 = clone $objWorkSheetBase;
//  Set the newly-cloned sheet title
$objWorkSheet1->setTitle('Cloned Sheet');
//  Attach the newly-cloned sheet to the $objPHPExcel workbook
$objPHPExcel->addSheet($objWorkSheet1);

It's useful to note that you can set styles for a cell even before you write data to that cell

like image 167
Mark Baker Avatar answered Nov 05 '22 20:11

Mark Baker