colors missing

Topics: Developer Forum
Jun 23, 2009 at 4:00 PM

 Hi,

Im creating several xlsx files in a foreach that are send by email.

Each xlsx file contains 1 or more sheets.

Each sheets start with +- the same header.

The first xlsx created is as is should al those that follow are missing certain background colors.

A bit more details,

foreach($data as $key=>$item){
    $file = $list->get_price_list($lists, "pl", "false", "file");
   //code to send the recieved file
    unset($file);
}

The get_price_list function

        $xls = new PHPExcel();
       
        //Layout head1
        $this->layout['head1'] = new PHPExcel_Style();
        $this->layout['head1']->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
        $this->layout['head1']->getFill()->getStartColor()->setARGB('FF000080');
        $this->layout['head1']->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
        $this->layout['head1']->getFont()->setBold(true);
        //Layout head2
        $this->layout['head2'] = new PHPExcel_Style();
        $this->layout['head2']->getFont()->setBold(true);
        $this->layout['head2']->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
        $this->layout['head2']->getFill()->getStartColor()->setARGB('FFD15FEE');
        //Layout titel
        $this->layout['titel'] = new PHPExcel_Style();
        $this->layout['titel']->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
        $this->layout['titel']->getFill()->getStartColor()->setARGB('FFD15FEE');
        $this->layout['titel']->getFont()->setBold(true);
        $this->layout['titel']->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //layout changed
        $this->layout['changed'] = new PHPExcel_Style();
        $this->layout['changed']->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
        $this->layout['changed']->getFill()->getStartColor()->setARGB('FFFFFF00');
        $this->layout['changed']->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
        //layout newArt 00
        $this->layout['newArt00'] = new PHPExcel_Style();
        $this->layout['newArt00']->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
        $this->layout['newArt00']->getFill()->getStartColor()->setARGB('FF00FF00');
        $this->layout['newArt00']->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00);
        //layout newArt
        $this->layout['newArt'] = new PHPExcel_Style();
        $this->layout['newArt']->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
        $this->layout['newArt']->getFill()->getStartColor()->setARGB('FF00FF00');
        $this->layout['newArt']->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);

        $this->add_page(&$xls, &$this->data1, $sheet, "Sheet1");

        $this->add_page(&$xls, &$this->data2, $sheet, "Sheet2");

        $xls->setActiveSheetIndex(0);

        $filename = "example.xlsx";
       
        $objWriter = new PHPExcel_Writer_Excel2007($xls);

       $objWriter->save("/tmp/$file);

The add_page function

.

.

.

        // Wijzigingen
        $xls->getActiveSheet()->mergeCells('H3:'.$colums[$colum_merge].'3');
        $xls->getActiveSheet()->setCellValue('H3', $this->titel['history']." ".date("d/m/Y",$this->histo_time));
        $xls->getActiveSheet()->getStyle('H3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
        $xls->getActiveSheet()->getStyle('H3')->getFill()->getStartColor()->setARGB('FFFFFF00');

        //Nieuw artikel zin
        $xls->getActiveSheet()->mergeCells('H4:'.$colums[$colum_merge].'4');
        $xls->getActiveSheet()->setCellValue('H4', $this->titel['history2']);
        $xls->getActiveSheet()->getStyle('H4')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
        $xls->getActiveSheet()->getStyle('H4')->getFill()->getStartColor()->setARGB('FF00FF00');

 

the lines in Bold no longer work after the first loop.

Thanks in advance,

Carl

 

 

 

 

Coordinator
Jun 23, 2009 at 4:18 PM
Edited Jun 23, 2009 at 4:18 PM

Just as a check, are you unsetting $objWriter after each save?

Developer
Jun 23, 2009 at 4:26 PM

Well, not sure if Mark's suggestion works or not, but I remember we had a similar issue not long ago:
http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId=56914

It turned out to be a problem with the old style engine used by PHPExcel 1.6.7 and before. With the new style engine it was not happening.

Perhaps try to download latest source code and report back whether it works or not:
http://phpexcel.codeplex.com/SourceControl/ListDownloadableCommits.aspx

 

Jun 24, 2009 at 7:29 AM

  Hi,

To MarkBaker: I did not unset $objWriter, so i did but it didn't help.

To koyama: I downloaded the latest source code and the problem is solved.

Thanks both for your help.