且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在PHPExcel中设置字体颜色,字体和字体大小

更新时间:2022-02-13 16:41:54

我建议您开始阅读文档(4.6.18。格式化单元格)。当应用很多格式化时,***使用 applyFromArray()根据文档,此方法也假设在设置许多样式属性时更快。有一个附件,您可以在其中找到此功能的所有可能的键。

I recommend you start reading the documentation (4.6.18. Formatting cells). When applying a lot of formatting it's better to use applyFromArray() According to the documentation this method is also suppose to be faster when you're setting many style properties. There's an annex where you can find all the possible keys for this function.

这将为您工作:

$phpExcel = new PHPExcel();

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

$phpExcel->getActiveSheet()->getCell('A1')->setValue('Some text');
$phpExcel->getActiveSheet()->getStyle('A1')->applyFromArray($styleArray);