[英]PHPExcel cell formating doesn't work after export
I have a PHP code that will export an array of data to excel. 我有一个PHP代码,可以将数据数组导出到excel。 It is working fine but the formatting isn't working on the output. 它工作正常,但格式在输出中不起作用。 For example, I have an array value of 0:13:00
(it is in 24 hour format). 例如,我的数组值为0:13:00
(采用24小时格式)。 What I want is to format it in excel to [mm]:ss
so the output should be 13:00
after the export but the value remain as it is while when I look on the cell formatting in excel, the format is already in [mm]:ss
. 我要在Excel中将其格式化为[mm]:ss
因此输出应为导出后的13:00
,但当我在excel中对单元格进行格式化时,该值保持不变,格式已经为[mm]:ss
。 I also tried changing the value to 12 hour format ( 12:13:00 AM
) but it also remain as it is after export. 我还尝试将值更改为12小时格式( 12:13:00 AM
),但在导出后也保持原样。 Can someone help me with this please. 有人可以帮我吗
Here is my code in formatting the cell using PHPExcel. 这是我使用PHPExcel格式化单元格的代码。
$sheet = $objPHPExcel->getActiveSheet();
$sheet->getStyle('C3:N199')->getNumberFormat()->setFormatCode('[mm]:ss');
You mean you have a string containing "0:13:00"
? 您的意思是您有一个包含"0:13:00"
的字符串? You need to convert it to an MS Excel Serialized timestamp for a number format code like [mm]:ss
to have any meaning.... use 您需要将其转换为MS Excel序列化时间戳,以使数字格式代码(如[mm]:ss
具有任何含义。
$objPHPExcel->getActiveSheet()
->setCellValue('A1',
PHPExcel_Calculation_DateTime::TIMEVALUE('00:13:15')
);
$objPHPExcel->getActiveSheet()
->getStyle('A1')
->getNumberFormat()
->setFormatCode('[mm]:ss');
as described in the PHPExcel documentation and examples 如PHPExcel文档和示例中所述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.