Merging cells in Excel using Apache POI

前端 未结 5 834
醉话见心
醉话见心 2020-12-02 16:49

Is there any other way to merge cells in Excel using Apache POI library?

I was trying using the following, but its not working

// selecting the regio         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 17:21

    You can use :

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

    Make sure the CellRangeAddress does not coincide with other merged regions as that will throw an exception.

    • If you want to merge cells one above another, keep column indexes same
    • If you want to merge cells which are in a single row, keep the row indexes same
    • Indexes are zero based

    For what you were trying to do this should work:

    sheet.addMergedRegion(new CellRangeAddress(rowNo, rowNo, 0, 3));
    

提交回复
热议问题