简体   繁体   中英

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

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM