2015-03-27 09:45
浏览 92

Phpexcel - 如何设置单元格值的字体格式

I am using phpexcel library. but when I want to set the font color, and different style for a cell value then when I export my file then those changes not applied there. my code is below

    require_once (SPEE_PLUGIN_DIRS . "/Classes/PHPExcel.php");

    require_once (SPEE_PLUGIN_DIRS . "/Classes/PHPExcel/IOFactory.php");

    $objPHPExcel = new PHPExcel();

    $styleArray = array(
                       'font'  => array(
                       'bold'  => true,
                       'color' => array('rgb' => 'FF0000'),
                       'size'  => 15,
                       'name'  => 'Verdana'





    $objPHPExcel->setActiveSheetIndex()->getStyle('E1')->applyFromArray(array("font" => array( "bold" => true))); // font not set bold.

    $objPHPExcel->getActiveSheet()->setCellValue('E1', 'my data');

    $objPHPExcel->getActiveSheet()->getCell('A7')->setValue('CNIC No');  

    $objPHPExcel->getActiveSheet()->getStyle('A7')->applyFromArray($styleArray); // this style array not work on 'A7'

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dti3914 2015-03-27 10:15

    At the bottom after ob_start(); replace all with the following code

    // Redirect output to a client’s web browser (Excel5)
    header('Content-Type: application/');
    header('Content-Disposition: attachment;filename="01simple.xls"');
    header('Cache-Control: max-age=0');
    // If you're serving to IE 9, then the following may be needed
    header('Cache-Control: max-age=1');
    // If you're serving to IE over SSL, then the following may be needed
    header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always  modified
    header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
    header ('Pragma: public'); // HTTP/1.0
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    打赏 评论

相关推荐 更多相似问题