Reputation: 163
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.
Upvotes: 16
Views: 24265
Reputation: 21
For removing major grid lines of your plot in openpyxl use:
mychart.x_axis.majorGridlines = None
mychart.y_axis.majorGridlines = None
Upvotes: 1
Reputation: 3839
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
Upvotes: 20
Reputation: 474031
There is a relevant issue in openpyxl
issue tracker. Plus, according to the source code show_gridlines
is just a worksheet class property that has no affect at all. Just watch the issue to get any update on it.
As an alternative solution, try the new and awesome xlsxwriter module. It has an ability to hide grid lines on a worksheet (see docs). Here's an example:
from xlsxwriter.workbook import Workbook
workbook = Workbook('hello_world.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Hello world')
worksheet.hide_gridlines(2)
workbook.close()
Upvotes: 11