php PHPExcel 样式获取默认数字格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21170401/
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 03:52:05  来源:igfitidea点击:

PHPExcel Style getting default number format

phpphpexcel

提问by hectorh30

I have the following code

我有以下代码

$xl = new PHPExcel();
$sheet = xl->setActiveSheetIndex(0)
$sheet->getStyle('A')->getNumberFormat()->setFormatCode('#,##0.00');
$format = $sheet->getStyle('A')->getNumberFormat()->getFormatCode();

I'd expect $format to contain #,##0.00but it contains General.

我希望 $format 包含#,##0.00但它包含General.

Am I missing something?

我错过了什么吗?

PHPExcel v. 1.7.6

PHPExcel v. 1.7.6

回答by Mark Baker

PHPExcel does not support row or column styles: styles are applied to cells

PHPExcel 不支持行或列样式:样式应用于单元格

$sheet->getStyle('A1')->getNumberFormat()->setFormatCode('#,##0.00');

or to ranges of cells

或单元格范围

$sheet->getStyle('A1:B2')->getNumberFormat()->setFormatCode('#,##0.00');

and version 1.7.6 is very dated now, you really should upgrade to a more recent version

现在 1.7.6 版本已经过时了,你真的应该升级到更新的版本