开发者

Pear Excel Writer: trimming leading zeros - how to prevent?

开发者 https://www.devze.com 2022-12-13 10:39 出处:网络
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 ar开发者_如何学Ce being trimmed

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 ar开发者_如何学Ce 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号