Hi all,
My python script is accessing data and exporting to excel .xlsx
I have a text field which contains 0 in front.
Problem facing is when export to .xlsx the text field License number is deleted.
The problem is Excel interpreting it as a number rather than a zip code. If you can format the cell as “Text” that might work. Alternatively you can prepend a single quotation, ' before the zip code and it should display properly (I’m not sure if this will mess with things later, though)
This forum doesn’t have that feature enabled, but your reply will be sufficient for future readers!
Were you able to pre-format the cell as text in your code, or did you use the ' to get it to display? I wasn’t sure if the first option was possible with whatever library you are using to write Excel files.
This is normal behavior when you write a cell with .write_number(). When you open the Excel file Excel will drop any leading zeroes for cells formatted as a number.
So when writing a zip code use .write_string().
When I’m writing Excel files with Xlsxwriter and pandas I have 2 routines:
WriteXlsx(). Writes out the whole Excel file row by row and calls WriteXlsxCell().
WriteXlsxCell(): parameters are row, column, data and I think a format object. It writes one cell and determines if the cell is a number, text, or formula, and calls .write_number(), .write_string(), or .write_formula().
Here is the documentation for the Worksheet class which has the write routines like .write_string(), .write_number(), and .write_formula().