use of org.apache.poi.xssf.usermodel.XSSFSimpleShape in project tika by apache.
the class XSSFExcelExtractorDecorator method processShapes.
private void processShapes(List<XSSFShape> shapes, XHTMLContentHandler xhtml) throws SAXException {
if (shapes == null) {
return;
}
for (XSSFShape shape : shapes) {
if (shape instanceof XSSFSimpleShape) {
String sText = ((XSSFSimpleShape) shape).getText();
if (sText != null && sText.length() > 0) {
xhtml.element("p", sText);
}
extractHyperLinksFromShape(((XSSFSimpleShape) shape).getCTShape(), xhtml);
}
}
}
use of org.apache.poi.xssf.usermodel.XSSFSimpleShape in project tika by apache.
the class XSSFBExcelExtractorDecorator method processShapes.
private void processShapes(List<XSSFShape> shapes, XHTMLContentHandler xhtml) throws SAXException {
if (shapes == null) {
return;
}
for (XSSFShape shape : shapes) {
if (shape instanceof XSSFSimpleShape) {
String sText = ((XSSFSimpleShape) shape).getText();
if (sText != null && sText.length() > 0) {
xhtml.element("p", sText);
}
extractHyperLinksFromShape(((XSSFSimpleShape) shape).getCTShape(), xhtml);
}
}
}
use of org.apache.poi.xssf.usermodel.XSSFSimpleShape in project poi by apache.
the class XSSFExcelExtractor method getText.
/**
* Retrieves the text contents of the file
*/
public String getText() {
DataFormatter formatter;
if (locale == null) {
formatter = new DataFormatter();
} else {
formatter = new DataFormatter(locale);
}
StringBuffer text = new StringBuffer();
for (Sheet sh : workbook) {
XSSFSheet sheet = (XSSFSheet) sh;
if (includeSheetNames) {
text.append(sheet.getSheetName()).append("\n");
}
// Header(s), if present
if (includeHeadersFooters) {
text.append(extractHeaderFooter(sheet.getFirstHeader()));
text.append(extractHeaderFooter(sheet.getOddHeader()));
text.append(extractHeaderFooter(sheet.getEvenHeader()));
}
// Rows and cells
for (Object rawR : sheet) {
Row row = (Row) rawR;
for (Iterator<Cell> ri = row.cellIterator(); ri.hasNext(); ) {
Cell cell = ri.next();
// Is it a formula one?
if (cell.getCellTypeEnum() == CellType.FORMULA) {
if (formulasNotResults) {
String contents = cell.getCellFormula();
checkMaxTextSize(text, contents);
text.append(contents);
} else {
if (cell.getCachedFormulaResultTypeEnum() == CellType.STRING) {
handleStringCell(text, cell);
} else {
handleNonStringCell(text, cell, formatter);
}
}
} else if (cell.getCellTypeEnum() == CellType.STRING) {
handleStringCell(text, cell);
} else {
handleNonStringCell(text, cell, formatter);
}
// Output the comment, if requested and exists
Comment comment = cell.getCellComment();
if (includeCellComments && comment != null) {
// Replace any newlines with spaces, otherwise it
// breaks the output
String commentText = comment.getString().getString().replace('\n', ' ');
checkMaxTextSize(text, commentText);
text.append(" Comment by ").append(comment.getAuthor()).append(": ").append(commentText);
}
if (ri.hasNext()) {
text.append("\t");
}
}
text.append("\n");
}
// add textboxes
if (includeTextBoxes) {
XSSFDrawing drawing = sheet.getDrawingPatriarch();
if (drawing != null) {
for (XSSFShape shape : drawing.getShapes()) {
if (shape instanceof XSSFSimpleShape) {
String boxText = ((XSSFSimpleShape) shape).getText();
if (boxText.length() > 0) {
text.append(boxText);
text.append('\n');
}
}
}
}
}
// Finally footer(s), if present
if (includeHeadersFooters) {
text.append(extractHeaderFooter(sheet.getFirstFooter()));
text.append(extractHeaderFooter(sheet.getOddFooter()));
text.append(extractHeaderFooter(sheet.getEvenFooter()));
}
}
return text.toString();
}
use of org.apache.poi.xssf.usermodel.XSSFSimpleShape in project poi by apache.
the class TestXSSFReader method getShapesString.
private String getShapesString(XSSFReader.SheetIterator it) {
StringBuilder sb = new StringBuilder();
while (it.hasNext()) {
it.next();
List<XSSFShape> shapes = it.getShapes();
if (shapes != null) {
for (XSSFShape shape : shapes) {
if (shape instanceof XSSFSimpleShape) {
String t = ((XSSFSimpleShape) shape).getText();
sb.append(t).append('\n');
}
}
}
}
return sb.toString();
}
Aggregations