字符串/数字以零开头的格式正确吗? [英] Correct format for strings / numbers beginning with zero?

查看:107
本文介绍了字符串/数字以零开头的格式正确吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP创建一个包含电话号码列表的文件. 可以,但是如果电话号码以零开头,则会从Excel文件中删除该数字.

I'm trying to use PHP to create a file containing a list of phone numbers. It's working OK however if the phone number begins with zero, the digit is dropped from the Excel file.

有人知道如何正确设置格式以使其保持不变吗?

Does anyone know how to set the formatting correctly so that it remains in place?

推荐答案

任一:

// 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');

这篇关于字符串/数字以零开头的格式正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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