CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 1 of 1

Thread: Java Excel automation cell background color repeating setFillForeground

  1. #1
    Join Date
    Aug 2008

    Question Java Excel automation cell background color repeating setFillForeground

    Hey all I have the code below that changes the background of a cell to either RED or GREEN. It seems that when I comment out the GREEN else code that my excel sheet has all red for each cell box in row 1. Likewise, if I do the opposite and comment out RED and un-comment GREEN then all the cells in row 1 are green.

    I'm not understanding what in the code below is making it color all the cells the same color even though the first 2 cells should be RED while all the others should be GREEN. I already checked my logic and its going to the first IF 2 times and then the rest is going to the else so that's correct.

    My code:
    static CellStyle headerCellStyle    = workbook.createCellStyle();
    for (int i = 0; i < arr.length; i++) {
         Row row             = sheet.createRow(rowNum1++);
         HSSFWorkbook hwb    = new HSSFWorkbook();
         HSSFPalette palette = hwb.getCustomPalette();
         Cell cell           = row.createCell(colNum);
         if (arr[i].contains("*")) {
             cell.setCellValue(arr[i].replace(" " + (i + 1) + ".xml*", ""));
         } else {
             cell.setCellValue(arr[i].replace(" " + (i + 1) + ".xml", ""));
    I'm sure I am just looking over something quite obvious but at this time I'm not able to find what that may be.

    Any help would be great!

    Note: Also posted to the following forums:

    Last edited by StealthRT; October 16th, 2019 at 12:16 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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)