*/
XSSFComment findCellComment(CellAddress cellAddress);
+ /**
+ * 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);
+
/**
* Remove the comment at cellRef location, if one exists
*
* @return cell comment if one exists, otherwise returns null
* @since POI 5.2.0
*/
+ @Override
public XSSFComment findCellComment(XSSFSheet sheet, CellAddress cellAddress) {
CTComment ctComment = getCTComment(cellAddress);
if(ctComment == null) {
import org.apache.poi.ss.util.ImageUtils;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
-import org.apache.poi.xssf.model.CommentsTable;
+import org.apache.poi.xssf.model.Comments;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
XSSFClientAnchor ca = (XSSFClientAnchor) anchor;
XSSFSheet sheet = getSheet();
- CommentsTable comments = sheet.getCommentsTable(true);
+ Comments comments = sheet.getCommentsTable(true);
return comments.createNewComment(getSheet(), ca);
}
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
+import org.apache.poi.xssf.model.Comments;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.usermodel.XSSFPivotTable.PivotTableReferenceConfigurator;
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
private final SortedMap<Integer, XSSFRow> _rows = new TreeMap<>();
private List<XSSFHyperlink> hyperlinks;
private ColumnHelper columnHelper;
- private CommentsTable sheetComments;
+ private Comments sheetComments;
/**
* cache of master shared formulas in this sheet.
* Master shared formula is the first formula in a group of shared formulas is saved in the f element.
// Look for bits we're interested in
for(RelationPart rp : getRelationParts()){
POIXMLDocumentPart p = rp.getDocumentPart();
- if(p instanceof CommentsTable) {
- sheetComments = (CommentsTable)p;
+ if(p instanceof Comments) {
+ sheetComments = (Comments)p;
}
if(p instanceof XSSFTable) {
tables.put( rp.getRelationship().getId(), (XSSFTable)p );
*
* @param create create a new comments table if it does not exist
*/
- protected CommentsTable getCommentsTable(boolean create) {
+ protected Comments getCommentsTable(boolean create) {
if(sheetComments == null && create){
// Try to create a comments table with the same number as
// the sheet has (i.e. sheet 1 -> comments 1)
try {
- sheetComments = (CommentsTable)createRelationship(
+ sheetComments = (Comments)createRelationship(
XSSFRelation.SHEET_COMMENTS, getWorkbook().getXssfFactory(), Math.toIntExact(sheet.getSheetId()));
} catch(PartAlreadyExistsException e) {
// Technically a sheet doesn't need the same number as
- // it's comments, and clearly someone has already pinched
+ // its comments, and clearly someone has already pinched
// our number! Go for the next available one instead
- sheetComments = (CommentsTable)createRelationship(
+ sheetComments = (Comments)createRelationship(
XSSFRelation.SHEET_COMMENTS, getWorkbook().getXssfFactory(), -1);
}
}
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.model.Comments;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.xmlbeans.XmlObject;
XSSFClientAnchor ca = (XSSFClientAnchor) anchor;
// create comments and vmlDrawing parts if they don't exist
- CommentsTable comments = wb.getXSSFWorkbook()
+ Comments comments = wb.getXSSFWorkbook()
.getSheetAt(0).getCommentsTable(true);
XSSFVMLDrawing vml = wb.getXSSFWorkbook()
.getSheetAt(0).getVMLDrawing(true);
}
// create the comment in two different ways and verify that there is no difference
- XSSFComment shape1 = new XSSFComment(comments, comments.newComment(CellAddress.A1), vmlShape1);
+ CommentsTable commentsTable = (CommentsTable)comments;
+ XSSFComment shape1 = new XSSFComment(comments, commentsTable.newComment(CellAddress.A1), vmlShape1);
shape1.setColumn(ca.getCol1());
shape1.setRow(ca.getRow1());
}
CellAddress ref = new CellAddress(ca.getRow1(), ca.getCol1());
- XSSFComment shape2 = new XSSFComment(comments, comments.newComment(ref), vmlShape2);
+ XSSFComment shape2 = new XSSFComment(comments, commentsTable.newComment(ref), vmlShape2);
assertEquals(shape1.getAuthor(), shape2.getAuthor());
assertEquals(shape1.getClientAnchor(), shape2.getClientAnchor());
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.CalculationChain;
+import org.apache.poi.xssf.model.Comments;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
XSSFComment comment = dg.createCellComment(new XSSFClientAnchor());
Cell cell = sheet.createRow(0).createCell(0);
- CommentsTable comments = sheet.getCommentsTable(false);
+ CommentsTable comments = (CommentsTable) sheet.getCommentsTable(false);
CTComments ctComments = comments.getCTComments();
cell.setCellComment(comment);
void commentsTable() throws IOException {
try (XSSFWorkbook wb1 = new XSSFWorkbook()) {
XSSFSheet sheet1 = wb1.createSheet();
- CommentsTable comment1 = sheet1.getCommentsTable(false);
+ CommentsTable comment1 = (CommentsTable) sheet1.getCommentsTable(false);
assertNull(comment1);
- comment1 = sheet1.getCommentsTable(true);
+ comment1 = (CommentsTable) sheet1.getCommentsTable(true);
assertNotNull(comment1);
assertEquals("/xl/comments1.xml", comment1.getPackagePart().getPartName().getName());
//second sheet
XSSFSheet sheet2 = wb1.createSheet();
- CommentsTable comment2 = sheet2.getCommentsTable(false);
+ CommentsTable comment2 = (CommentsTable) sheet2.getCommentsTable(false);
assertNull(comment2);
- comment2 = sheet2.getCommentsTable(true);
+ comment2 = (CommentsTable) sheet2.getCommentsTable(true);
assertNotNull(comment2);
assertSame(comment2, sheet2.getCommentsTable(true));
//now test against a workbook containing cell comments
try (XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx")) {
XSSFSheet sheet1 = wb2.getSheetAt(0);
- CommentsTable comment1 = sheet1.getCommentsTable(true);
+ CommentsTable comment1 = (CommentsTable) sheet1.getCommentsTable(true);
assertNotNull(comment1);
assertEquals("/xl/comments1.xml", comment1.getPackagePart().getPartName().getName());
assertSame(comment1, sheet1.getCommentsTable(true));