Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing gridlines from excel using python (openpyxl)

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.

like image 627
user2343790 Avatar asked May 02 '13 16:05

user2343790


People also ask

How do you hide gridlines in Excel?

Select the worksheet. Click the Page Layout tab. To show gridlines: Under Gridlines, select the View check box. To hide gridlines: Under Gridlines, clear the View check box.

How do I remove gridlines in Excel Xlsxwriter?

hide_gridlines() Set the option to hide gridlines on the screen and the printed page. Parameters: option (int) – Hide gridline options.

Is openpyxl faster than pandas?

Step 3: Load with Openpyxl The file is loaded to memory but data is loaded through a generator which allows mapped-retrieval of values. Still slow but a tiny drop faster than Pandas.


1 Answers

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()
like image 197
alecxe Avatar answered Oct 13 '22 01:10

alecxe