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


Java PackageAccess类代码示例

本文整理汇总了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;
	}
}
 
开发者ID:bingyulei007,项目名称:bingexcel,代码行数:17,代码来源:DefaultXSSFSaxHandler.java

示例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;
		}
	}

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

示例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();
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:26,代码来源:Xlsx2TmxHelper.java

示例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();
	}
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:21,代码来源:XlsxRowReader.java

示例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;
}
 
开发者ID:eurekaclinical,项目名称:eureka,代码行数:38,代码来源:XlsxDataProvider.java

示例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());
}
 
开发者ID:UnifiedViews,项目名称:Plugins,代码行数:28,代码来源:ExcelToCsv.java

示例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());
  }
}
 
开发者ID:monitorjbl,项目名称:excel-streaming-reader,代码行数:16,代码来源:BufferedStringsTableTest.java

示例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());
  }
}
 
开发者ID:monitorjbl,项目名称:excel-streaming-reader,代码行数:16,代码来源:BufferedStringsTableTest.java

示例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);
}
 
开发者ID:iMDT,项目名称:xlsx-io,代码行数:5,代码来源:XlsxStreamer.java

示例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();
}
 
开发者ID:monitorjbl,项目名称:excel-streaming-reader,代码行数:6,代码来源:StreamingReaderTest.java

示例11: XlsxMetadata

import org.apache.poi.openxml4j.opc.PackageAccess; //导入依赖的package包/类
public XlsxMetadata(String fileLocation) throws InvalidFormatException, IOException {

        this.pack = OPCPackage.open(fileLocation, PackageAccess.READ);
    }
 
开发者ID:iMDT,项目名称:xlsx-io,代码行数:5,代码来源:XlsxMetadata.java


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