PHPExcel - 如何设计excel - 更改颜色,合并行?

时间:2014-07-10 10:37:56

标签: php codeigniter phpexcel

我正在使用PHPExcel我需要设计一些带有颜色的excel并合并行和列,

我创造的是

include ('Classes/PHPExcel.php');
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle("My Sheet");

$rowCount = 1;
$objPHPExcel->getProperties()->setTitle("Title");

$objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, 'test val1');
$objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, 'test val2');
$objPHPExcel->getActiveSheet()->SetCellValue('c'.$rowCount, 'test val3');

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save('uploadedimage/Report/some_excel_file.xlsx');

此代码生成excel表,但我需要一张包含大量数据和格式的Excel工作表

提前谢谢

1 个答案:

答案 0 :(得分:2)

合并单元格
$objPHPExcel->mergeCells("D1:N1");

设置颜色:

$objPHPExcel->getStyle('A1')->applyFromArray(
    array(
        'fill' => array(
            'type' => PHPExcel_Style_Fill::FILL_SOLID,
            'color' => array('rgb' => 'FF0000')
        )
    )
);