phpexcel - 如何更改excel的整列的数据类型 [英] phpexcel -How to change data type for whole column of an excel
问题描述
我正在为整列更改数据类型(例如:我需要将M列更改为一般格式)。在数量字段中显示为 2.00
,我需要将此整列更改为通用格式即。显示为2
。但是它不会更改数据类型。
I'm trying to change the datatype for a whole column (for eg: i need to change for "M" Column to general format). Its displaying as 2.00
in quantity field,I need to change this whole column to general format ie. display as "2"
. But its not changing the datatype.
这是代码:
$objPHPExcel->getActiveSheet()
->setCellValue(
$aCells[$eExcelColumn] . $eExcelRow,
$sCellData ,
PHPExcel_Cell_DataType::TYPE_NUMERIC
);
$objPHPExcel->getActiveSheet()->getStyle('M1:M97')
->getNumberFormat()
->setFormatCode('0');
如何将整列M作为一般格式
How to do for the whole column "M" as general format
推荐答案
PHPExcel不支持列或行样式:您需要设置范围
的样式细胞,正如你所做的那样
PHPExcel doesn't support column or row styling: you need to set the style for a range
of cells, exactly as you are doing with
$objPHPExcel->getActiveSheet()->getStyle('M1:M97')
->getNumberFormat()
->setFormatCode('0');
如果您想要一般
格式而不是'0'
,然后将其设置为一般
而不是
if you want General
format rather than '0'
, then set it to General
Instead:
$objPHPExcel->getActiveSheet()->getStyle('M1:M97')
->getNumberFormat()
->setFormatCode('General');
或
$objPHPExcel->getActiveSheet()->getStyle('M1:M97')
->getNumberFormat()
->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_GENERAL);
这篇关于phpexcel - 如何更改excel的整列的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!