Apache POI Merge Cell--Simple explanation version with demo

Source: Internet
Author: User

Methods used to merge cells:

Sheet.addmergedregion (cellrangeaddress cellrangeaddress); The method of constructing a Cellrangeaddress object requires passing in the first row, last row, first column, and last column of the merged cell. Cellrangeaddress cra=new cellrangeaddress (0, 3, 3, 9); How to write data to a merged cell
    1. The first thing to look at is the Firstcol index of your cellrangeaddress construction method
    2. Creating a Firstcol Cell object
    3. The set method of the cell writes the data
Write data in the next position of a merged cell
    1. View Lastcol Index of the Cellrangeaddress construction method
    2. Create Lastcol+1 cell
    3. The set method of the cell writes the data

Here is the demo:

1FileOutputStream fos=NewFileOutputStream ("D:\\13.xls"); 2           3Workbook wb=NewHssfworkbook (); 4           5Sheet sheet=Wb.createsheet (); 6         /* 7 * Set the range of merged cell ranges8 * FirstRow 0-based9 * LastRow 0-basedTen * Firstcol 0-based One * Lastcol 0-based A          */   -Cellrangeaddress cra=NewCellrangeaddress (0, 3, 3, 9);  -            the         //add merged cells in sheet - sheet.addmergedregion (CRA);  -            -Row row = Sheet.createrow (0);  +            -Cell Cell_1 = Row.createcell (3);  +            ACell_1.setcellvalue ("When you ' re right, no one remembers, when you ' re wrong, no one forgets.");  at            -         //cell position 3-9 is merged into a single cell, no matter how you create a 4th cell or a 5th cell ... Then write the data.  are not writable.  -Cell cell_2 = Row.createcell (10);  -            -Cell_2.setcellvalue ("What's Up!"));  -            in wb.write (FOS);  -            toFos.close ();

Apache POI Merge Cell--Simple explanation version with demo

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.