Setting background custom color, XSSFWorkbook











up vote
0
down vote

favorite












I use this code to change the font in excel to color, which I define



        Color sColor = new Color (value,0,0);
XSSFColor userColor = new XSSFColor(sColor);

CellStyle style = wb.createCellStyle();
XSSFFont font = wb.createFont();

font.setColor(userColor);
style.setFont(font);
cell.setCellStyle(style);


Can I change the cell's Background same way.



I saw the question here
Setting background custom color not working for XSSF in Apache POI
And I used the code:



        XSSFCellStyle cellStyle = wb.createCellStyle();
XSSFColor color = new XSSFColor(new java.awt.Color(value, 0, 0));
((XSSFCellStyle)cellStyle).setFillBackgroundColor(color);

cell.setCellStyle(cellStyle);


The background still always white.



Am sure that all other parts of the code written properly, because it works when I changed the font.



I have office 2010 on my computer










share|improve this question
























  • "but I had error on" what error? compiler error? runtime error? what is the error/what is it supposed to be doing that its not?
    – scigs
    Nov 7 at 20:50










  • @scigs can you please see the question after editing.
    – Ezz Eddin Othman
    Nov 10 at 17:44















up vote
0
down vote

favorite












I use this code to change the font in excel to color, which I define



        Color sColor = new Color (value,0,0);
XSSFColor userColor = new XSSFColor(sColor);

CellStyle style = wb.createCellStyle();
XSSFFont font = wb.createFont();

font.setColor(userColor);
style.setFont(font);
cell.setCellStyle(style);


Can I change the cell's Background same way.



I saw the question here
Setting background custom color not working for XSSF in Apache POI
And I used the code:



        XSSFCellStyle cellStyle = wb.createCellStyle();
XSSFColor color = new XSSFColor(new java.awt.Color(value, 0, 0));
((XSSFCellStyle)cellStyle).setFillBackgroundColor(color);

cell.setCellStyle(cellStyle);


The background still always white.



Am sure that all other parts of the code written properly, because it works when I changed the font.



I have office 2010 on my computer










share|improve this question
























  • "but I had error on" what error? compiler error? runtime error? what is the error/what is it supposed to be doing that its not?
    – scigs
    Nov 7 at 20:50










  • @scigs can you please see the question after editing.
    – Ezz Eddin Othman
    Nov 10 at 17:44













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I use this code to change the font in excel to color, which I define



        Color sColor = new Color (value,0,0);
XSSFColor userColor = new XSSFColor(sColor);

CellStyle style = wb.createCellStyle();
XSSFFont font = wb.createFont();

font.setColor(userColor);
style.setFont(font);
cell.setCellStyle(style);


Can I change the cell's Background same way.



I saw the question here
Setting background custom color not working for XSSF in Apache POI
And I used the code:



        XSSFCellStyle cellStyle = wb.createCellStyle();
XSSFColor color = new XSSFColor(new java.awt.Color(value, 0, 0));
((XSSFCellStyle)cellStyle).setFillBackgroundColor(color);

cell.setCellStyle(cellStyle);


The background still always white.



Am sure that all other parts of the code written properly, because it works when I changed the font.



I have office 2010 on my computer










share|improve this question















I use this code to change the font in excel to color, which I define



        Color sColor = new Color (value,0,0);
XSSFColor userColor = new XSSFColor(sColor);

CellStyle style = wb.createCellStyle();
XSSFFont font = wb.createFont();

font.setColor(userColor);
style.setFont(font);
cell.setCellStyle(style);


Can I change the cell's Background same way.



I saw the question here
Setting background custom color not working for XSSF in Apache POI
And I used the code:



        XSSFCellStyle cellStyle = wb.createCellStyle();
XSSFColor color = new XSSFColor(new java.awt.Color(value, 0, 0));
((XSSFCellStyle)cellStyle).setFillBackgroundColor(color);

cell.setCellStyle(cellStyle);


The background still always white.



Am sure that all other parts of the code written properly, because it works when I changed the font.



I have office 2010 on my computer







java excel apache






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 17:43

























asked Nov 7 at 20:47









Ezz Eddin Othman

488




488












  • "but I had error on" what error? compiler error? runtime error? what is the error/what is it supposed to be doing that its not?
    – scigs
    Nov 7 at 20:50










  • @scigs can you please see the question after editing.
    – Ezz Eddin Othman
    Nov 10 at 17:44


















  • "but I had error on" what error? compiler error? runtime error? what is the error/what is it supposed to be doing that its not?
    – scigs
    Nov 7 at 20:50










  • @scigs can you please see the question after editing.
    – Ezz Eddin Othman
    Nov 10 at 17:44
















