php PHPExcel:设置字体大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14243365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:55:58  来源:igfitidea点击:

PHPExcel: Setting font size?

phpphpexcel

提问by AnchovyLegend

I have been looking to change the font size of some Excel cells using a PHP library called PHPExcel.

我一直在寻找使用名为 PHPExcel 的 PHP 库来更改某些 Excel 单元格的字体大小。

This is what I tried:

这是我尝试过的:

$objPHPExcel->getActiveSheet()->getStyle("F1:G1")->getFont()->setFontSize(16);

The method above does not work. I was wondering if anyone knows how to do this?

上面的方法不起作用。我想知道是否有人知道如何做到这一点?

Many thanks in advance.

提前谢谢了。

回答by vvolkov

Use setSizemethod instead setFontSize, it should work:

改用setSizemethod setFontSize,它应该可以工作:

$objPHPExcel->getActiveSheet()->getStyle("F1:G1")->getFont()->setSize(16);

回答by simhumileco

If you want to use the style array, then you can do something like this:

如果要使用样式数组,则可以执行以下操作:

$fontStyle = [
    'font' => [
        'size' => 16
    ]
];

$workbook->getActiveSheet()
    ->getStyle("F1:G1")
    ->applyFromArray($fontStyle);