Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Tolls

Thread: Applying Custom clors to cells using style

  1. #1
    Praveen198226 is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Applying Custom clors to cells using style

    Hi Everyone,

    I have to apply custom colors to Excel cells of HSSF Workbook. I have created cell style like but it is not applying expected clor.My POI version is 3.8v.

    HSSFWorkbook hssfwb = (HSSFWorkbook)wb;
    HSSFPalette palette = hssfwb.getCustomPalette();
    short colorIndex = 45;
    palette.setColorAtIndex(colorIndex, (byte)201, (byte)221, (byte)255);
    HSSFCellStyle style = ((HSSFWorkbook)wb).createCellStyle();
    style.setFillForegroundColor(colorIndex);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUN D);
    return style;
    Please help me on this.

    Thanks,
    ypk

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Applying Custom clors to cells using style

    Is it applying any colour?

    And does the setFillForegroundColor take the index, or does that short parameter represent something else?
    Please do not ask for code as refusal often offends.

  3. #3
    Praveen198226 is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Re: Applying Custom clors to cells using style

    Hi Tolls,

    Its not at all applying color.

    No idea on your second question. It is suppose to take short index but I am unsure whether it is taking or not. I am clue less about what is happening.

    Please help me.

    Thanks,
    ypk

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,094
    Rep Power
    4

    Default Re: Applying Custom clors to cells using style

    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Applying Custom clors to cells using style

    That link does raise a point.
    Are you actually assigning the style to a cell?
    Please do not ask for code as refusal often offends.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,094
    Rep Power
    4

    Default Re: Applying Custom clors to cells using style

    The style seems to come from the workbook, not a specific cell. You specify to the cell which index of the global palette to use (using that short value mentioned earlier). Somewhere along the line there must be a mix-up of which palette is actually used.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Applying Custom clors to cells using style

    No.
    You give the cell a style.
    That style has a colour from the colour palette associated with it.

    These are the relevant bits of the code at the link:
    Java Code:
        HSSFCell cell = row.createCell((short) 0);
        cell.setCellValue("Default Palette");
    
        HSSFCellStyle style = wb.createCellStyle();
        style.setFillForegroundColor(HSSFColor.LIME.index);
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    
        cell.setCellStyle(style);
    The later code simply changes the underlying palette.
    gimbal2 likes this.
    Please do not ask for code as refusal often offends.

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,094
    Rep Power
    4

    Default Re: Applying Custom clors to cells using style

    oh, I missed that bit. I stand corrected.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Applying Sound to Java Game
    By VTechJava in forum New To Java
    Replies: 2
    Last Post: 04-26-2013, 05:11 PM
  2. Applying Aspectj in EJB 2.0 without using Spring
    By hgupta1204 in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 04-25-2012, 08:59 AM
  3. Applying action event on window closing?
    By asifzbaig in forum AWT / Swing
    Replies: 2
    Last Post: 06-13-2011, 07:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •