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
PHPExcel Style getting default number format
提问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 版本已经过时了,你真的应该升级到更新的版本

