Removing gridlines from excel using python (openpyxl)

user2343790 picture user2343790 · May 2, 2013 · Viewed 9.1k times · Source

I'm trying to remove gridlines from excel worksheet which I created using openpyxl, and it's not working. I'm doing this:

wb = Workbook()   
ws = wb.get_active_sheet()
ws.show_gridlines = False
print ws.show_gridlines
wb.save('file.xlsx')

The that code prints the 'False', yet the saved file shows gridlines.

Answer

fralau picture fralau · Sep 18, 2017

This was fixed in 2015.

Here is the recommended solution (from description of issue)

from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws.sheet_view.showGridLines
True
ws.sheet_view.showGridLines = False
wb.save("gridlines.xlsx")

Beware that you should type ws.sheet_view.showGridLines and not ws.showGridLines.