From 9337603b1b849dac6d0eb5aef027aa7861db90af Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Mon, 23 Nov 2015 12:47:24 +0000 Subject: [PATCH] bug 58365: patch from Hannes Erven. Update XSSFSheetXMLHandler.java to use CellAddress instead of CellReference/String git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1715794 13f79535-47bb-0310-9956-ffa450edef68 --- .../eventusermodel/XSSFSheetXMLHandler.java | 37 ++++++------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java index 227441859e..39a852eb79 100644 --- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java +++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java @@ -22,6 +22,7 @@ import java.util.Queue; import org.apache.poi.ss.usermodel.BuiltinFormats; import org.apache.poi.ss.usermodel.DataFormatter; +import org.apache.poi.ss.util.CellAddress; import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -105,7 +106,7 @@ public class XSSFSheetXMLHandler extends DefaultHandler { private StringBuffer formula = new StringBuffer(); private StringBuffer headerFooter = new StringBuffer(); - private Queue commentCellRefs; + private Queue commentCellRefs; /** * Accepts objects needed while parsing. @@ -162,9 +163,9 @@ public class XSSFSheetXMLHandler extends DefaultHandler { @SuppressWarnings("deprecation") private void init() { if (commentsTable != null) { - commentCellRefs = new LinkedList(); + commentCellRefs = new LinkedList(); for (CTComment comment : commentsTable.getCTComments().getCommentList().getCommentArray()) { - commentCellRefs.add(new CellReference(comment.getRef())); + commentCellRefs.add(new CellAddress(comment.getRef())); } } } @@ -362,7 +363,7 @@ public class XSSFSheetXMLHandler extends DefaultHandler { // Do we have a comment for this cell? checkForEmptyCellComments(EmptyCellCommentsCheckType.CELL); - XSSFComment comment = commentsTable != null ? commentsTable.findCellComment(cellRef) : null; + XSSFComment comment = commentsTable != null ? commentsTable.findCellComment(new CellAddress(cellRef)) : null; // Output output.cell(cellRef, thisStr, comment); @@ -443,17 +444,17 @@ public class XSSFSheetXMLHandler extends DefaultHandler { } } - CellReference nextCommentCellRef; + CellAddress nextCommentCellRef; do { - CellReference cellRef = new CellReference(this.cellRef); - CellReference peekCellRef = commentCellRefs.peek(); + CellAddress cellRef = new CellAddress(this.cellRef); + CellAddress peekCellRef = commentCellRefs.peek(); if (type == EmptyCellCommentsCheckType.CELL && cellRef.equals(peekCellRef)) { // remove the comment cell ref from the list if we're about to handle it alongside the cell content commentCellRefs.remove(); return; } else { // fill in any gaps if there are empty cells with comment mixed in with non-empty cells - int comparison = cellRefComparator.compare(peekCellRef, cellRef); + int comparison = peekCellRef.compareTo(cellRef); if (comparison > 0 && type == EmptyCellCommentsCheckType.END_OF_ROW && peekCellRef.getRow() <= rowNum) { nextCommentCellRef = commentCellRefs.remove(); outputEmptyCellComment(nextCommentCellRef); @@ -472,10 +473,9 @@ public class XSSFSheetXMLHandler extends DefaultHandler { /** * Output an empty-cell comment. */ - private void outputEmptyCellComment(CellReference cellRef) { - String cellRefString = cellRef.formatAsString(); - XSSFComment comment = commentsTable.findCellComment(cellRefString); - output.cell(cellRefString, null, comment); + private void outputEmptyCellComment(CellAddress cellRef) { + XSSFComment comment = commentsTable.findCellComment(cellRef); + output.cell(cellRef.formatAsString(), null, comment); } private enum EmptyCellCommentsCheckType { @@ -483,19 +483,6 @@ public class XSSFSheetXMLHandler extends DefaultHandler { END_OF_ROW, END_OF_SHEET_DATA } - private static final Comparator cellRefComparator = new Comparator() { - @Override - public int compare(CellReference o1, CellReference o2) { - int result = compare(o1.getRow(), o2.getRow()); - if (result == 0) { - result = compare(o1.getCol(), o2.getCol()); - } - return result; - } - public int compare(int x, int y) { - return (x < y) ? -1 : ((x == y) ? 0 : 1); - } - }; /** * You need to implement this to handle the results -- 2.39.5