[英]How to get PHPExcel cell format
I am reading an excel file using PHPExcel. 我正在使用PHPExcel阅读excel文件。 I want to know if there is way to know the cells format. 我想知道是否有办法知道单元格的格式。 Eg: no.of decimal places, if % or number etc. 例如:小数位数,如果%或数字等。
You can read the number format mask for a cell by doing: 您可以通过执行以下操作来读取单元格的数字格式掩码:
$objPHPExcel->getActiveSheet()
->getStyle('A1')
->getNumberFormat()
->getFormatCode();
which will return the formatting mask as a string 这将以字符串形式返回格式掩码
eg 例如
'£#,##0;-£#,##0'
or 要么
'0.00%'
but PHPExcel provides no functionality to interpret this mask to show whether it is a percentage or how many decimals should be shown; 但是PHPExcel没有提供解释此掩码以显示它是百分比还是应显示小数位数的功能; you'd need to add that logic yourself; 您需要自己添加该逻辑; although you could possibly extract some of the logic for interpreting it from the code for the toFormattedString()
method in PHPExcel_Style_NumberFormat
尽管你可能提取一些逻辑用于从所述代码将其解释为toFormattedString()
在方法PHPExcel_Style_NumberFormat
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.