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:
parent
831fa71953
commit
a77dd2777b
@ -22,6 +22,7 @@ import java.util.Queue;
|
|||||||
|
|
||||||
import org.apache.poi.ss.usermodel.BuiltinFormats;
|
import org.apache.poi.ss.usermodel.BuiltinFormats;
|
||||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
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.ss.util.CellReference;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
@ -105,7 +106,7 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
|
|||||||
private StringBuffer formula = new StringBuffer();
|
private StringBuffer formula = new StringBuffer();
|
||||||
private StringBuffer headerFooter = new StringBuffer();
|
private StringBuffer headerFooter = new StringBuffer();
|
||||||
|
|
||||||
private Queue<CellReference> commentCellRefs;
|
private Queue<CellAddress> commentCellRefs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accepts objects needed while parsing.
|
* Accepts objects needed while parsing.
|
||||||
@ -162,9 +163,9 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private void init() {
|
private void init() {
|
||||||
if (commentsTable != null) {
|
if (commentsTable != null) {
|
||||||
commentCellRefs = new LinkedList<CellReference>();
|
commentCellRefs = new LinkedList<CellAddress>();
|
||||||
for (CTComment comment : commentsTable.getCTComments().getCommentList().getCommentArray()) {
|
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?
|
// Do we have a comment for this cell?
|
||||||
checkForEmptyCellComments(EmptyCellCommentsCheckType.CELL);
|
checkForEmptyCellComments(EmptyCellCommentsCheckType.CELL);
|
||||||
XSSFComment comment = commentsTable != null ? commentsTable.findCellComment(cellRef) : null;
|
XSSFComment comment = commentsTable != null ? commentsTable.findCellComment(new CellAddress(cellRef)) : null;
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
output.cell(cellRef, thisStr, comment);
|
output.cell(cellRef, thisStr, comment);
|
||||||
@ -443,17 +444,17 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CellReference nextCommentCellRef;
|
CellAddress nextCommentCellRef;
|
||||||
do {
|
do {
|
||||||
CellReference cellRef = new CellReference(this.cellRef);
|
CellAddress cellRef = new CellAddress(this.cellRef);
|
||||||
CellReference peekCellRef = commentCellRefs.peek();
|
CellAddress peekCellRef = commentCellRefs.peek();
|
||||||
if (type == EmptyCellCommentsCheckType.CELL && cellRef.equals(peekCellRef)) {
|
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
|
// remove the comment cell ref from the list if we're about to handle it alongside the cell content
|
||||||
commentCellRefs.remove();
|
commentCellRefs.remove();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// fill in any gaps if there are empty cells with comment mixed in with non-empty cells
|
// 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) {
|
if (comparison > 0 && type == EmptyCellCommentsCheckType.END_OF_ROW && peekCellRef.getRow() <= rowNum) {
|
||||||
nextCommentCellRef = commentCellRefs.remove();
|
nextCommentCellRef = commentCellRefs.remove();
|
||||||
outputEmptyCellComment(nextCommentCellRef);
|
outputEmptyCellComment(nextCommentCellRef);
|
||||||
@ -472,10 +473,9 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
|
|||||||
/**
|
/**
|
||||||
* Output an empty-cell comment.
|
* Output an empty-cell comment.
|
||||||
*/
|
*/
|
||||||
private void outputEmptyCellComment(CellReference cellRef) {
|
private void outputEmptyCellComment(CellAddress cellRef) {
|
||||||
String cellRefString = cellRef.formatAsString();
|
XSSFComment comment = commentsTable.findCellComment(cellRef);
|
||||||
XSSFComment comment = commentsTable.findCellComment(cellRefString);
|
output.cell(cellRef.formatAsString(), null, comment);
|
||||||
output.cell(cellRefString, null, comment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum EmptyCellCommentsCheckType {
|
private enum EmptyCellCommentsCheckType {
|
||||||
@ -483,19 +483,6 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
|
|||||||
END_OF_ROW,
|
END_OF_ROW,
|
||||||
END_OF_SHEET_DATA
|
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
|
* You need to implement this to handle the results
|
||||||
|
Loading…
Reference in New Issue
Block a user