Setting value to cells after merging in POI

前端 未结 1 708
栀梦
栀梦 2020-12-30 17:25

I want to form a excel output as below in POI:

\"enter

As clear from the image

相关标签:
1条回答
  • 2020-12-30 18:16

    in reality I did not understand your problem completely, but I have some key points, that I think, will be helpful to you.

    1. The first Cell of merged region keeps the value of the merged cell, rest cells keep blank value. Means if cell A2 to A5 is merged with value "Test" then on iteration A2 will show "Test" while rest will show blank. SO if you want to read the merged cell value, you need to read its first cell only, and similarly if you want to write in the merged cells, you just need to write in first cell only.

    2. sheet.getNumMergedRegions(); return integer that will be the total number of merged region in the sheet. you can iterate through it using loop as well.

    3. CellRangeAddress merge = sheet.getMergedRegion(int index); will give you the range address of the specified index obtained from getNumMergedRegions()

    4. now merge.getFirstRow(),merge.getLastRow(), merge.getFirstColumn(), merge.getLastColumn(), merge.getNumberOfCells(), are the methods for the same.

    The iteration through row containing merged cells and row not containing any merged cell are not much different. Hope this will help you to resolve your problem.

    0 讨论(0)
提交回复
热议问题