Pear Excel Writer:修剪前导零 - 如何防止?

发布于 2024-08-13 16:53:54 字数 278 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情定在深秋 2024-08-20 16:53:54

要在 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 by Spreadsheet_Excel_Writer. if not, you could set it from within the writer with Format::setNumFormat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文