當前位置: 首頁>>代碼示例>>Java>>正文


Java OPCPackage類代碼示例

本文整理匯總了Java中org.apache.poi.openxml4j.opc.OPCPackage的典型用法代碼示例。如果您正苦於以下問題:Java OPCPackage類的具體用法?Java OPCPackage怎麽用?Java OPCPackage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OPCPackage類屬於org.apache.poi.openxml4j.opc包,在下文中一共展示了OPCPackage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testAccessEmptyIterator

import org.apache.poi.openxml4j.opc.OPCPackage; //導入依賴的package包/類
@Test(expected = NoSuchElementException.class)
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);) {
        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();
        iterator.next().getRun();
    }
}
 
開發者ID:ObeoNetwork,項目名稱:M2Doc,代碼行數:18,代碼來源:RunProviderTests.java

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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);) {
        TokenIterator iterator = new TokenIterator(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,代碼來源:RunIteratorTests.java

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: processAll

import org.apache.poi.openxml4j.opc.OPCPackage; //導入依賴的package包/類
private void processAll(OPCPackage pkg)
		throws IOException, OpenXML4JException, InvalidFormatException, SAXException {
	XSSFReader xssfReader = new XSSFReader(pkg);
	mStylesTable = xssfReader.getStylesTable();
	SharedStringsTable sst = xssfReader.getSharedStringsTable();
	XMLReader parser = this.fetchSheetParser(sst);
	Iterator<InputStream> sheets = xssfReader.getSheetsData();
	while (sheets.hasNext()) {
		mCurrentRowIndex = 0;
		mSheetIndex++;
		InputStream sheet = sheets.next();
		InputSource sheetSource = new InputSource(sheet);
		parser.parse(sheetSource);
		sheet.close();
	}
	pkg.close();
}
 
開發者ID:wuwz,項目名稱:ExcelKit,代碼行數:18,代碼來源:XlsxReader.java

示例14: processBySheet

import org.apache.poi.openxml4j.opc.OPCPackage; //導入依賴的package包/類
private void processBySheet(int sheetIndex, OPCPackage pkg)
		throws IOException, OpenXML4JException, InvalidFormatException, SAXException {
	XSSFReader r = new XSSFReader(pkg);
	SharedStringsTable sst = r.getSharedStringsTable();

	XMLReader parser = fetchSheetParser(sst);

	// rId2 found by processing the Workbook
	// 根據 rId# 或 rSheet# 查找sheet
	InputStream sheet = r.getSheet("rId" + (sheetIndex + 1));
	mSheetIndex++;
	InputSource sheetSource = new InputSource(sheet);
	parser.parse(sheetSource);
	sheet.close();
	pkg.close();
}
 
開發者ID:wuwz,項目名稱:ExcelKit,代碼行數:17,代碼來源:XlsxReader.java

示例15: 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


注:本文中的org.apache.poi.openxml4j.opc.OPCPackage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。