bengbengbalabalabeng commented on issue #303:
URL: https://github.com/apache/fesod/issues/303#issuecomment-4207095201
`OnceAbsoluteMergeStrategy` is not suitable for Fill (`shiftRows` logic)
scenarios. The strategy itself does not handle conflicts in the merged area
after row displacement. Please refer to the JavaDoc description of
`org.apache.poi.ss.usermodel.Sheet#shiftRows(int, int, int, boolean, boolean)`:
```java
/**
* Shifts rows between startRow and endRow n number of rows.
* If you use a negative number, it will shift rows up.
* Code ensures that rows don't wrap around
*
* <p>
* Additionally shifts merged regions that are completely defined in
these
* rows (ie. merged 2 cells on a row to be shifted). All merged regions
that are
* completely overlaid by shifting will be deleted.
*/
void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight,
boolean resetOriginalRowHeight);
```
---
**Solution**
Please try the customized `SheetWriteHandler` interface and override the
`afterSheetDispose` method.
Version: 2.0.1-incubating
```java
public class CustomMergeStrategy implements SheetWriteHandler {
private final int firstRowIndex;
private final int lastRowIndex;
private final int firstColumnIndex;
private final int lastColumnIndex;
public CustomMergeStrategy(int firstRowIndex, int lastRowIndex, int
firstColumnIndex, int lastColumnIndex) {
if (firstRowIndex >= 0 && lastRowIndex >= 0 && firstColumnIndex >= 0
&& lastColumnIndex >= 0) {
this.firstRowIndex = firstRowIndex;
this.lastRowIndex = lastRowIndex;
this.firstColumnIndex = firstColumnIndex;
this.lastColumnIndex = lastColumnIndex;
} else {
throw new IllegalArgumentException("All parameters must be
greater than 0");
}
}
@Override
public void afterSheetDispose(SheetWriteHandlerContext context) {
CellRangeAddress cellRangeAddress = new
CellRangeAddress(this.firstRowIndex, this.lastRowIndex, this.firstColumnIndex,
this.lastColumnIndex);
context.getWriteSheetHolder().getSheet().addMergedRegionUnsafe(cellRangeAddress);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]