Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6929017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:15:51+00:00 2026-05-27T11:15:51+00:00

I need advice on setting styles in Openpyxl. I see that the NumberFormat of

  • 0

I need advice on setting styles in Openpyxl.

I see that the NumberFormat of a cell can be set, but I also require setting of font colors and attributes (bold etc). There is a style.py class but it seems I can’t set the style attribute of a cell, and I don’t really want to start tinkering with the openpyxl source code.

Has anyone found a solution to this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:15:51+00:00Added an answer on May 27, 2026 at 11:15 am

    As of openpyxl version 1.5.7, I have successfully applied the following worksheet style options…

    from openpyxl.reader.excel import load_workbook
    from openpyxl.workbook import Workbook
    from openpyxl.styles import Color, Fill
    from openpyxl.cell import Cell
    
    # Load the workbook...
    book = load_workbook('foo.xlsx')
    
    # define ws here, in this case I pick the first worksheet in the workbook...
    #    NOTE: openpyxl has other ways to select a specific worksheet (i.e. by name
    #    via book.get_sheet_by_name('someWorksheetName'))
    ws = book.worksheets[0]
    
    ## ws is a openpypxl worksheet object
    _cell = ws.cell('C1')
    
    # Font properties
    _cell.style.font.color.index = Color.GREEN
    _cell.style.font.name = 'Arial'
    _cell.style.font.size = 8
    _cell.style.font.bold = True
    _cell.style.alignment.wrap_text = True
    
    # Cell background color
    _cell.style.fill.fill_type = Fill.FILL_SOLID
    _cell.style.fill.start_color.index = Color.DARKRED
    
    # You should only modify column dimensions after you have written a cell in 
    #     the column. Perfect world: write column dimensions once per column
    # 
    ws.column_dimensions["C"].width = 60.0
    

    FYI, you can find the names of the colors in openpyxl/style.py… I sometimes I patch in extra colors from the X11 color names

    class Color(HashableObject):
        """Named colors for use in styles."""
        BLACK = 'FF000000'
        WHITE = 'FFFFFFFF'
        RED = 'FFFF0000'
        DARKRED = 'FF800000'
        BLUE = 'FF0000FF'
        DARKBLUE = 'FF000080'
        GREEN = 'FF00FF00'
        DARKGREEN = 'FF008000'
        YELLOW = 'FFFFFF00'
        DARKYELLOW = 'FF808000'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I have this working but I need advice. I'd like to know
I need some advice. I’m building an app that has a sequence of 4
I need some help - I have tried setting setSpecificDate so that the array
I need some advice on how to set column widths in a HTML table.
I need advice and how to got about setting up a simple service for
Can anyone give me any advice on setting up the ability for a user
I need advice or directions on how to write an algorithm which will find
I need advice on the following HTML: <!-- Beginning of ROW !--> <div id="row1">
I need advice on using stored procedures with Entity Framwork 4.x to return data
I need advice on how to change the file formatted following way file1: A

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.