Do not display 0's in workbook xlsxwriter

Viewed 100

There is a way to have a workbook not display 0 values under Excel->Preferences (on mac). Is there a way to set this with xlsxwriter? I know I can do this via conditional formatting for each sheet, but it involves setting the font to be an invisible color and my background colors are variable, so that's a lot more complicated.

1 Answers

You can use the worksheet.hide_zero() method, like this:

import xlsxwriter

workbook = xlsxwriter.Workbook('hide_zero.xlsx')
worksheet = workbook.add_worksheet()

worksheet.hide_zero()

worksheet.write('A1', 1)
worksheet.write('A2', 0)
worksheet.write('A3', 1)

workbook.close()

Output:

enter image description here

Related