如何获得phpexcel以保持电话号码中的前导0? [英] How to get phpexcel to keep leading 0s in phone numbers?

查看:97
本文介绍了如何获得phpexcel以保持电话号码中的前导0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我现在用来设置单元格值的代码.如果该数字具有分隔符(如),则可以正常工作.或/,但是当没有分隔符时,它将另存为int,并且剥去了前导0

Here's the code i'm using right now to set the cell values. It works alright if the number has separators like . or / but when there's no separator it gets saved as int and the leading 0 is stripped

$sheet->setCellValue($letter[$j].$row_nr,$entity['Phone'], PHPExcel_Cell_DataType::TYPE_STRING);

推荐答案

任一:

// Set the value explicitly as a string
$objPHPExcel->getActiveSheet()->setCellValueExplicit('A1', '0029', PHPExcel_Cell_DataType::TYPE_STRING);

// Set the value as a number formatted with leading zeroes
$objPHPExcel->getActiveSheet()->setCellValue('A3', 29);
$objPHPExcel->getActiveSheet()->getStyle('A3')->getNumberFormat()->setFormatCode('0000');

请注意,在第一种情况下,我调用的是setCellValueExplicit()方法,而不是setCellValue()方法.在您的代码中,将PHPExcel_Cell_DataType :: TYPE_STRING传递给setCellValue()没有任何意义,并且该参数将被忽略.

Note that in the first case I'm calling the setCellValueExplicit() method, not the setCellValue() method. In your code, passing PHPExcel_Cell_DataType::TYPE_STRING to setCellValue() has no meaning, and the argument is simply ignored.

这篇关于如何获得phpexcel以保持电话号码中的前导0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