Reference: http://apps.hi.baidu.com/share/detail/17249059
Poi may use some Operation Summaries for setting the Excel cell format:
Obtain the thin objects first:
Hssfworkbook WB = new hssfworkbook ();
Hssfsheet sheet = WB. createsheet ();
Hssfcellstyle setborder = WB. createcellstyle ();
1. Set the background color:
Setborder. setfillforegroundcolor (short) 13); // you can specify the background color.
Setborder. setfillpattern (hssfcellstyle. solid_foreground );
2. Set the border:
Setborder. setborderbottom (hssfcellstyle. border_thin); // Bottom Border
Setborder. setborderleft (hssfcellstyle. border_thin); // left border
Setborder. setbordertop (hssfcellstyle. border_thin); // The upper border
Setborder. setborderright (hssfcellstyle. border_thin); // right border
3. Set center:
Setborder. setalignment (hssfcellstyle. align_center); // center
4. Set the font:
Hssffont font = WB. createfont ();
Font. setfontname (" ");
Font. setfontheightinpoints (short) 16); // you can specify the font size.
Hssffont font2 = WB. createfont ();
Font2.setfontname (" _ gb2312 ");
Font2.setboldweight (hssffont. boldweight_bold); // bold display
Font2.setfontheightinpoints (short) 12 );
Setborder. setfont (font); // select the font format
5. Set the column width:
Sheet. setcolumnwidth (0, 3766); // The first parameter indicates the column ID (starting from 0). The first parameter indicates the width value. For details, refer to "2012-08-10". The width is 2nd.
6. Set automatic line feed:
Setborder. setwraptext (true); // set automatic line feed
7. Merge cells:
Region region1 = new region (0, (short) 0, 0, (short) 6 );
// Parameter 1: row number parameter 2: Start column Number Parameter 3: row number parameter 4: End column number
Or use
Cellrangeaddress region1 = new cellrangeaddress (rownumber, rownumber, (short) 0, (short) 11 );
However, you should note that the parameters of the two constructor methods are not the same. The specific version of POI depends on which one is used.
Sheet. addmergedregion (region1 );
There are so many currently used products that will be added later.