当前位置: 首页>>代码示例>>Java>>正文


Java OPCPackage.open方法代码示例

本文整理汇总了Java中org.apache.poi.openxml4j.opc.OPCPackage.open方法的典型用法代码示例。如果您正苦于以下问题:Java OPCPackage.open方法的具体用法?Java OPCPackage.open怎么用?Java OPCPackage.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.openxml4j.opc.OPCPackage的用法示例。


在下文中一共展示了OPCPackage.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
/**
 * 遍历工作簿中所有的电子表格
 * 
 * @param filename
 * @throws Exception
 */
public void process(InputStream stream) throws Exception {
	OPCPackage pkg = OPCPackage.open(stream);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse(sheetSource);
		sheet.close();
	}
}
 
开发者ID:tb544731152,项目名称:iBase4J,代码行数:22,代码来源:Excel2007Reader.java

示例2: docxFileContentParser

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
public String docxFileContentParser(String fileName) {
	try {
		FileInputStream fs = new FileInputStream(new File(fileName));
		OPCPackage d = OPCPackage.open(fs);
		if (fileName.endsWith(".docx")) {
			XWPFWordExtractor xw = new XWPFWordExtractor(d);
			return xw.getText();
		} else if (fileName.endsWith(".pptx")) {
			XSLFPowerPointExtractor xp = new XSLFPowerPointExtractor(d);
			return xp.getText();
		} else if (fileName.endsWith(".xlsx")) {
			XSSFExcelExtractor xe = new XSSFExcelExtractor(d);
			xe.setFormulasNotResults(true);
			xe.setIncludeSheetNames(true);
			return xe.getText();
		}
	} catch (Exception e) {
		System.out.println("# DocxFileParser Error :" + e.getMessage());
	}
	return "";
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:22,代码来源:DocxFileParser.java

示例3: testNonEmptyDoc

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
@Test
public void testNonEmptyDoc() throws InvalidFormatException, IOException {
    try (FileInputStream is = new FileInputStream("resources/document/notEmpty/notEmpty-template.docx");
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenProvider iterator = new TokenProvider(document);
        XWPFRun run = iterator.next().getRun();
        assertEquals("P1Run1 ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P1Run2", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals(" P1Run3", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run1 ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run2", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals(" ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run3", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("", run.getText(run.getTextPosition()));
        assertTrue(!iterator.hasNext());
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:26,代码来源:RunProviderTests.java

示例4: testLookaheadEmptyIterator

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
@Test
public void testLookaheadEmptyIterator() throws InvalidFormatException, IOException {
    try (FileInputStream is = new FileInputStream("resources/document/notEmpty/notEmpty-template.docx");
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenProvider iterator = new TokenProvider(document);
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        iterator.next().getRun();
        assertNull(iterator.lookAhead(1));
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:18,代码来源:RunProviderTests.java

示例5: testNextWitLookAhead

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
@Test
public void testNextWitLookAhead() throws InvalidFormatException, IOException {
    try (FileInputStream is = new FileInputStream("resources/document/notEmpty/notEmpty-template.docx");
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenProvider iterator = new TokenProvider(document);
        // CHECKSTYLE:OFF
        assertTrue(iterator.hasElements(7));
        // CHECKSTYLE:ON
        XWPFRun run;
        run = iterator.lookAhead(1).getRun();
        assertEquals("P1Run1 ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P1Run1 ", run.getText(run.getTextPosition()));
        run = iterator.lookAhead(1).getRun();
        assertEquals("P1Run2", run.getText(run.getTextPosition()));
        run = iterator.lookAhead(2).getRun();
        assertEquals(" P1Run3", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P1Run2", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals(" P1Run3", run.getText(run.getTextPosition()));
        assertTrue(iterator.hasElements(4));
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:26,代码来源:RunProviderTests.java

示例6: testAccessEmptyIterator

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
@Test
public void testAccessEmptyIterator() throws InvalidFormatException, IOException {
    try (FileInputStream is = new FileInputStream("resources/document/notEmpty/notEmpty-template.docx");
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenIterator iterator = new TokenIterator(document);
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertNotNull(iterator.next());
        assertFalse(iterator.hasNext());
        boolean hasException = false;
        try {
            iterator.next();
        } catch (NoSuchElementException e) {
            assertTrue(e instanceof NoSuchElementException);
            hasException = true;
        }
        assertTrue(hasException);
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:26,代码来源:RunIteratorTests.java

示例7: getTextContent

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
/**
 * Gets the textual element of the .docx at the given {@link URI}.
 * 
 * @param uriConverter
 *            the {@link URIConverter}
 * @param uri
 *            the .docx {@link URI}
 * @return the textual element of the .docx at the given {@link URI}
 */
public static String getTextContent(URIConverter uriConverter, URI uri) {
    String result = "";

    try (InputStream is = uriConverter.createInputStream(uri);
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);
            XWPFWordExtractor ex = new XWPFWordExtractor(document);) {

        result += "===== Document Text ====\n";
        result += ex.getText();
        // CHECKSTYLE:OFF
    } catch (Throwable e) {
        // CHECKSTYLE:ON
        /*
         * if for some reason we can't use POI to get the text content then move along, we'll still get the XML and hashs
         */
    }
    return result;
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:29,代码来源:M2DocTestUtils.java

示例8: unmarshal

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T> List<T> unmarshal(Class<T> type) {
    try (OPCPackage open = OPCPackage.open(poijiFile.file())) {

        ReadOnlySharedStringsTable readOnlySharedStringsTable = new ReadOnlySharedStringsTable(open);
        XSSFReader xssfReader = new XSSFReader(open);
        StylesTable styles = xssfReader.getStylesTable();

        SheetIterator iter = (SheetIterator) xssfReader.getSheetsData();
        int index = 0;

        while (iter.hasNext()) {
            try (InputStream stream = iter.next()) {
                if (index == options.sheetIndex()) {
                    return processSheet(styles, readOnlySharedStringsTable, type, stream);
                }
            }
            ++index;
        }
        return new ArrayList<>();
    } catch (SAXException | IOException | OpenXML4JException e) {
        throw new PoijiException("Problem occurred while reading data", e);
    }
}
 
开发者ID:ozlerhakan,项目名称:poiji,代码行数:26,代码来源:XSSFUnmarshaller.java

示例9: process

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
/**
 * 遍历工作簿中所有的电子表格
 * 
 * @param filename string
 * @throws Exception  if an error occurred
 */
public void process(String filename) throws Exception {
	OPCPackage pkg = OPCPackage.open(filename);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse(sheetSource);
		sheet.close();
	}
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:22,代码来源:Excel2007Reader.java

示例10: process

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
/**
 * 遍历工作簿中所有的电子表格
 * 
 * @param filename
 * @throws Exception
 */
public void process(String filename) throws Exception {
	OPCPackage pkg = OPCPackage.open(filename);
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();
	XMLReader parser = fetchSheetParser(sst);
	Iterator<InputStream> sheets = r.getSheetsData();
	while (sheets.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse(sheetSource);
		sheet.close();
	}
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:22,代码来源:Excel2007Reader.java

示例11: importFromXLSX

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
/**
 * ImportFromXLSX
 * @param inputStream
 * @param sheetNumber
 * @return
 * @throws InvalidFormatException
 * @throws IOException
 */
public static DenseObjectMatrix2D importFromXLSX(final InputStream inputStream, final int sheetNumber)
		throws InvalidFormatException, IOException 
{
	final OPCPackage pkg = OPCPackage.open(inputStream);
	final XSSFWorkbook workbook = new XSSFWorkbook(pkg);
	final DenseObjectMatrix2D matrix = importFromWorkbook(workbook, sheetNumber);
	pkg.close();
	
	return matrix;
}
 
开发者ID:ansleliu,项目名称:GraphicsViewJambi,代码行数:19,代码来源:ImportNetworkFromExcel.java

示例12: execute

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
public void execute(InputStream inputStream, IParseExcelRowMapper parseExcelRowMapper) throws Exception {
	OPCPackage pkg = OPCPackage.open(inputStream);
	XSSFReader xssfReader = new XSSFReader(pkg);
	sst = xssfReader.getSharedStringsTable();
	stylesTable = xssfReader.getStylesTable();

	SAXParserFactory saxFactory = SAXParserFactory.newInstance();
	SAXParser saxParser = saxFactory.newSAXParser();
	XMLReader parser = saxParser.getXMLReader();
	parser.setContentHandler(new XSSFParserHandler());

	this.parseExcelRowMapper = parseExcelRowMapper;

	XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
	while (iter.hasNext()) {
		curRow = 0;
		sheetIndex++;
		InputStream sheet = iter.next();
		sheetName = iter.getSheetName();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse(sheetSource);
		sheet.close();
	}

}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:26,代码来源:XSSFParser.java

示例13: testOPC

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
@Test
public void testOPC() throws Exception {
	// setup
	InputStream inputStream = OOXMLSignatureVerifierTest.class.getResourceAsStream("/hello-world-signed.docx");

	// operate
	OPCPackage opcPackage = OPCPackage.open(inputStream);

	ArrayList<PackagePart> parts = opcPackage.getParts();
	for (PackagePart part : parts) {
		LOG.debug("part name: " + part.getPartName().getName());
		LOG.debug("part content type: " + part.getContentType());
	}

	ArrayList<PackagePart> signatureParts = opcPackage
			.getPartsByContentType("application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml");
	assertFalse(signatureParts.isEmpty());

	PackagePart signaturePart = signatureParts.get(0);
	LOG.debug("signature part class type: " + signaturePart.getClass().getName());

	PackageDigitalSignatureManager packageDigitalSignatureManager = new PackageDigitalSignatureManager();
	// yeah... POI implementation still missing
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:25,代码来源:OOXMLSignatureVerifierTest.java

示例14: DefaultXSSFSaxHandler

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
public DefaultXSSFSaxHandler(File file, ExcelReadListener excelReader,
		boolean ignoreNumFormat) throws InvalidFormatException {
	
	
	try {
		this.pkg = OPCPackage.open(file, PackageAccess.READ);
		this.excelReader = excelReader;
		this.ignoreNumFormat = ignoreNumFormat;
		this.handler = new DefaultSheetContentsHandler(
				excelReader);
	} catch (IllegalArgumentException  e) {
		//异常是open方法抛出的。确保io关闭
		pkg.revert();
		throw e;
	}
}
 
开发者ID:bingyulei007,项目名称:bingexcel,代码行数:17,代码来源:DefaultXSSFSaxHandler.java

示例15: create

import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的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");
   

}
 
开发者ID:bingyulei007,项目名称:bingexcel,代码行数:34,代码来源:ExcelReaderFactory.java


注:本文中的org.apache.poi.openxml4j.opc.OPCPackage.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。