I have a data in master excel file which I am trying to split and store it in multiple child excel files.
I would like to format the data in child files as a table.
So, I tried the below code
tab = Table(displayName = "Table1", ref = "A1:" get_column_letter(wb1.worksheets[0].max_column) str(wb1.worksheets[0].max_row) )
style = TableStyleInfo(name="TableStyleMedium2", showFirstColumn=True, showLastColumn=True, showRowStripes=True, showColumnStripes=True)
tab.tableStyleInfo = style
wb1.worksheets[0].add_table(tab)
But in my master file, the TableStyleMedium2
looks like below
When I apply the same style to my child file (shown in code above), it looks slightly different
You can see that alternate rows are not fully white. instead only certain cells are white.
I found out that openpyxl takes Bandedcolumns=True
by default but I am unable to turn it off programmatically. I am able to manually resolve this issue by unchecking Bandedcolumns
but how do I do it using openpyxl
TypeError: init() got an unexpected keyword argument 'showBandedColumns'
Why is this happening and how can I resolve this?
CodePudding user response:
The attributes
showRowStripes=
showColumnStripes=
control the Style options 'Banded Rows' and 'Banded Columns' in the Table design Tab respectively, setting to False will disable
style = TableStyleInfo(name="TableStyleMedium2",
showFirstColumn=True,
showLastColumn=True,
showRowStripes=True,
showColumnStripes=False)
will uncheck the 'Banded Columns' box.