From d1385bbe1bea4f5882206d6e3f11710b8c7203da Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 20 Apr 2015 20:13:33 +0000 Subject: [PATCH] Fix bug 57828, shifting more than one commit per row did not work. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1674975 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/usermodel/XSSFSheet.java | 8 +++-- .../usermodel/TestXSSFSheetShiftRows.java | 34 ++++++++++++++++++ test-data/spreadsheet/57828.xlsx | Bin 0 -> 9708 bytes 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test-data/spreadsheet/57828.xlsx diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index f24a33194..189922ad4 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -2596,11 +2596,13 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { // i.e. when shifting down, start from down and go up, when shifting up, vice-versa SortedMap commentsToShift = new TreeMap(new Comparator() { public int compare(XSSFComment o1, XSSFComment o2) { - int row1 = new CellReference(o1.getCTComment().getRef()).getRow(); - int row2 = new CellReference(o2.getCTComment().getRef()).getRow(); + int row1 = o1.getRow(); + int row2 = o2.getRow(); if(row1 == row2) { - return 0; + // ordering is not important when row is equal, but don't return zero to still + // get multiple comments per row into the map + return o1.hashCode() - o2.hashCode(); } // when shifting down, sort higher row-values first diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java index e915ee0d4..89364463b 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java @@ -332,4 +332,38 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows { wb.removeSheetAt(sn); } } + + public void testBug57828_OnlyOneCommentShiftedInRow() throws IOException { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57828.xlsx"); + XSSFSheet sheet = wb.getSheetAt(0); + + Comment comment1 = sheet.getCellComment(2, 1); + assertNotNull(comment1); + + Comment comment2 = sheet.getCellComment(2, 2); + assertNotNull(comment2); + + Comment comment3 = sheet.getCellComment(1, 1); + assertNull("NO comment in (1,1) and it should be null", comment3); + + sheet.shiftRows(2, 2, -1); + + comment3 = sheet.getCellComment(1, 1); + assertNotNull("Comment in (2,1) moved to (1,1) so its not null now.", comment3); + + comment1 = sheet.getCellComment(2, 1); + assertNull("No comment currently in (2,1) and hence it is null", comment1); + + comment2 = sheet.getCellComment(1, 2); + assertNotNull("Comment in (2,2) should have moved as well because of shift rows. But its not", comment2); + +// OutputStream stream = new FileOutputStream("/tmp/57828.xlsx"); +// try { +// wb.write(stream); +// } finally { +// stream.close(); +// } + + wb.close(); + } } diff --git a/test-data/spreadsheet/57828.xlsx b/test-data/spreadsheet/57828.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..c750a094428176b89fbe03f7f9d21675d2d973e9 GIT binary patch literal 9708 zcmeHN^;;aP&TeExRpTg#5=u|L zN~|7QwZ7`bJrP$JA;RDn1XRtOoS9b%X}1Mcaj%shEeJbCOCiV`nKN59GDN9$jFss* zGKJS_!+au-BJ(h=LE2R#XPN|9h=X(LlG8#R=XA!ODC@B;);YPb~#m zf{shx++yWc`-{Q)(`1hAay_ufV_hV16NDv=gf33Cyvd?&mxCUol|v#dX6kW5e@_<= zUHYX%NJ|j%m_*p!FaUG@40*Ok9|h^CQ*bu29pR>XZ{#`Aqci+avP+bY5m`R*!JGtr zK++puWI8nDnGzZbht`m4l$zbE)VOb}TO|?)Y$#R1=`x=(eBc0p`+GQm%3tEOR)d}D z1WH0hXgH!l56}GCedor@p#1T!;Ockk7m*on^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