Pear Excel Writer:修剪前导零 - 如何防止?
我正在使用 Pear Excel Writer 包将数据集从 PHP 导出到 Excel。我的问题是某些数据字段有前导零(例如邮政编码),但这些字段在 Excel 中被修剪。我尝试在字段开头添加撇号以强制使用文本字段,但随后 Excel 显示它,这是我不想要的。我既不是 PHP 也不是 Excel 专家,但我希望我错过了一些相对简单的东西。有什么想法吗?
I'm using the Pear Excel Writer package to export a dataset to Excel from PHP. My problem is some of the data fields have leading zeros (such as a zip code), but these are being trimmed in Excel. I tried adding an apostrophe to the start of the fields to force a text field, but then Excel displays it, which I don't want. I'm neither a PHP nor Excel expert, but I expect I'm missing something relatively simple. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在 Excel 中显示前导零,您必须应用自定义数字格式。对于固定长度数字 - 您的情况 - 这将类似于
00000
(对于 5 位数字),对于可变长度数字,例如"000"#
(一个带有 3 个前导零的数字)。此 Excel 格式应由Spreadsheet_Excel_Writer
接管。如果没有,您可以使用Format::setNumFormat
。to display leading zeros in excel, you have to apply a custom number format. for fixed-length numbers - your case - this would be something like
00000
(for a 5 digit number), for variable-length numbers something like"000"#
(a number with 3 leading zeros). this excel format should be taken over bySpreadsheet_Excel_Writer
. if not, you could set it from within the writer withFormat::setNumFormat
.