use of org.apache.poi.xssf.model.CommentsTable in project poi by apache.
the class XSSFEventBasedExcelExtractor method getText.
/**
* Processes the file and returns the text
*/
public String getText() {
try {
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(container, concatenatePhoneticRuns);
XSSFReader xssfReader = new XSSFReader(container);
StylesTable styles = xssfReader.getStylesTable();
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
StringBuffer text = new StringBuffer();
SheetTextExtractor sheetExtractor = new SheetTextExtractor();
while (iter.hasNext()) {
InputStream stream = iter.next();
if (includeSheetNames) {
text.append(iter.getSheetName());
text.append('\n');
}
CommentsTable comments = includeCellComments ? iter.getSheetComments() : null;
processSheet(sheetExtractor, styles, comments, strings, stream);
if (includeHeadersFooters) {
sheetExtractor.appendHeaderText(text);
}
sheetExtractor.appendCellText(text);
if (includeTextBoxes) {
processShapes(iter.getShapes(), text);
}
if (includeHeadersFooters) {
sheetExtractor.appendFooterText(text);
}
sheetExtractor.reset();
stream.close();
}
return text.toString();
} catch (IOException e) {
LOGGER.log(POILogger.WARN, e);
return null;
} catch (SAXException se) {
LOGGER.log(POILogger.WARN, se);
return null;
} catch (OpenXML4JException o4je) {
LOGGER.log(POILogger.WARN, o4je);
return null;
}
}
use of org.apache.poi.xssf.model.CommentsTable in project poi by apache.
the class XSSFDrawing method createCellComment.
/**
* Creates a comment.
* @param anchor the client anchor describes how this comment is attached
* to the sheet.
* @return the newly created comment.
*/
@Override
public XSSFComment createCellComment(ClientAnchor anchor) {
XSSFClientAnchor ca = (XSSFClientAnchor) anchor;
XSSFSheet sheet = getSheet();
//create comments and vmlDrawing parts if they don't exist
CommentsTable comments = sheet.getCommentsTable(true);
XSSFVMLDrawing vml = sheet.getVMLDrawing(true);
com.microsoft.schemas.vml.CTShape vmlShape = vml.newCommentShape();
if (ca.isSet()) {
// convert offsets from emus to pixels since we get a DrawingML-anchor
// but create a VML Drawing
int dx1Pixels = ca.getDx1() / Units.EMU_PER_PIXEL;
int dy1Pixels = ca.getDy1() / Units.EMU_PER_PIXEL;
int dx2Pixels = ca.getDx2() / Units.EMU_PER_PIXEL;
int dy2Pixels = ca.getDy2() / Units.EMU_PER_PIXEL;
String position = ca.getCol1() + ", " + dx1Pixels + ", " + ca.getRow1() + ", " + dy1Pixels + ", " + ca.getCol2() + ", " + dx2Pixels + ", " + ca.getRow2() + ", " + dy2Pixels;
vmlShape.getClientDataArray(0).setAnchorArray(0, position);
}
CellAddress ref = new CellAddress(ca.getRow1(), ca.getCol1());
if (comments.findCellComment(ref) != null) {
throw new IllegalArgumentException("Multiple cell comments in one cell are not allowed, cell: " + ref);
}
return new XSSFComment(comments, comments.newComment(ref), vmlShape);
}
Aggregations