You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2015/04/20 22:13:33 UTC
svn commit: r1674975 - in /poi/trunk:
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
test-data/spreadsheet/57828.xlsx
Author: centic
Date: Mon Apr 20 20:13:33 2015
New Revision: 1674975
URL: http://svn.apache.org/r1674975
Log:
Fix bug 57828, shifting more than one commit per row did not work.
Added:
poi/trunk/test-data/spreadsheet/57828.xlsx
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1674975&r1=1674974&r2=1674975&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Mon Apr 20 20:13:33 2015
@@ -2596,11 +2596,13 @@ public class XSSFSheet extends POIXMLDoc
// i.e. when shifting down, start from down and go up, when shifting up, vice-versa
SortedMap<XSSFComment, Integer> commentsToShift = new TreeMap<XSSFComment, Integer>(new Comparator<XSSFComment>() {
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
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java?rev=1674975&r1=1674974&r2=1674975&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java Mon Apr 20 20:13:33 2015
@@ -332,4 +332,38 @@ public final class TestXSSFSheetShiftRow
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();
+ }
}
Added: poi/trunk/test-data/spreadsheet/57828.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/57828.xlsx?rev=1674975&view=auto
==============================================================================
Binary files poi/trunk/test-data/spreadsheet/57828.xlsx (added) and poi/trunk/test-data/spreadsheet/57828.xlsx Mon Apr 20 20:13:33 2015 differ
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org