Reprint: Poi set Excel table border, font, etc.

Source: Internet
Author: User
Tags set background

Reprinted from: http://z3sm2012.iteye.com/blog/1446669

Some summary of operations that need to format Excel cells may be used in POI:

Get the Workbook object first:

Hssfworkbook wb = new Hssfworkbook ();

Hssfsheet sheet = Wb.createsheet ();

Hssfcellstyle SetBorder = Wb.createcellstyle ();

First, set the background color:

Setborder.setfillforegroundcolor ((short) 13);//Set Background color
Setborder.setfillpattern (Hssfcellstyle.solid_foreground);

Second, set the border:

Setborder.setborderbottom (Hssfcellstyle.border_thin); Bottom Frame
Setborder.setborderleft (Hssfcellstyle.border_thin);//left Border
Setborder.setbordertop (Hssfcellstyle.border_thin);//Top Border
Setborder.setborderright (Hssfcellstyle.border_thin);//Right Border

Third, set the center:

Setborder.setalignment (Hssfcellstyle.align_center); Center

Four, set the font:

Hssffont font = Wb.createfont ();
Font.setfontname ("Blackbody");
Font.setfontheightinpoints ((short) 16);//Set Font size

Hssffont Font2 = Wb.createfont ();
Font2.setfontname ("Imitation _gb2312");
Font2.setboldweight (hssffont.boldweight_bold);//Bold display
Font2.setfontheightinpoints ((short) 12);

Setborder.setfont (font);//Select the font format you want to use

Five, set the column width:

Sheet.setcolumnwidth (0, 3766); The first parameter represents the column ID (starting at 0), and the 2nd parameter represents the Width value

Six, set the automatic line wrapping:

Setborder.setwraptext (TRUE);//Set line wrapping

Seven, merge the cells:

Region Region1 = new Region (0, (short) 0, 0, (short) 6);

Parameter 1: line number parameter 2: Starting column number parameter 3: line number parameter 4: terminating column number

or with

Cellrangeaddress Region1 = new Cellrangeaddress (RowNumber, RowNumber, (short) 0, (short) 11);

However, it should be noted that the parameters of the two constructor methods are not the same, depending on the different versions of the POI.
Sheet.addmergedregion (Region1);

So much has been used so far, and new additions will continue to follow.

Reprint: Poi set Excel table border, font, etc.

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.