"but I had error on" what error? compiler error? runtime error? what is the error/what is it supposed to be doing that its not?
– scigs
Nov 7 at 20:50




"but I had error on" what error? compiler error? runtime error? what is the error/what is it supposed to be doing that its not?
– scigs
Nov 7 at 20:50












@scigs can you please see the question after editing.
– Ezz Eddin Othman
Nov 10 at 17:44




@scigs can you please see the question after editing.
– Ezz Eddin Othman
Nov 10 at 17:44












2 Answers
2






active

oldest

votes

















up vote
0
down vote













Create cell style object:



CellStyle backgroundStyle = workbook.createCellStyle(); 


Set custom color:



backgroundStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());


Add style to the cell:



cell.setCellStyle(backgroundStyle);





share|improve this answer




























    up vote
    0
    down vote



    accepted










    Thanks all
    I found solution now



            XSSFCellStyle cellStyle = wb.createCellStyle();

    XSSFColor color = new XSSFColor(new java.awt.Color(value, 0, 0));

    ((XSSFCellStyle)cellStyle).setFillBackgroundColor(color);
    cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    cellStyle.setFillForegroundColor(color);
    cell.setCellStyle(cellStyle);





    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53197569%2fsetting-background-custom-color-xssfworkbook%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      Create cell style object:



      CellStyle backgroundStyle = workbook.createCellStyle(); 


      Set custom color:



      backgroundStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());


      Add style to the cell:



      cell.setCellStyle(backgroundStyle);





      share|improve this answer

























        up vote
        0
        down vote













        Create cell style object:



        CellStyle backgroundStyle = workbook.createCellStyle(); 


        Set custom color:



        backgroundStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());


        Add style to the cell:



        cell.setCellStyle(backgroundStyle);





        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote









          Create cell style object:



          CellStyle backgroundStyle = workbook.createCellStyle(); 


          Set custom color:



          backgroundStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());


          Add style to the cell:



          cell.setCellStyle(backgroundStyle);





          share|improve this answer












          Create cell style object:



          CellStyle backgroundStyle = workbook.createCellStyle(); 


          Set custom color:



          backgroundStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());


          Add style to the cell:



          cell.setCellStyle(backgroundStyle);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 7 at 21:00









          Centos

          17519




          17519
























              up vote
              0
              down vote



              accepted










              Thanks all
              I found solution now



                      XSSFCellStyle cellStyle = wb.createCellStyle();

              XSSFColor color = new XSSFColor(new java.awt.Color(value, 0, 0));

              ((XSSFCellStyle)cellStyle).setFillBackgroundColor(color);
              cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
              cellStyle.setFillForegroundColor(color);
              cell.setCellStyle(cellStyle);





              share|improve this answer

























                up vote
                0
                down vote



                accepted










                Thanks all
                I found solution now



                        XSSFCellStyle cellStyle = wb.createCellStyle();

                XSSFColor color = new XSSFColor(new java.awt.Color(value, 0, 0));

                ((XSSFCellStyle)cellStyle).setFillBackgroundColor(color);
                cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                cellStyle.setFillForegroundColor(color);
                cell.setCellStyle(cellStyle);





                share|improve this answer























                  up vote
                  0
                  down vote



                  accepted







                  up vote
                  0
                  down vote



                  accepted






                  Thanks all
                  I found solution now



                          XSSFCellStyle cellStyle = wb.createCellStyle();

                  XSSFColor color = new XSSFColor(new java.awt.Color(value, 0, 0));

                  ((XSSFCellStyle)cellStyle).setFillBackgroundColor(color);
                  cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                  cellStyle.setFillForegroundColor(color);
                  cell.setCellStyle(cellStyle);





                  share|improve this answer












                  Thanks all
                  I found solution now



                          XSSFCellStyle cellStyle = wb.createCellStyle();

                  XSSFColor color = new XSSFColor(new java.awt.Color(value, 0, 0));

                  ((XSSFCellStyle)cellStyle).setFillBackgroundColor(color);
                  cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                  cellStyle.setFillForegroundColor(color);
                  cell.setCellStyle(cellStyle);






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 10 at 18:15









                  Ezz Eddin Othman

                  488




                  488






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53197569%2fsetting-background-custom-color-xssfworkbook%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Hercules Kyvelos

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud