3

I have a dataframe df where i want to change the header background color, apply borders and save it excel file in .xlsx extension.

I have tried styleframe, some functionalities in openpyxl and tried to write udf s, But nothing seemed to work.

2
  • 1
    Why don't you include in the question what you tried. It's okay if its broken. Commented Dec 27, 2016 at 6:35
  • Do you use Windows? If so, you can have Python interface with COM for full access to Excel object library. Commented Dec 27, 2016 at 9:11

1 Answer 1

3

Here is the solution using StyleFrame package that you mentioned.

import pandas as pd
from styleframe import StyleFrame, Styler, utils

df = pd.DataFrame({'a': [1, 2, 3], 'b': [1, 2, 3]})
sf = StyleFrame(df)

sf.apply_headers_style(styler_obj=Styler(bold=True,
                                         bg_color=utils.colors.green,
                                         border_type=utils.borders.medium))

sf.to_excel('output.xlsx').save()

I would recommend you to make sure that you have the lastest version of StyleFrame installed.

pip install -U styleframe
Sign up to request clarification or add additional context in comments.

2 Comments

Actually, it depends on pandas lower to 1.2.0, which is out of date
I do not know if it's a different version. but for latest versions the import doesn't work. should be changed to "from styleframe import StyleFrame, Styler, utils"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.