use of org.apache.poi.xssf.model.CommentsTable in project poi by apache.
the class TestXSSFReader method testComments.
public void testComments() throws Exception {
OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("comments.xlsx");
XSSFReader r = new XSSFReader(pkg);
XSSFReader.SheetIterator it = (XSSFReader.SheetIterator) r.getSheetsData();
int count = 0;
while (it.hasNext()) {
count++;
InputStream inp = it.next();
inp.close();
if (count == 1) {
assertNotNull(it.getSheetComments());
CommentsTable ct = it.getSheetComments();
assertEquals(1, ct.getNumberOfAuthors());
assertEquals(3, ct.getNumberOfComments());
} else {
assertNull(it.getSheetComments());
}
}
assertEquals(3, count);
}
use of org.apache.poi.xssf.model.CommentsTable in project tika by apache.
the class XSSFExcelExtractorDecorator method buildXHTML.
/**
* @see org.apache.poi.xssf.extractor.XSSFExcelExtractor#getText()
*/
@Override
protected void buildXHTML(XHTMLContentHandler xhtml) throws SAXException, XmlException, IOException {
OPCPackage container = extractor.getPackage();
ReadOnlySharedStringsTable strings;
XSSFReader.SheetIterator iter;
XSSFReader xssfReader;
StylesTable styles;
try {
xssfReader = new XSSFReader(container);
styles = xssfReader.getStylesTable();
iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
strings = new ReadOnlySharedStringsTable(container);
} catch (InvalidFormatException e) {
throw new XmlException(e);
} catch (OpenXML4JException oe) {
throw new XmlException(oe);
}
//temporary workaround for POI-61034
//remove once POI 3.17-beta1 is released
Set<String> seen = new HashSet<>();
while (iter.hasNext()) {
SheetTextAsHTML sheetExtractor = new SheetTextAsHTML(xhtml);
PackagePart sheetPart = null;
try (InputStream stream = iter.next()) {
sheetPart = iter.getSheetPart();
final String partName = sheetPart.getPartName().toString();
if (seen.contains(partName)) {
continue;
}
seen.add(partName);
addDrawingHyperLinks(sheetPart);
sheetParts.add(sheetPart);
CommentsTable comments = iter.getSheetComments();
// Start, and output the sheet name
xhtml.startElement("div");
xhtml.element("h1", iter.getSheetName());
// Extract the main sheet contents
xhtml.startElement("table");
xhtml.startElement("tbody");
processSheet(sheetExtractor, comments, styles, strings, stream);
}
xhtml.endElement("tbody");
xhtml.endElement("table");
// do the headers before the contents)
for (String header : sheetExtractor.headers) {
extractHeaderFooter(header, xhtml);
}
for (String footer : sheetExtractor.footers) {
extractHeaderFooter(footer, xhtml);
}
// Do text held in shapes, if required
if (config.getIncludeShapeBasedContent()) {
List<XSSFShape> shapes = iter.getShapes();
processShapes(shapes, xhtml);
}
//for now dump sheet hyperlinks at bottom of page
//consider a double-pass of the inputstream to reunite hyperlinks with cells/textboxes
//step 1: extract hyperlink info from bottom of page
//step 2: process as we do now, but with cached hyperlink relationship info
extractHyperLinks(sheetPart, xhtml);
// All done with this sheet
xhtml.endElement("div");
}
}
use of org.apache.poi.xssf.model.CommentsTable in project poi by apache.
the class TestXSSFComment method author.
@Test
public void author() {
CommentsTable sheetComments = new CommentsTable();
CTComment ctComment = sheetComments.newComment(CellAddress.A1);
assertEquals(1, sheetComments.getNumberOfAuthors());
XSSFComment comment = new XSSFComment(sheetComments, ctComment, null);
assertEquals("", comment.getAuthor());
comment.setAuthor("Apache POI");
assertEquals("Apache POI", comment.getAuthor());
assertEquals(2, sheetComments.getNumberOfAuthors());
comment.setAuthor("Apache POI");
assertEquals(2, sheetComments.getNumberOfAuthors());
comment.setAuthor("");
assertEquals("", comment.getAuthor());
assertEquals(2, sheetComments.getNumberOfAuthors());
}
use of org.apache.poi.xssf.model.CommentsTable in project poi by apache.
the class TestXSSFComment method getSetRow.
@Test
public void getSetRow() {
CommentsTable sheetComments = new CommentsTable();
XSSFVMLDrawing vml = new XSSFVMLDrawing();
CTComment ctComment = sheetComments.newComment(CellAddress.A1);
CTShape vmlShape = vml.newCommentShape();
XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);
comment.setRow(1);
assertEquals(1, comment.getRow());
assertEquals(1, new CellReference(ctComment.getRef()).getRow());
assertEquals(1, vmlShape.getClientDataArray(0).getRowArray(0).intValue());
comment.setRow(5);
assertEquals(5, comment.getRow());
assertEquals(5, new CellReference(ctComment.getRef()).getRow());
assertEquals(5, vmlShape.getClientDataArray(0).getRowArray(0).intValue());
}
use of org.apache.poi.xssf.model.CommentsTable in project poi by apache.
the class TestXSSFSheet method setCellComment.
@Test
public void setCellComment() throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
XSSFDrawing dg = sheet.createDrawingPatriarch();
XSSFComment comment = dg.createCellComment(new XSSFClientAnchor());
Cell cell = sheet.createRow(0).createCell(0);
CommentsTable comments = sheet.getCommentsTable(false);
CTComments ctComments = comments.getCTComments();
cell.setCellComment(comment);
assertEquals("A1", ctComments.getCommentList().getCommentArray(0).getRef());
comment.setAuthor("test A1 author");
assertEquals("test A1 author", comments.getAuthor((int) ctComments.getCommentList().getCommentArray(0).getAuthorId()));
workbook.close();
}
Aggregations