Given a wb
with 5 worksheets, I am adding a column to each every day using openpyxl
, and this has been working well. Now though, with just over 60 columns, the width of the first N number of columns (seems to be B through to BH) has become 0. This results in the columns essentially disappearing when opened in Excel:
Fetching the width of the first few columns confirms this (where fb
is a <Worksheet>
object):
In [71]: fb.column_dimensions["A"].width
Out[71]: 46.125
In [72]: fb.column_dimensions["B"].width
Out[72]: 0.0
In [73]: fb.column_dimensions["BI"].width
Out[73]: 11.75
In [73]: fb.column_dimensions["BJ"].width
Out[73]: 10.25
I've tried setting auto_size:
for dimension in fb.column_dimensions.values():
dimension.auto_size = True
and then saving the workbook, but this had no effect (columns are still invisible in Excel). So I tried manually setting the size of a couple of columns to a reasonable size e.g. 12:
fb.column_dimensions["B"].width = 12
and again saving, but still no change (columns are still invisible in Excel), despite the fact that when I reload the spreadsheet in openpyxl and check the columns width, they are set to the new (non-zero) size.
Should either or both of these approaches even have worked, and there is an additional step I'm missing?
Python: 2.7.10
Openpyxl: 2.2.2
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…