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.