本文整理汇总了Java中org.apache.poi.openxml4j.opc.PackageAccess类的典型用法代码示例。如果您正苦于以下问题:Java PackageAccess类的具体用法?Java PackageAccess怎么用?Java PackageAccess使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PackageAccess类属于org.apache.poi.openxml4j.opc包,在下文中一共展示了PackageAccess类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DefaultXSSFSaxHandler
import org.apache.poi.openxml4j.opc.PackageAccess; //导入依赖的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;
}
}
示例2: create
import org.apache.poi.openxml4j.opc.PackageAccess; //导入依赖的package包/类
/**
* @param file
* @param excelReader
* @param ignoreNumFormat 是否忽略数据格式 (default=false,按照格式读取)
* @return
* @throws Exception
*/
public static ReadHandler create(File file, ExcelReadListener excelReader,
boolean ignoreNumFormat) throws Exception {
if (!file.exists()) {
throw new FileNotFoundException(file.toString());
}
try {
POIFSFileSystem fs = new POIFSFileSystem(file);
return create(fs, excelReader, ignoreNumFormat);
} catch (OfficeXmlFileException e) {
OPCPackage pkg = OPCPackage.open(file, PackageAccess.READ);
try {
return create(pkg, excelReader, ignoreNumFormat);
} catch (IllegalArgumentException | IOException e1) {
pkg.revert();
throw e1;
}
}
}
示例3: parseXlsxFileAndWriteTmxBody
import org.apache.poi.openxml4j.opc.PackageAccess; //导入依赖的package包/类
public void parseXlsxFileAndWriteTmxBody(String fileName, AbstractWriter tmxWriter, IProgressMonitor monitor)
throws ParserConfigurationException, SAXException, IOException, OpenXML4JException {
this.tmxWriter = tmxWriter;
this.monitor = monitor;
File file = new File(fileName);
long length = file.length();
monitor.beginTask("", countTotal(length));
OPCPackage p = OPCPackage.open(fileName, PackageAccess.READ);
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(p);
XSSFReader xssfReader = new XSSFReader(p);
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
try {
while (iter.hasNext()) {
InputStream stream = iter.next();
parse(stream, strings, tmxWriter);
stream.close();
// 目前只处理第一个sheet
break;
}
} finally {
p.close();
}
monitor.done();
}
示例4: readRows
import org.apache.poi.openxml4j.opc.PackageAccess; //导入依赖的package包/类
public void readRows(IProgressMonitor monitor) throws ParserConfigurationException, SAXException, IOException, OpenXML4JException {
monitor.beginTask("", 10);
monitor.worked(1);
OPCPackage p = OPCPackage.open(xlsxFile, PackageAccess.READ);
ReadOnlySharedStringsTable shareString = new ReadOnlySharedStringsTable(p);
XSSFReader xssfReader = new XSSFReader(p);
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
try {
while (iter.hasNext()) {
InputStream stream = iter.next();
readCells(stream, shareString, new SubProgressMonitor(monitor, 9));
stream.close();
// 目前只处理第一个sheet
break;
}
} finally {
p.close();
monitor.done();
}
}
示例5: XlsxDataProvider
import org.apache.poi.openxml4j.opc.PackageAccess; //导入依赖的package包/类
/**
* Create the data provider from the given data file.
*
* @param inDataFile The Excel workbook file to use as the data store.
* @throws DataProviderException Thrown when the workbook can not be
* accessed, or parsed correctly.
*/
public XlsxDataProvider(File inDataFile, Locale locale) throws DataProviderException {
if (inDataFile == null) {
throw new IllegalArgumentException("inDataFile cannot be null");
}
this.logErrorMessage = new MessageFormat(MessageFormat.format(
"Spreadsheet {0} is missing required sheet",
new Object[]{inDataFile.getAbsolutePath()})
+ " {0}");
this.exceptionErrorMessage = new MessageFormat(
"Required worksheet {0} is missing");
try {
LOGGER.debug("Creating workbook from {}",
inDataFile.getAbsolutePath());
this.opcPackage = OPCPackage.open(inDataFile.getAbsolutePath(),
PackageAccess.READ);
this.workbook = new XSSFWorkbook(this.opcPackage);
this.validateWorksheets();
} catch (InvalidFormatException | InvalidOperationException ex) {
throw new DataProviderException("Invalid XLSX file", ex);
} catch (IOException ioe) {
throw new DataProviderException("Error reading XLSX file", ioe);
}
this.messages =
locale != null
? ResourceBundle.getBundle("Messages", locale)
: ResourceBundle.getBundle("Messages");
this.dataFile = inDataFile;
}
示例6: excelToCsv
import org.apache.poi.openxml4j.opc.PackageAccess; //导入依赖的package包/类
private void excelToCsv(FilesDataUnit.Entry entry) throws EncryptedDocumentException, InvalidFormatException, IOException,
DataUnitException {
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.excelTransformationStared", entry.getSymbolicName());
File excelFile = FilesHelper.asFile(entry);
try (Workbook wb = WorkbookFactory.create(OPCPackage.open(excelFile, PackageAccess.READ))) {
for (int s = 0; s < wb.getNumberOfSheets(); s++) {
Sheet sheet = wb.getSheetAt(s);
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.sheetName", sheet.getSheetName());
if (sheetNameSet.isEmpty() || sheetNameSet.contains(sheet.getSheetName())) {
DpuFile csvFile = createCsvFile(entry.getSymbolicName(), sheet.getSheetName());
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.csvGenerationStarted", csvFile.symbolicName);
sheetToCsv(sheet, csvFile.file);
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.csvGenerationFinished", csvFile.symbolicName);
} else {
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.sheetIgnored", sheet.getSheetName());
}
}
} catch (EncryptedDocumentException | InvalidFormatException | IOException ex) {
ContextUtils.sendError(ctx, "ExcelToCsv.excelTransformationFailed", ex, "ExcelToCsv.excelTransformationFailed", entry.getSymbolicName());
throw ex;
}
ContextUtils.sendShortInfo(ctx, "ExcelToCsv.excelTransformationFinishedSuccessfully", entry.getSymbolicName());
}
示例7: testStringsWithMultipleXmlElements
import org.apache.poi.openxml4j.opc.PackageAccess; //导入依赖的package包/类
/**
* Verifies a bug where BufferedStringsTable was only looking at the first Characters xml element
* in a text sequence.
*/
@Test
public void testStringsWithMultipleXmlElements() throws Exception {
File file = new File("src/test/resources/blank_cells.xlsx");
File sstCache = File.createTempFile("cache", ".sst");
sstCache.deleteOnExit();
try (OPCPackage pkg = OPCPackage.open(file, PackageAccess.READ);
BufferedStringsTable sst = BufferedStringsTable.getSharedStringsTable(sstCache, 1000, pkg)) {
assertNotNull(sst);
assertEquals("B1 is Blank --->", sst.getEntryAt(0).getT());
}
}
示例8: testStringsWrappedInFormatting
import org.apache.poi.openxml4j.opc.PackageAccess; //导入依赖的package包/类
/**
* Verifies a bug where BufferedStringsTable was dropping text enclosed in formatting
* instructions.
*/
@Test
public void testStringsWrappedInFormatting() throws Exception {
File file = new File("src/test/resources/shared_styled_string.xlsx");
File sstCache = File.createTempFile("cache", ".sst");
sstCache.deleteOnExit();
try (OPCPackage pkg = OPCPackage.open(file, PackageAccess.READ);
BufferedStringsTable sst = BufferedStringsTable.getSharedStringsTable(sstCache, 1000, pkg)) {
assertNotNull(sst);
assertEquals("shared styled string", sst.getEntryAt(0).getT());
}
}
示例9: XlsxStreamer
import org.apache.poi.openxml4j.opc.PackageAccess; //导入依赖的package包/类
public XlsxStreamer(String fileLocation, DataCallback dataCallback) throws InvalidFormatException, IOException {
this(dataCallback);
this.pack = OPCPackage.open(fileLocation, PackageAccess.READ);
}
示例10: testClosingFiles
import org.apache.poi.openxml4j.opc.PackageAccess; //导入依赖的package包/类
@Test
public void testClosingFiles() throws Exception {
OPCPackage o = OPCPackage.open(new File("src/test/resources/blank_cell_StringCellValue.xlsx"), PackageAccess.READ);
o.close();
}
示例11: XlsxMetadata
import org.apache.poi.openxml4j.opc.PackageAccess; //导入依赖的package包/类
public XlsxMetadata(String fileLocation) throws InvalidFormatException, IOException {
this.pack = OPCPackage.open(fileLocation, PackageAccess.READ);
}