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

  • Home
  • SEARCH
  • 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 8119503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:49:09+00:00 2026-06-06T04:49:09+00:00

I am using POI 3.8 version and trying to read the background color of

  • 0

I am using POI 3.8 version and trying to read the background color of a cell in an excel sheet (XLS). Ideally I wanted to copy this cell with styles to a different sheet. When I did a cloneFrom(..) method, its not copying the correct colors to the target sheet.

When I tried to read the cell’s background color separately, I am not getting the correct RGB value. If I could get the correct RGB value I can create a custom palette and set the same to the target sheet’s cell.

Is there a correct way of reading the background color from a cell?

I have tried the following

cell.getCellStyle().getFillBackgroundColor()
cell.getCellStyle().getFillBackgroundColorColor().getTriplet() 

The above line should give me RGB value of 159/200/222, but is giving me an incorrect value of 51/204/204.

Could someone please help on the same. I have already checked this forum for all possible answers and still could not get what I want.

  • 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-06-06T04:49:10+00:00Added an answer on June 6, 2026 at 4:49 am

    The problem is that HSSF uses a color palette (essentially an array of colors) to define its RGB values. So the background color is actually an index into the palette. Here is some code to get the actual rgb values of the cell’s background color:

        CellStyle style = cell.getCellStyle();
        short colorIdx = style.getFillForegroundColor();
        HSSFPalette palette = ((HSSFWorkbook) wb).getCustomPalette();
        HSSFColor color = palette.getColor(colorIdx);
        short [] triplet = color.getTriplet();
        // triplet will contain the actual rgb values
    

    In your output spreadsheet, you have to add a custom color to the palette. If there is an empty space in your output’s palette, you can use HSSFPalette.addColor. Otherwise, you will have to replace an unused existing color using HSSFPalette.setColorAtIndex. Once you add the custom color, you use CellStyle.setFillBackgroundColor to set the cell’s background color, passing in the index of the custom color you just created.

    If you can use an XSSF (xlsx) file instead of an HSSF (xls) file, you would not need to fool around with a color palette. You can use actual rgb values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read all cell value from excel sheet using Apache POI and
I'm trying to set Excel cell colors using Apache POI in Java. I played
I'm using POI library to read excel sheets, xls and xlsx. I'm wondering if
I have tried to read an excel file using POI and then I wanted
folks, I am able to read the excel sheet using apache POI in grails
I have just Extracted the cells from the excel sheet using Apache POI, everything
I'm using the apache POI to read Word documents. I'm using this example as
i am trying to read an excel file using java. while compiling the program
I'm trying to generate an excel file with some validations, I've read the poi
I'm using Apache POI 3.6, I want to read an excel file which has

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.