Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Folding multiple rows with openpyxl

Tags:

openpyxl

Is there a way to fold multiple rows using openpyxl? There doesn't appear to be a row equivalent to the example found on the openpyxl simple usage page.

import openpyxl
wb = openpyxl.Workbook(True)
ws = wb.create_sheet()
ws.column_dimensions.group('A','D', hidden=True)
wb.save('group.xlsx')
like image 492
lyineyes Avatar asked Nov 25 '14 18:11

lyineyes


Video Answer


2 Answers

You can do it using row_dimensions.group method

from openpyxl import Workbook

wb = Workbook()
ws = wb.create_sheet()
ws.column_dimensions.group("A", "D", hidden=True)
ws.row_dimensions.group(1, 5, hidden=True)
wb.save("group.xlsx")
like image 29
Vlad Bezden Avatar answered Oct 06 '22 04:10

Vlad Bezden


No, there isn't an equivalent but rows are slightly easier to deal with because they are always there, ColumnDimensions are created on demand. Simply set the rows you want to hidden.

Eg. to hide rows 5 to 9:

for idx in range(5, 10):
    ws.row_dimensions[idx].hidden = True
like image 120
Charlie Clark Avatar answered Oct 06 '22 04:10

Charlie Clark