question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: `Styler.to_excel` does not export styles and formats correctly

See original GitHub issue

This is a tracker / explainer for the various issues:

  • (#21221)
  • (#25185)
  • (#30008)
  • (#34438)

Essentially these issues record 3 things:

Set_table_styles

Styler.set_table_styles is not exported to excel. This will not be changed (at least by me). To write xlsx, excel styling needs to be attached on a per-cell basis, whereas in HTML indirect references can be created in the CSS language that the browser will parse, for example thead th will apply to all header cells in the header section, and tbody th:nth-child(3n+0) will apply to every third header cell in the body section starting with first. Without writing our own HTML to cell translator for the CSS language it is therefore impossible to map and account for all the complex CSS rules that can be used within set_table_styles. This is well documented.

Todo:

  • We will instead propose changes that allow styling to header cells, to complement that already in place for body cells, (#41995)

Exporting formatting

The number of possible formatting constructs allowed by Python is greater than what excel offers. Excel also has specified structures that differ from Pythons structures. It is impossible to dynamically code these relationships in some ambiguous cases. Therefore this will not be implemented.

Todo:

  • There is currently a pseudo CSS attribute: number-format which can be used to apply specific Excel based formatting. This should be much better documented with examples.

Border styles bug

Borders in CSS can be specified in many different ways, and the parsing code to translate this into excel’s border structure is broken

Todo

  • Review the border CSS translation code and propose a solution, if only to document a single way of getting this to work. (#45312)

Hiding and Concatening

The Styler uses the base implementation of DataFrame.to_excel. It does not do any preliminary filtering and/or alteration of the ctx object to format cells in the right place. It also doesnt react to hidden indexes and/or elements.

Todo

  • document some of the missing features in Styler.to_excel.
  • review how this can be implemented or insert a series of small PRs gradually improving the consistency.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
attack68commented, Aug 10, 2022

the updates have been provided where merged prs have been linked. any issues not currnetly being worked on do not have links or merged prs.

0reactions
Freud16commented, Dec 19, 2022

or just use styler.applymap_index which is one of the PRs that addressed part of these issues

didn’t know we have that, tks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does the export of a styled pandas dataframe to Excel not ...
I have tried to df.style.applymap , it does not return an error but it does not seem to work. Anyone has any ideas...
Read more >
Excel Export - Styles - Angular Data Grid
Excel Export provides a special mechanism to add styles to the exported spreadsheet that works independently of the styles applied to the grid....
Read more >
pandas.io.formats.style.Styler.to_excel
Representation for infinity (there is no native representation for infinity in Excel). verbosebool, default True. Display more information in the error logs.
Read more >
Improving Pandas Excel Output - Practical Business Python -
In addition there was a subtle bug in prior pandas versions that would not allow the formatting to work correctly when using XlsxWriter...
Read more >
Export Data Store Entity to Excel Smart Service - Appian 22.1
The exported data can then be imported into other third-party ... The Smart Service returns a document in an Excel format. ... Style:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found