1
votes

I have an Excel template that I need to fill out in php script. Table's headers are highlighted with different colours:

enter image description here

In php script I open template, add some data and save file:

 //Template from VitalSource
    $template = APPLICATION_PATH.'/../public/VitalSourceTemplate.xlsx';

    // Read the file
    $fileType = PHPExcel_IOFactory::identify($template);
    $objReader = PHPExcel_IOFactory::createReader($fileType);
    $objPHPExcel = $objReader->load($template);


    $objPHPExcel->setActiveSheetIndex(0);
    $row = 4;

    /*
       Add new rows to the Excel file
    */

// Write the file
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $fileType);
    $objWriter->save('testVS.xlsx');

Data is here, the only problem is that header colours are changing:

enter image description here

What can be the problem? How to leave original style of cells?

UPD

Here is a dropbox link to the template file - dropbox

UPD 2

When I convert template file from xlsx to xls everything works as expected.

Here is a link to the xlsx template - link

Here is a link to the xls template - link

Does PHPExcel process xlsx and xls colors differently? At other hand I use Numbers on Mac to open Excel files and converting them to xlsx and xls - probably there is some bug with Numbers. Appreciate any help and information.

1
Without access to the original files, it's impossible to answer for certain; but is the template using a custom colour set or theme? - Mark Baker
@MarkBaker Thank you for response. I added link to the template file. I'm not sure how can I check if colour set is custom or not? - Tamara
@MarkBaker I have checked - template uses colors from the standard Excel 56 pallet. But for some reason color #42 become color #3. - Tamara

1 Answers

0
votes

You can copy and paste but if ypou paste in other book you have to do the following:

Paste special --> Keep original theme