diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 0dee5466ae..3fdd8c1b9a 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -3044,7 +3044,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx public void shiftRows(int startRow, int endRow, final int n, boolean copyRowHeight, boolean resetOriginalRowHeight) { List overlappingTables = new ArrayList<>(); for (XSSFTable table : getTables()) { - if (table.getStartRowIndex() <= endRow || table.getEndRowIndex() >= startRow) { + if ((table.getStartRowIndex() < startRow && table.getEndRowIndex() < startRow) + || (table.getStartRowIndex() > endRow && table.getEndRowIndex() > endRow)) { + // not overlapping + } else { overlappingTables.add(table); } } @@ -3082,7 +3085,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx public void shiftColumns(int startColumn, int endColumn, final int n) { List overlappingTables = new ArrayList<>(); for (XSSFTable table : getTables()) { - if (table.getStartColIndex() <= endColumn || table.getEndRowIndex() >= startColumn) { + if ((table.getStartColIndex() < startColumn && table.getEndColIndex() < startColumn) + || (table.getStartColIndex() > endColumn && table.getEndColIndex() > endColumn)) { + // not overlapping + } else { overlappingTables.add(table); } }