Color of the "POI" custom cell

Source: Internet
Author: User
Tags border color set background

Process Description:

The POI object includes a partial base color, which is used in the form

Hssfcellstyle Styleheader = Wb.createcellstyle ()//Create a cell's style
        //Background color setting
        style.setfillbackgroundcolor ( HSSFColor.GREEN.index);

Among them, HSSFColor.GREEN.index is the color that poi comes with.

Our idea is to modify POI's own color, configure its RGB to the color we want, and then let the system call.

Complete process:

1. Create Worksheets and Content Sheet page objects

Hssfworkbook wb = new Hssfworkbook ();
Hssfsheet sheet = wb.createsheet ("Sheet 1");

2. Modify the original POI color object, modify it to the desired color

Set the custom color
hssfpalette Custompalette = Wb.getcustompalette ();  
            Custompalette.setcoloratindex (HSSFColor.LIGHT_GREEN.index, (byte) 0, (byte) 204, (byte) 153); 

            Custompalette.setcoloratindex (HSSFColor.LIGHT_BLUE.index, (byte) 203, (byte) 236, (byte) 222); 

            

3. Create row

Hssfcell cell;
Hssfrow Row;

4. Create a Style object

Hssfcellstyle Styleheader = Wb.createcellstyle ()//Create a cell's style//Background color setting Style.setfillbackgroundcolor (hssfcolor.gre

        En.index);
        Fill mode Style.setfillpattern (hssfcellstyle.solid_foreground); Style.setalignment (Hssfcellstyle.align_center)//Set Horizontal center Style.setverticalalignment (hssfcellstyle.vertical_
        Center)/Up/down Center//set up and down the left and right border style style.setborderleft (Hssfcellstyle.border_thick);
        Style.setborderbottom (Hssfcellstyle.border_thick);
        Style.setborderright (Hssfcellstyle.border_thick);

        Style.setbordertop (Hssfcellstyle.border_thick);
        Sets the border color Style.setbottombordercolor (HSSFColor.WHITE.index);
        Style.settopbordercolor (HSSFColor.WHITE.index);
        Style.setleftbordercolor (HSSFColor.WHITE.index);


        Style.setrightbordercolor (HSSFColor.WHITE.index);
        Sets the font to Hssffont font = Wb.createfont ();
        Font.setfontname ("Microsoft Yahei"); Font.setfontheightinpoints ((short) 14);

        Font.setboldweight (Hssffont.boldweight_normal);
        Set Background color style.setfillforegroundcolor (HSSFColor.LIGHT_BLUE.index); Font.setcolor (HSSFColor.BLACK.index);

5. Add cell to row

Table header Data
        string[] HeadRow1 = {"", "GMV", "UV", "CVR", "Price"};
        Inserts data
        int rowint = 1 from the second line;
        row = Sheet.createrow ((short) rowint++);
        Row.setheight ((short) (538));
        Inserts the first header data for
        (int i = 0; i < headrow1.length i++) {
             cell = Row.createcell (i+6);
             Cell.setcellvalue (Headrow1[i]);
             Cell.setcellstyle (Styleheader);
         }

The main code is the second paragraph.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.