Skip to content

Commit

Permalink
Make sure that column width is not too large when writing to xlsx
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuppmann committed Mar 2, 2024
1 parent 1ceeeeb commit 562b5da
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pyam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def write_sheet(writer, name, df, index=False):
if df.dtypes[col].name.startswith(("float", "int")):
width = len(str(col)) + 2
else:
width = (
max([df[col].map(lambda x: len(str(x or "None"))).max(), len(col)]) + 2
width = min(
max([df[col].map(lambda x: len(str(x or "None"))).max(), len(col)]) + 2,
100, # make sure that column width is not too large
)
writer.sheets[name].set_column(i, i, width) # assumes xlsxwriter as engine

Expand Down

0 comments on commit 562b5da

Please sign in to comment.