Home > Software engineering >  Why does xlsxwriter write ' at the start of my cells
Why does xlsxwriter write ' at the start of my cells

Time:10-24

it is my code:

import xlsxwriter

# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook('Expenses01.xlsx')
worksheet = workbook.add_worksheet()

# Some data we want to write to the worksheet.


# Write a total using a formula.
worksheet.write_string(0, 0, '99999999001')
worksheet.write_string(0, 1, '99999999001')
worksheet.write_string(0, 2, '99999999001')
worksheet.write_string(0, 3, '99999999001')
worksheet.write_string(0, 4, '99999999001')
worksheet.write_string(0, 5, '99999999001')

workbook.close()

I am using

Ubuntu 20.04.2 LTS

XlsxWriter==3.0.1

LibreOffice Calc Version: 6.4.7.2

In Libre office cells contains this: '99999999001 - why XlsxWriterr add apostophe to start of my cells?

enter image description here

CodePudding user response:

The apostrophe before your number in Libreoffice just notes that the cell format is of type text. It isn't actually a part of the cell's content. See this link for more information: enter image description here

CodePudding user response:

To interpret it as string, not number.

If the value is "000123", by default, XLSX will treat it as number and you will see "123" as cell value. The leading "zero(s)" is missing.

If prefixed with apostrophe ', it will be treated as text and you will see the original input which is "000123". The leading zero(s) will not disappear.

The prefixed apostrophe symbol is very useful especially if you are storing tel phone number, social identity number, area code, membership no, or any product code that leading zero is crucial for it's data identification.

  • Related