JavaEar 专注于收集分享传播有价值的技术资料

Heading and total style in Excel 2007 using PHPExcel

Is it possible to apply a heading style (especially heading 3 as in excel 2007) and total style (as in excel 2007) in a cell in Excel 2007 using PHPExcel as shown in the following snippet?

enter image description here

I applied these styles after generating it (as can be seen in the Shipping Address, Billing Address and Total cells). Tried on Google for a long time but couldn't find it therefore, I presumably believed that they might not be supported by PHPExcel. Is there a way to do so using PHPExcel?

1个回答

    最佳答案
  1. Excel's "Predefined styles" aren't built into PHPExcel, although it wouldn't be too difficult to emulate.

    You can define a style array to replicate any of Excel's predefined styles, and then use the applyFromArray() method to set a cell to that style.

    $totalStyle = array(
        'borders' => array(
            'outline' => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN,
                'color' => array('argb' => 'FF000000'),
            ),
        ),
    );
    $objPHPExcel->getActiveSheet()->getStyle('A4:C4')->applyFromArray($totalStyle);
    

    All you need to do is work out the individual components of each pre-defined Excel style, and define the style array accordingly.