Snippet to reproduce:
import xlsxwriter
workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()
data_fmt = workbook.add_format({'num_format': r"0.00##\%;[RED](0.00##\%)"})
worksheet.write('A1', 5.5, data_fmt)
workbook.close()
My expecatation would be that when I open up that file and inspect the format for A1
it would be 0.00##\%;[RED](0.00##\%)
.
Instead I get 0.00##%;[RED](0.00##%)
NOTE: The format, taken from this stackoverflow question is what would give you the percent sign at the end without multiplying the value by 100.
EDIT2:
>>> import xlsxwriter
>>> xlsxwriter.__version__
'1.0.2'
Also, I am opening the file in LibreOffice.
EDIT3:
Here's a snippet that tries 1, 2, 3, and 4 backslashes. All of them produce the same format when I open the result in libreoffice.
import xlsxwriter
fmts = [r"0.00##\%;[RED](0.00##\%)", r"0.00##\\%;[RED](0.00##\\%)",
r"0.00##\\\%;[RED](0.00##\\\%)", r"0.00##\\\\%;[RED](0.00##\\\\%)"]
fp = "test{}.xlsx"
for i, fmt in enumerate(fmts):
workbook = xlsxwriter.Workbook(fp.format(i))
worksheet = workbook.add_worksheet()
data_fmt = workbook.add_format({'num_format': fmt})
worksheet.write('A1', 5.5, data_fmt)
workbook.close()
EDIT 4:
I have confirmed that this is issue does not exist in excel. So currently it is strictly a LibreOffice issue.