I am using Spreadsheet_Excel_Writer and it works great for creating Excel files on the fly. However, I am having trouble trying to get some data to be saved correctly.

We have UPCs, like 050000235001, and the leading zero gets removed. I know in Excel you can format the cell to a text type, but how do I do that when creating the spread sheet?

There is setNumFormat() but that only formats number types, like percentages, dates, times, etc.

    have you verified that its not php that is removing those 0's because its treating the string as a number?
    you could do something like $upc = sprintf("%012s", $upc); if they are 12 digit upc's. that will put the leading 0's on.

      Drew,
      I tried your suggestion and the zeros are still removed. My guess is that the excel writer, or excel itself, is treating the UPC as numbers and not text. I also tried it in Open Office with the same results.

      Anyone know how to fix this?
      Travis

        This is a completely untested idea (never done any of this, but given what I know (pretty much nothing) it's what I'd try), but can you write it out with quotes around it? As '050000235001' instead of just 050000235001?

          Write a Reply...