import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_SPREADSHEETML;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
*/
public XSSFSheetXMLHandler(
Styles styles,
- CommentsTable comments,
+ Comments comments,
SharedStrings strings,
SheetContentsHandler sheetContentsHandler,
DataFormatter dataFormatter,
this(styles, strings, sheetContentsHandler, new DataFormatter(), formulasNotResults);
}
- private void init(CommentsTable commentsTable) {
+ private void init(Comments commentsTable) {
if (commentsTable != null) {
commentCellRefs = new LinkedList<>();
- for (CellAddress cellAddress : commentsTable.getCellComments().keySet()) {
- commentCellRefs.add(cellAddress);
+ for (Iterator<CellAddress> iter = commentsTable.getCellAddresses(); iter.hasNext(); ) {
+ commentCellRefs.add(iter.next());
}
}
}
public void processSheet(
SheetContentsHandler sheetContentsExtractor,
Styles styles,
- CommentsTable comments,
+ Comments comments,
SharedStrings strings,
InputStream sheetInputStream)
throws IOException, SAXException {
text.append(iter.getSheetName());
text.append('\n');
}
- CommentsTable comments = includeCellComments ? iter.getSheetComments() : null;
+ Comments comments = includeCellComments ? iter.getSheetComments() : null;
processSheet(sheetExtractor, styles, comments, strings, stream);
if (includeHeadersFooters) {
sheetExtractor.appendHeaderText(text);
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.xssf.usermodel.XSSFComment;
+import java.util.Iterator;
+
/**
* An interface exposing useful functions for dealing with Excel Workbook Comments.
* It is intended that this interface should support low level access and not expose
* @return returns true if a comment was removed
*/
boolean removeComment(CellAddress cellRef);
+
+ /**
+ * Returns all cell addresses that have comments.
+ * @return An iterator to traverse all cell addresses that have comments.
+ * @since 4.0.0
+ */
+ Iterator<CellAddress> getCellAddresses();
}
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Removal;
import org.apache.poi.xssf.usermodel.XSSFComment;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
// Return the comment, or null if not known
return commentRefs.get(cellRef);
}
-
+
+ /**
+ * Returns all cell addresses that have comments.
+ * @return An iterator to traverse all cell addresses that have comments.
+ * @since 4.0.0
+ */
+ @Override
+ public Iterator<CellAddress> getCellAddresses() {
+ prepareCTCommentCache();
+ return commentRefs.keySet().iterator();
+ }
+
/**
* Returns all cell comments on this sheet.
* @return A map of each Comment in this sheet, keyed on the cell address where
* the comment is located.
+ * @deprecated use <code>getCellAddresses</code> instead
*/
+ @Removal(version = "4.2")
+ @Deprecated
public Map<CellAddress, XSSFComment> getCellComments() {
prepareCTCommentCache();
final TreeMap<CellAddress, XSSFComment> map = new TreeMap<>();
- for (final Entry<CellAddress, CTComment> e: commentRefs.entrySet()) {
+ for (final Entry<CellAddress, CTComment> e : commentRefs.entrySet()) {
map.put(e.getKey(), new XSSFComment(this, e.getValue(), null));
}
}
// the cell comments in sheetComments.getCellComments() do not have the client anchors set
Map<CellAddress, XSSFComment> map = new HashMap<>();
- for(CellAddress address : sheetComments.getCellComments().keySet()) {
+ for(Iterator<CellAddress> iter = sheetComments.getCellAddresses(); iter.hasNext(); ) {
+ CellAddress address = iter.next();
map.put(address, getCellComment(address));
}
return map;