Changes in formatting between 1.6.6 and 1.6.7

Topics: User Forum
Apr 28, 2009 at 4:05 PM
Hi,
I just upgraded to 1.6.7 and then some of my formatting was lost. When I revert to 1.6.6 i get the formatting back.

In my script I have created two excel sheets, which both have formatting correct. But this last script, which use does not receive the formatting correct.
Any ideas on where to search. Can there be a memory leak, or something else which mean that i should re-initialize the script.

        $objPHPExcel = new PHPExcel();


        // metadata
        $objPHPExcel->getProperties()->setCreator("figaf");
        $objPHPExcel->getProperties()->setLastModifiedBy("figaf");
        $objPHPExcel->getProperties()->setTitle("PI Mapping diff");
        $objPHPExcel->getProperties()->setKeywords("pi mapping diff");



        // Set active sheet index to the first sheet, so Excel opens this as the first sheet
        $objPHPExcel->setActiveSheetIndex(0);

        $objPHPExcel->getActiveSheet()->setTitle('Mapping difference');

        //insert information about the mappping
        $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Mapping name');
        $objPHPExcel->getActiveSheet()->setCellValue('C1', $oldMapInfo->getValue('NAME'));
        $objPHPExcel->getActiveSheet()->setCellValue('D1', $newMapInfo->getValue('NAME'));
 
        $objPHPExcel->getActiveSheet()->mergeCells('A1:B1');

 $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);

        //format the top document this seems to work.
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(60);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(70);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(70);

        $objPHPExcel->getActiveSheet()->setCellValue('A'.(self::STARTLINE-1), 'Changed');
        $objPHPExcel->getActiveSheet()->setCellValue('B'.(self::STARTLINE-1), 'Target');
        $objPHPExcel->getActiveSheet()->setCellValue('C'.(self::STARTLINE-1), 'Old mapping');
        $objPHPExcel->getActiveSheet()->setCellValue('D'.(self::STARTLINE-1), 'New Mapping');


        $objPHPExcel->getActiveSheet()->getStyle('A'.(self::STARTLINE-1))->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle('A'.(self::STARTLINE-1))->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);

        // write content
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->save($this->directory.'/diff.xlsx');
Developer
Apr 28, 2009 at 9:05 PM
I couldn't quite reconstruct your script because there are some unknown parameters. Not sure what changes in 1.6.7 compared to 1.6.6 could be causing this.

I do see one thing in the code. When you apply styling to a merged range of cells, all of the cells in the range need the styling applied.

Instead of this:

$objPHPExcel->getActiveSheet()->mergeCells('A1:B1');
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);

do like this:

$objPHPExcel->getActiveSheet()->mergeCells('A1:B1');
$styleArray = array('font' => array('bold' => true));
$objPHPExcel->getActiveSheet()->duplicateStyleArray($styleArray, 'A1:B1');

If one forgets to apply the style to the entire range, borders may only show up partially in MS Office Excel.