Merging cells in Excel using Apache POI

Merging cells in Excel using Apache POI

Asked on January 8, 2019 in Excel.
Add Comment


  • 3 Answer(s)

    Try this following solution :

        Use this sheet.addMergedRegion(rowFrom,rowTo,colFrom,colTo);

    For example sheet.addMergedRegion(new CellRangeAddress(1,1,1,4)); will be joining from B2 to E2. Extract it is based on based indexing, example. POI version 3.12.

    For more information, use it BusyDeveloper’s Guide

    Answered on January 8, 2019.
    Add Comment

    The alternative solution to merging cells in Excel using Apache POI :

    sheet.addMergedRegion(new CellRangeAddress(start-col,end-col,start-cell,end-cell));
    
    Answered on January 8, 2019.
    Add Comment

    Try this explanation :

    sheet.addMergedRegion(new CellRangeAddress(startRowIndx, endRowIndx, startColIndx,endColIndx));
    

    Note  the Cell Range Address does not go along with other mingle regions as that will throw an exception.

    • Maintain column indexes same when need to mingle cells one above another.
    • Maintain the row indexes same when need to mingle cells that are in a single row.
    • Indexes are based on zero.

    Use this code :

    sheet.addMergedRegion(new CellRangeAddress(rowNo, rowNo, 0, 3));
    
    Answered on January 8, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.