use of org.apache.poi.ooxml.extractor.POIXMLTextExtractor in project yyl_example by Relucent.
the class WordExample method toString.
public static String toString(byte[] content) throws IOException {
try (InputStream input = new ByteArrayInputStream(content)) {
FileMagic magic = ofMagic(content);
// DOC:OLE2
if (FileMagic.OLE2.equals(magic)) {
try (WordExtractor extractor = new WordExtractor(input)) {
return extractor.getText();
}
}
// DOCX:OOXML
OPCPackage opcPackage = OPCPackage.open(input);
try (POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage)) {
return extractor.getText();
}
} catch (XmlException | OpenXML4JException e) {
throw new IOException(e);
}
}
Aggregations