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
This commit is contained in:
Javen O'Neal 2015-11-23 12:47:24 +00:00
parent 788050c1bd
commit 9337603b1b
1 changed files with 12 additions and 25 deletions

View File

@ -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<CellReference> commentCellRefs;
private Queue<CellAddress> 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<CellReference>();
commentCellRefs = new LinkedList<CellAddress>();
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<CellReference> cellRefComparator = new Comparator<CellReference>() {
@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