mirror of https://github.com/apache/poi.git
bug 61474, github #81: fix ColumnShifter#removalNeeded to use columns instead of rows
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1814257 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6ceee17033
commit
9f03e0bc08
|
@ -49,6 +49,7 @@ public abstract class ColumnShifter extends BaseRowColShifter {
|
||||||
* @param n the number of columns to shift
|
* @param n the number of columns to shift
|
||||||
* @return an array of affected merged regions, doesn't contain deleted ones
|
* @return an array of affected merged regions, doesn't contain deleted ones
|
||||||
*/
|
*/
|
||||||
|
// Keep this code in sync with {@link RowShifter#shiftMergedRegions}
|
||||||
public List<CellRangeAddress> shiftMergedRegions(int startColumn, int endColumn, int n) {
|
public List<CellRangeAddress> shiftMergedRegions(int startColumn, int endColumn, int n) {
|
||||||
List<CellRangeAddress> shiftedRegions = new ArrayList<>();
|
List<CellRangeAddress> shiftedRegions = new ArrayList<>();
|
||||||
Set<Integer> removedIndices = new HashSet<>();
|
Set<Integer> removedIndices = new HashSet<>();
|
||||||
|
@ -93,6 +94,7 @@ public abstract class ColumnShifter extends BaseRowColShifter {
|
||||||
return shiftedRegions;
|
return shiftedRegions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep in sync with {@link RowShifter#removalNeeded}
|
||||||
private boolean removalNeeded(CellRangeAddress merged, int startColumn, int endColumn, int n) {
|
private boolean removalNeeded(CellRangeAddress merged, int startColumn, int endColumn, int n) {
|
||||||
final int movedColumns = endColumn - startColumn + 1;
|
final int movedColumns = endColumn - startColumn + 1;
|
||||||
|
|
||||||
|
@ -101,10 +103,14 @@ public abstract class ColumnShifter extends BaseRowColShifter {
|
||||||
final CellRangeAddress overwrite;
|
final CellRangeAddress overwrite;
|
||||||
if(n > 0) {
|
if(n > 0) {
|
||||||
// area is moved down => overwritten area is [endColumn + n - movedColumns, endColumn + n]
|
// area is moved down => overwritten area is [endColumn + n - movedColumns, endColumn + n]
|
||||||
overwrite = new CellRangeAddress(Math.max(endColumn + 1, endColumn + n - movedColumns), endColumn + n, 0, 0);
|
final int firstCol = Math.max(endColumn + 1, endColumn + n - movedColumns);
|
||||||
|
final int lastCol = endColumn + n;
|
||||||
|
overwrite = new CellRangeAddress(0, 0, firstCol, lastCol);
|
||||||
} else {
|
} else {
|
||||||
// area is moved up => overwritten area is [startColumn + n, startColumn + n + movedColumns]
|
// area is moved up => overwritten area is [startColumn + n, startColumn + n + movedColumns]
|
||||||
overwrite = new CellRangeAddress(startColumn + n, Math.min(startColumn - 1, startColumn + n + movedColumns), 0, 0);
|
final int firstCol = startColumn + n;
|
||||||
|
final int lastCol = Math.min(startColumn - 1, startColumn + n + movedColumns);
|
||||||
|
overwrite = new CellRangeAddress(0, 0, firstCol, lastCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the merged-region and the overwritten area intersect, we need to remove it
|
// if the merged-region and the overwritten area intersect, we need to remove it
|
||||||
|
|
|
@ -51,6 +51,7 @@ public abstract class RowShifter extends BaseRowColShifter {
|
||||||
* @param n the number of rows to shift
|
* @param n the number of rows to shift
|
||||||
* @return an array of affected merged regions, doesn't contain deleted ones
|
* @return an array of affected merged regions, doesn't contain deleted ones
|
||||||
*/
|
*/
|
||||||
|
// Keep this code in sync with {@link ColumnShifter#shiftMergedRegions}
|
||||||
public List<CellRangeAddress> shiftMergedRegions(int startRow, int endRow, int n) {
|
public List<CellRangeAddress> shiftMergedRegions(int startRow, int endRow, int n) {
|
||||||
List<CellRangeAddress> shiftedRegions = new ArrayList<>();
|
List<CellRangeAddress> shiftedRegions = new ArrayList<>();
|
||||||
Set<Integer> removedIndices = new HashSet<>();
|
Set<Integer> removedIndices = new HashSet<>();
|
||||||
|
@ -95,6 +96,7 @@ public abstract class RowShifter extends BaseRowColShifter {
|
||||||
return shiftedRegions;
|
return shiftedRegions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep in sync with {@link ColumnShifter#removalNeeded}
|
||||||
private boolean removalNeeded(CellRangeAddress merged, int startRow, int endRow, int n) {
|
private boolean removalNeeded(CellRangeAddress merged, int startRow, int endRow, int n) {
|
||||||
final int movedRows = endRow - startRow + 1;
|
final int movedRows = endRow - startRow + 1;
|
||||||
|
|
||||||
|
@ -103,10 +105,14 @@ public abstract class RowShifter extends BaseRowColShifter {
|
||||||
final CellRangeAddress overwrite;
|
final CellRangeAddress overwrite;
|
||||||
if(n > 0) {
|
if(n > 0) {
|
||||||
// area is moved down => overwritten area is [endRow + n - movedRows, endRow + n]
|
// area is moved down => overwritten area is [endRow + n - movedRows, endRow + n]
|
||||||
overwrite = new CellRangeAddress(Math.max(endRow + 1, endRow + n - movedRows), endRow + n, 0, 0);
|
final int firstRow = Math.max(endRow + 1, endRow + n - movedRows);
|
||||||
|
final int lastRow = endRow + n;
|
||||||
|
overwrite = new CellRangeAddress(firstRow, lastRow, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
// area is moved up => overwritten area is [startRow + n, startRow + n + movedRows]
|
// area is moved up => overwritten area is [startRow + n, startRow + n + movedRows]
|
||||||
overwrite = new CellRangeAddress(startRow + n, Math.min(startRow - 1, startRow + n + movedRows), 0, 0);
|
final int firstRow = startRow + n;
|
||||||
|
final int lastRow = Math.min(startRow - 1, startRow + n + movedRows);
|
||||||
|
overwrite = new CellRangeAddress(firstRow, lastRow, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the merged-region and the overwritten area intersect, we need to remove it
|
// if the merged-region and the overwritten area intersect, we need to remove it
|
||||||
|
|
Loading…
Reference in New Issue