本文整理汇总了Java中org.apache.poi.POIXMLDocument类的典型用法代码示例。如果您正苦于以下问题:Java POIXMLDocument类的具体用法?Java POIXMLDocument怎么用?Java POIXMLDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
POIXMLDocument类属于org.apache.poi包,在下文中一共展示了POIXMLDocument类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readContent
import org.apache.poi.POIXMLDocument; //导入依赖的package包/类
@Override
protected String readContent(final VFSLeaf leaf) throws IOException, DocumentException {
BufferedInputStream bis = null;
final StringBuilder buffy = new StringBuilder();
try {
bis = new BufferedInputStream(leaf.getInputStream());
final POIXMLTextExtractor extractor = (POIXMLTextExtractor) ExtractorFactory.createExtractor(bis);
final POIXMLDocument document = extractor.getDocument();
if (document instanceof XWPFDocument) {
final XWPFDocument xDocument = (XWPFDocument) document;
final XWPFHeaderFooterPolicy hfPolicy = xDocument.getHeaderFooterPolicy();
extractHeaders(buffy, hfPolicy);
extractContent(buffy, xDocument);
extractFooters(buffy, hfPolicy);
}
return buffy.toString();
} catch (final Exception e) {
throw new DocumentException(e.getMessage());
} finally {
if (bis != null) {
bis.close();
}
}
}
示例2: create
import org.apache.poi.POIXMLDocument; //导入依赖的package包/类
/**
* @param inp
* @param excelReader
* @param ignoreNumFormat 是否忽略数据格式 (default=false,按照格式读取)
* @return jie
* @throws InvalidFormatException
* @throws IOException
* @throws SQLException
*/
public static ReadHandler create(InputStream inp,
ExcelReadListener excelReader, boolean ignoreNumFormat)
throws InvalidFormatException, IOException, SQLException {
// If clearly doesn't do mark/reset, wrap up
if (! inp.markSupported()) {
inp = new PushbackInputStream(inp, 8);
}
// Ensure that there is at least some data there
byte[] header8 = IOUtils.peekFirst8Bytes(inp);
// Try to create
if (POIFSFileSystem.hasPOIFSHeader(header8)) {
POIFSFileSystem fs = new POIFSFileSystem(inp);
return create(fs, excelReader, ignoreNumFormat);
}
if (POIXMLDocument.hasOOXMLHeader(inp)) {
OPCPackage pkg = OPCPackage.open(inp);
return create(pkg, excelReader, ignoreNumFormat);
}
throw new InvalidFormatException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
}
示例3: readContent
import org.apache.poi.POIXMLDocument; //导入依赖的package包/类
@Override
protected String readContent(final VFSLeaf leaf) throws IOException, DocumentException {
BufferedInputStream bis = null;
final StringBuilder buffy = new StringBuilder();
try {
bis = new BufferedInputStream(leaf.getInputStream());
final POIXMLTextExtractor extractor = (POIXMLTextExtractor) ExtractorFactory.createExtractor(bis);
final POIXMLDocument document = extractor.getDocument();
if (document instanceof XSSFWorkbook) {
final XSSFWorkbook xDocument = (XSSFWorkbook) document;
extractContent(buffy, xDocument);
}
return buffy.toString();
} catch (final Exception e) {
throw new DocumentException(e.getMessage());
} finally {
if (bis != null) {
bis.close();
}
}
}
示例4: readContent
import org.apache.poi.POIXMLDocument; //导入依赖的package包/类
@Override
public String readContent(final VFSLeaf leaf) throws IOException, DocumentException {
BufferedInputStream bis = null;
final StringBuilder buffy = new StringBuilder();
try {
bis = new BufferedInputStream(leaf.getInputStream());
final POIXMLTextExtractor extractor = (POIXMLTextExtractor) ExtractorFactory.createExtractor(bis);
final POIXMLDocument document = extractor.getDocument();
if (document instanceof XSLFSlideShow) {
final XSLFSlideShow slideShow = (XSLFSlideShow) document;
final XMLSlideShow xmlSlideShow = new XMLSlideShow(slideShow);
extractContent(buffy, xmlSlideShow);
}
return buffy.toString();
} catch (final Exception e) {
throw new DocumentException(e.getMessage());
} finally {
if (bis != null) {
bis.close();
}
}
}
示例5: isNewExcelFormat
import org.apache.poi.POIXMLDocument; //导入依赖的package包/类
/**
* Detect the excel format with only peeking at the first 8 bytes of the input stream (leaving the stream untouched).
*
* @param inputStream the xls input stream.
* @return true if the given input stream is a xls new format.
* @throws IOException if an error occurs.
*/
public static boolean isNewExcelFormat(InputStream inputStream) throws IOException {
boolean newFormat = false;
// Ensure that there is at least some data there
byte[] headers = IOUtils.peekFirst8Bytes(inputStream);
if (NPOIFSFileSystem.hasPOIFSHeader(headers)) {
newFormat = false;
}
if (POIXMLDocument.hasOOXMLHeader(new ByteArrayInputStream(headers))) {
newFormat = true;
}
return newFormat;
}
示例6: readPackage
import org.apache.poi.POIXMLDocument; //导入依赖的package包/类
public static OPCPackage readPackage(String path){
try {
OPCPackage pack = POIXMLDocument.openPackage(path);
return pack;
} catch (IOException e) {
throw new RuntimeException("read word file["+path+"] error:"+e.getMessage());
}
}
示例7: setTemplate
import org.apache.poi.POIXMLDocument; //导入依赖的package包/类
/**
* 为文档设置模板
* @param templatePath 模板文件名称
*/
public void setTemplate(String templatePath) {
try {
this.document = new XWPFDocument(POIXMLDocument.openPackage(templatePath));
bookMarks = new BookMarks(document);
} catch (IOException e) {
e.printStackTrace();
}
}
示例8: testPOI
import org.apache.poi.POIXMLDocument; //导入依赖的package包/类
@Test
public void testPOI() throws Exception {
// setup
InputStream inputStream = OOXMLSignatureVerifierTest.class.getResourceAsStream("/hello-world-unsigned.docx");
// operate
boolean result = POIXMLDocument.hasOOXMLHeader(inputStream);
// verify
assertTrue(result);
}
示例9: getWorkbook
import org.apache.poi.POIXMLDocument; //导入依赖的package包/类
public static Workbook getWorkbook(InputStream i) throws IOException
{
BufferedInputStream bis = new BufferedInputStream(i);
if (POIXMLDocument.hasOOXMLHeader(bis))
{
return new XSSFWorkbook(bis);
}
else if (POIFSFileSystem.hasPOIFSHeader(bis))
{
return new HSSFWorkbook(bis);
}
throw new FileReadException("Unable to read the file because it is of the incorrect format type.", null);
}
示例10: getDocument
import org.apache.poi.POIXMLDocument; //导入依赖的package包/类
/**
* @see mj.ocraptor.extraction.tika.parser.microsoft.ooxml.OOXMLExtractor#getDocument()
*/
public POIXMLDocument getDocument() {
return extractor.getDocument();
}
示例11: getDocument
import org.apache.poi.POIXMLDocument; //导入依赖的package包/类
/**
* Returns the opened document.
*
* @see POIXMLTextExtractor#getDocument()
*/
POIXMLDocument getDocument();