Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel, Copy sheet from one to another xls document with style

I need to create an xls file using lists of other files

I do something like this:

    $objReader = PHPExcel_IOFactory::createReader('Excel5');
    $file_tmpl = $objReader->load('doc10.xls');

$file_tmpl - the resulting file

    $file1 = $objReader->load('doc11.xls');

$file1 - file that is copied sheet

    $file1->setActiveSheetIndex(1);
    $sheet = $file1->getActiveSheet();          
    $file_tmpl->addSheet($sheet,1);

As a result, the sheet is copied, except for the style of the cell: the borders, fonts, text size, text color. How to move all together with style?

Thank you.

like image 854
Иван Васильев Avatar asked Oct 21 '25 00:10

Иван Васильев


1 Answers

There is a method built into PHPExcel for this: addExternalSheet() which copies the styling as well as the content from one workbook to another.

There is a script (43mergeWorkbooks.php) to demonstrate its use in the /Examples folder of PHPExcel

like image 116
Mark Baker Avatar answered Oct 22 '25 16:10

Mark Baker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!