2025, Oct 02 19:00

Pandas Styler.bar() Won’t Show in Excel: Understand the Limitation and Use Native Data Bars or Export HTML

Learn why Pandas Styler.bar() disappears in Excel export, what to_excel() supports, and how to fix with Excel data bars or by exporting HTML for sharing.

When Pandas Styler renders beautiful bars over numeric columns in a Jupyter notebook, it’s tempting to expect the same inside an exported Excel file. The surprise comes when the spreadsheet opens and the bars are gone. This guide explains why it happens, what is actually supported, and how to share the styled result reliably.

Notebook vs. Excel: same data, different rendering engines

Styler in Jupyter uses HTML and CSS to visualize DataFrames. Excel, in contrast, doesn’t understand those CSS styles. As a consequence, certain visualizations that look great in the notebook won’t survive a round-trip to an .xlsx file.

Reproducible example showing the issue

The following snippet reads a CSV, applies Styler.bar() to the close column, and then writes to an Excel file. In a notebook, the bars appear. In Excel, they don’t.

import pandas as pd

quotes = pd.read_csv('./sp500.csv')

view = quotes.style

view.bar(subset=['close'], color='#6399ae',
         vmin=0, vmax=quotes['close'].max())

view.to_excel('./sp500.csv', index=False)

Why the bars disappear in Excel

Excel doesn’t support the CSS-based styles that Styler uses. Only a restricted subset of Styler output is exportable via to_excel(), and Styler.bar() isn’t included in that set. The official documentation confirms that only selected features are supported for Excel export. See the Export to Excel section in the Pandas Table Visualization docs: https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html#Export-to-Excel.

If you need in-cell bars inside Excel, you have to rely on Excel’s native conditional formatting (data bars), not the CSS bars generated by Styler.

What you can do instead

If the goal is a one-click, “execute and review” handoff that preserves the visual styling, exporting HTML is a direct route. The HTML will display the CSS bars exactly as seen in a notebook. The resulting file can be opened in any modern browser. From there, it is possible to select the rendered table and paste it into Microsoft Word via Paste Special using HTML Format. There may be ways to paste into Excel as well, but the reliable path described here is to Word.

import pandas as pd

quotes = pd.read_csv('./sp500.csv')

view = quotes.style

view.bar(subset=['close'], color='#6399ae',
         vmin=0, vmax=quotes['close'].max())

html_out = view.to_html()
with open('sp500.html', 'w', encoding='utf-8') as fh:
    fh.write(html_out)

This preserves the exact styling produced by Styler for easy sharing, viewing, and, if needed, copy-paste workflows into other tools that accept HTML formatting.

Why this matters for reporting workflows

Data presentation depends on the rendering engine of the target medium. Notebook-centric visual features are not automatically portable to Excel. Knowing this ahead of time helps avoid dead ends and guides you toward choosing the right output channel for the audience: native Excel features for spreadsheets, or HTML for web-like, pixel-accurate representations.

Takeaways

Styler.bar() is a CSS visualization and won’t survive export to Excel via to_excel(). For true Excel in-cell bars, use Excel’s data bars via conditional formatting. For quick one-click sharing that preserves Pandas styling, export HTML with to_html() and distribute the HTML file. Align the output format with the final destination and you’ll save time, avoid surprises, and deliver exactly what your reviewers expect.

The article is based on a question from StackOverflow by ludovico and an answer by Ashish Chandpa.