import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.xssf.model.Comments;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.model.SharedStrings;
import org.apache.poi.xssf.model.StylesTable;
/**
* Table with cell comments
*/
- private CommentsTable commentsTable;
+ private Comments comments;
/**
* Read only access to the shared strings table, for looking
DataFormatter dataFormatter,
boolean formulasNotResults) {
this.stylesTable = styles;
- this.commentsTable = comments;
+ this.comments = comments;
this.sharedStringsTable = strings;
this.output = sheetContentsHandler;
this.formulasNotResults = formulasNotResults;
this.nextDataType = xssfDataType.NUMBER;
this.formatter = dataFormatter;
- init();
+ init(comments);
}
/**
this(styles, strings, sheetContentsHandler, new DataFormatter(), formulasNotResults);
}
- private void init() {
+ private void init(CommentsTable commentsTable) {
if (commentsTable != null) {
commentCellRefs = new LinkedList<>();
//noinspection deprecation
// Do we have a comment for this cell?
checkForEmptyCellComments(EmptyCellCommentsCheckType.CELL);
- XSSFComment comment = commentsTable != null ? commentsTable.findCellComment(new CellAddress(cellRef)) : null;
+ XSSFComment comment = comments != null ? comments.findCellComment(new CellAddress(cellRef)) : null;
// Output
output.cell(cellRef, thisStr, comment);
* Output an empty-cell comment.
*/
private void outputEmptyCellComment(CellAddress cellRef) {
- XSSFComment comment = commentsTable.findCellComment(cellRef);
+ XSSFComment comment = comments.findCellComment(cellRef);
output.cell(cellRef.formatAsString(), null, comment);
}
*/
public interface SheetContentsHandler {
/** A row with the (zero based) row number has started */
- public void startRow(int rowNum);
+ void startRow(int rowNum);
/** A row with the (zero based) row number has ended */
- public void endRow(int rowNum);
+ void endRow(int rowNum);
/**
* A cell, with the given formatted value (may be null),
* <code>src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java</code>
* for an example of how to handle this scenario.
*/
- public void cell(String cellReference, String formattedValue, XSSFComment comment);
+ void cell(String cellReference, String formattedValue, XSSFComment comment);
/** A header or footer has been encountered */
- public default void headerFooter(String text, boolean isHeader, String tagName) {}
+ default void headerFooter(String text, boolean isHeader, String tagName) {}
/** Signal that the end of a sheet was been reached */
- public default void endSheet() {}
+ default void endSheet() {}
}
}
XSSFBCommentsTable comments,
SharedStrings strings,
InputStream sheetInputStream)
- throws IOException, SAXException {
+ throws IOException {
DataFormatter formatter;
if (getLocale() == null) {
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler;
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler.SheetContentsHandler;
+import org.apache.poi.xssf.model.Comments;
import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.xssf.model.SharedStrings;
import org.apache.poi.xssf.model.StylesTable;
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.xssf.model;
+
+import org.apache.poi.ss.util.CellAddress;
+import org.apache.poi.xssf.usermodel.XSSFComment;
+
+/**
+ * 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
+ * all the comments in memory
+ */
+public interface Comments {
+
+ int getNumberOfComments();
+
+ int getNumberOfAuthors();
+
+ String getAuthor(long authorId);
+
+ int findAuthor(String author);
+
+ /**
+ * Finds the cell comment at cellAddress, if one exists
+ *
+ * @param cellAddress the address of the cell to find a comment
+ * @return cell comment if one exists, otherwise returns null
+ */
+ XSSFComment findCellComment(CellAddress cellAddress);
+
+ /**
+ * Remove the comment at cellRef location, if one exists
+ *
+ * @param cellRef the location of the comment to remove
+ * @return returns true if a comment was removed
+ */
+ boolean removeComment(CellAddress cellRef);
+}
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CommentsDocument;
@Internal
-public class CommentsTable extends POIXMLDocumentPart {
+public class CommentsTable extends POIXMLDocumentPart implements Comments {
+
public static final String DEFAULT_AUTHOR = "";
public static final int DEFAULT_AUTHOR_ID = 0;
+
/**
* Underlying XML Beans CTComment list.
*/
throw new IOException(e.getLocalizedMessage());
}
}
+
public void writeTo(OutputStream out) throws IOException {
CommentsDocument doc = CommentsDocument.Factory.newInstance();
doc.setComments(comments);
}
}
+ @Override
public int getNumberOfComments() {
return comments.getCommentList().sizeOfCommentArray();
}
+ @Override
public int getNumberOfAuthors() {
return comments.getAuthors().sizeOfAuthorArray();
}
+ @Override
public String getAuthor(long authorId) {
return comments.getAuthors().getAuthorArray((int)authorId);
}
+ @Override
public int findAuthor(String author) {
String[] authorArray = comments.getAuthors().getAuthorArray();
for (int i = 0 ; i < authorArray.length; i++) {
* @param cellAddress the address of the cell to find a comment
* @return cell comment if one exists, otherwise returns null
*/
+ @Override
public XSSFComment findCellComment(CellAddress cellAddress) {
CTComment ct = getCTComment(cellAddress);
return ct == null ? null : new XSSFComment(this, ct, null);
* @param cellRef the location of the comment to remove
* @return returns true if a comment was removed
*/
+ @Override
public boolean removeComment(CellAddress cellRef) {
final String stringRef = cellRef.formatAsString();
CTCommentList lst = comments.getCommentList();
* @param idx index of item to return.
* @return the item at the specified position in this Shared String table.
*/
- public RichTextString getItemAt(int idx);
+ RichTextString getItemAt(int idx);
/**
* Return an integer representing the total count of strings in the workbook. This count does not
*
* @return the total count of strings in the workbook
*/
- public int getCount();
+ int getCount();
/**
* Returns an integer representing the total count of unique strings in the Shared String Table.
*
* @return the total count of unique strings in the workbook
*/
- public int getUniqueCount();
+ int getUniqueCount();
}