PHPExcel-列的格式 [英] PHPExcel - format for the column
问题描述
我需要为所有列格式设置:FORMAT_NUMBER
I need to set for all columns format: FORMAT_NUMBER
我可以为一个牢房做一个.但是我不能为整个B列做准备.
I can do it for one cell. But I can not do for the whole column B.
$objPHPExcel->getActiveSheet()->getStyle('B2')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
如何设置整个B列? PHPExcel_Style_NumberFormat :: FORMAT_NUMBER
How to set the entire column B? PHPExcel_Style_NumberFormat :: FORMAT_NUMBER
推荐答案
您可以为单个单元格或一系列单元格设置样式;但不适用于列或行.
You can set styling for an individual cell, or for a range of cells; but not for a column or a row.
要设置范围的样式,请使用
To set the style for a range, use
$objPHPExcel->getActiveSheet()
->getStyle('B2:B1024')
->getNumberFormat()
->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
因此,只需在列B
中标识要为其设置样式的第一行和最后一行,并以此为基础构建一个范围字符串.
So just identify the first and last rows that you want to set the style for in column B
, and build a range string from that.
$ column ='B'; $ firstRow = 2; $ lastRow = 1024;
$column = 'B'; $firstRow = 2; $lastRow = 1024;
$objPHPExcel->getActiveSheet()
->getStyle($column.$firstRow.':'.$column.$lastRow)
->getNumberFormat()
->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
这篇关于PHPExcel-列的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!