You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/11/17 18:41:16 UTC
svn commit: r1895113 - in /poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf: model/CommentsTable.java usermodel/XSSFSheet.java
Author: fanningpj
Date: Wed Nov 17 18:41:16 2021
New Revision: 1895113
URL: http://svn.apache.org/viewvc?rev=1895113&view=rev
Log:
try to make comments table more extensible
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java?rev=1895113&r1=1895112&r2=1895113&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java Wed Nov 17 18:41:16 2021
@@ -164,6 +164,25 @@ public class CommentsTable extends POIXM
CTComment ct = getCTComment(cellAddress);
return ct == null ? null : new XSSFComment(this, ct, null);
}
+
+ /**
+ * Finds the cell comment at cellAddress, if one exists
+ *
+ * @param sheet the sheet that has the comment
+ * @param cellAddress the address of the cell to find a comment
+ * @return cell comment if one exists, otherwise returns null
+ * @since POI 5.2.0
+ */
+ public XSSFComment findCellComment(XSSFSheet sheet, CellAddress cellAddress) {
+ CTComment ctComment = getCTComment(cellAddress);
+ if(ctComment == null) {
+ return null;
+ }
+
+ XSSFVMLDrawing vml = sheet.getVMLDrawing(false);
+ return new XSSFComment(this, ctComment,
+ vml == null ? null : vml.findCommentShape(cellAddress.getRow(), cellAddress.getColumn()));
+ }
/**
* Get the underlying CTComment xmlbean for a comment located at cellRef, if it exists
@@ -221,21 +240,6 @@ public class CommentsTable extends POIXM
return new XSSFComment(this, newComment(ref), vmlShape);
}
-
- /**
- * Refresh Map<CellAddress, CTComment> commentRefs cache,
- * Calls that use the commentRefs cache will perform in O(1)
- * time rather than O(n) lookup time for List<CTComment> comments.
- */
- private void prepareCTCommentCache() {
- // Create the cache if needed
- if(commentRefs == null) {
- commentRefs = new HashMap<>();
- for (CTComment comment : comments.getCommentList().getCommentArray()) {
- commentRefs.put(new CellAddress(comment.getRef()), comment);
- }
- }
- }
/**
* Create a new comment located at cell address
@@ -304,4 +308,19 @@ public class CommentsTable extends POIXM
public CTComments getCTComments(){
return comments;
}
+
+ /**
+ * Refresh Map<CellAddress, CTComment> commentRefs cache,
+ * Calls that use the commentRefs cache will perform in O(1)
+ * time rather than O(n) lookup time for List<CTComment> comments.
+ */
+ private void prepareCTCommentCache() {
+ // Create the cache if needed
+ if(commentRefs == null) {
+ commentRefs = new HashMap<>();
+ for (CTComment comment : comments.getCommentList().getCommentArray()) {
+ commentRefs.put(new CellAddress(comment.getRef()), comment);
+ }
+ }
+ }
}
Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1895113&r1=1895112&r2=1895113&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Wed Nov 17 18:41:16 2021
@@ -774,14 +774,7 @@ public class XSSFSheet extends POIXMLDoc
return null;
}
- CTComment ctComment = sheetComments.getCTComment(address);
- if(ctComment == null) {
- return null;
- }
-
- XSSFVMLDrawing vml = getVMLDrawing(false);
- return new XSSFComment(sheetComments, ctComment,
- vml == null ? null : vml.findCommentShape(address.getRow(), address.getColumn()));
+ return sheetComments.findCellComment(this, address);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org