本文整理汇总了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();
}
}
示例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();
}
}
示例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 "";
}
示例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());
}
}
示例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));
}
}
示例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));
}
}
示例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());
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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();
}
示例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;
}