本文整理汇总了Java中org.apache.poi.openxml4j.opc.OPCPackage.close方法的典型用法代码示例。如果您正苦于以下问题:Java OPCPackage.close方法的具体用法?Java OPCPackage.close怎么用?Java OPCPackage.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.openxml4j.opc.OPCPackage
的用法示例。
在下文中一共展示了OPCPackage.close方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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;
}
示例4: processOneSheet
import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
public void processOneSheet(String filename, int sheetId) throws Exception {
OPCPackage pkg = OPCPackage.open(filename);
XSSFReader r = new XSSFReader(pkg);
SharedStringsTable sst = r.getSharedStringsTable();
XMLReader parser = fetchSheetParser(sst);
// rId2 found by processing the Workbook
// 根据 rId# 或 rSheet# 查找sheet
InputStream sheet2 = r.getSheet("rId" + sheetId);
sheetIndex++;
InputSource sheetSource = new InputSource(sheet2);
parser.parse(sheetSource);
sheet2.close();
pkg.close();
}
示例5: process
import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
/**
* 遍历 excel 文件
*/
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();
}
pkg.close();
}
示例6: parseXlsxFileAndWriteTmxBody
import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的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();
}
示例7: readRows
import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的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();
}
}
示例8: signUnencryptedOpcPackage
import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
private void signUnencryptedOpcPackage(InputStream tmpFileInputStream, SignatureConfig sc) throws InvalidFormatException, IOException, XMLSignatureException, MarshalException {
OPCPackage pkg = OPCPackage.open(tmpFileInputStream);
sc.setOpcPackage(pkg);
SignatureInfo si = new SignatureInfo();
si.setSignatureConfig(sc);
si.confirmSignature();
pkg.save(this.finalOutputStream);
pkg.close();
}
示例9: signEncryptedPackage
import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
private void signEncryptedPackage(InputStream tmpFileInputStream, SignatureConfig sc, String password) throws IOException, InvalidFormatException, FormatNotUnderstoodException, XMLSignatureException, MarshalException {
NPOIFSFileSystem poifsTemp = new NPOIFSFileSystem(tmpFileInputStream);
EncryptionInfo info = new EncryptionInfo(poifsTemp);
Decryptor d = Decryptor.getInstance(info);
try {
if (!d.verifyPassword(password)) {
throw new FormatNotUnderstoodException("Error: Cannot decrypt new Excel file (.xlsx) for signing. Invalid password");
}
// signing
OPCPackage pkg = OPCPackage.open(d.getDataStream(poifsTemp));
sc.setOpcPackage(pkg);
SignatureInfo si = new SignatureInfo();
si.setSignatureConfig(sc);
si.confirmSignature();
// encrypt again
Encryptor enc = info.getEncryptor();
enc.confirmPassword(password);
NPOIFSFileSystem poifs = new NPOIFSFileSystem();
OutputStream os = enc.getDataStream(poifs);
pkg.save(os);
pkg.close();
if (os!=null) {
os.close();
}
poifs.writeFilesystem(this.finalOutputStream);
if (poifs!=null) {
poifs.close();
}
if (poifsTemp!=null) {
poifsTemp.close();
}
} catch (GeneralSecurityException e) {
LOG.error(e);
throw new FormatNotUnderstoodException("Error: Cannot decrypt new Excel file (.xlsx) for signing.");
}
}
示例10: importFromXLSX
import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
public DenseObjectMatrix2D importFromXLSX(final File file, final int sheetNumber) throws InvalidFormatException,
IOException {
final OPCPackage pkg = OPCPackage.open(file);
final XSSFWorkbook workbook = new XSSFWorkbook(pkg);
final DenseObjectMatrix2D matrix = importFromWorkbook(workbook, sheetNumber);
pkg.close();
return matrix;
}
示例11: transformInternal
import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
@Override
protected void transformInternal(ContentReader reader,
ContentWriter writer,
TransformationOptions options) throws Exception
{
final String sourceMimetype = reader.getMimetype();
final String sourceExtension = getMimetypeService().getExtension(sourceMimetype);
final String targetMimetype = writer.getMimetype();
if (log.isDebugEnabled())
{
StringBuilder msg = new StringBuilder();
msg.append("Transforming from ").append(sourceMimetype)
.append(" to ").append(targetMimetype);
log.debug(msg.toString());
}
OPCPackage pkg = null;
try
{
File ooxmlTempFile = TempFileProvider.createTempFile(this.getClass().getSimpleName() + "_ooxml", sourceExtension);
reader.getContent(ooxmlTempFile);
// Load the file
pkg = OPCPackage.open(ooxmlTempFile.getPath());
// Does it have a thumbnail?
PackageRelationshipCollection rels =
pkg.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL);
if (rels.size() > 0)
{
// Get the thumbnail part
PackageRelationship tRel = rels.getRelationship(0);
PackagePart tPart = pkg.getPart(tRel);
// Write it to the target
InputStream tStream = tPart.getInputStream();
writer.putContent( tStream );
tStream.close();
}
else
{
log.debug("No thumbnail present in " + reader.toString());
throw new UnimportantTransformException(NO_THUMBNAIL_PRESENT_IN_FILE + targetMimetype);
}
}
catch (IOException e)
{
throw new AlfrescoRuntimeException("Unable to transform " + sourceExtension + " file.", e);
}
finally
{
if (pkg != null)
{
pkg.close();
}
}
}
示例12: testClosingFiles
import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
@Test
public void testClosingFiles() throws Exception {
OPCPackage o = OPCPackage.open(new File("src/test/resources/blank_cell_StringCellValue.xlsx"), PackageAccess.READ);
o.close();
}
示例13: main
import org.apache.poi.openxml4j.opc.OPCPackage; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String SAMPLE_PERSON_DATA_FILE_PATH = "src/test/resources/Sample-Person-Data.xlsx";
File file = new File(SAMPLE_PERSON_DATA_FILE_PATH);
InputStream inputStream = new FileInputStream(file);
// The package open is instantaneous, as it should be.
OPCPackage pkg = null;
try {
ExcelWorkSheetRowCallbackHandler sheetRowCallbackHandler =
new ExcelWorkSheetRowCallbackHandler(new ExcelRowContentCallback() {
@Override
public void processRow(int rowNum, Map<String, String> map) {
// Do any custom row processing here, such as save
// to database
// Convert map values, as necessary, to dates or
// parse as currency, etc
System.out.println("rowNum=" + rowNum + ", map=" + map);
}
});
pkg = OPCPackage.open(inputStream);
ExcelSheetCallback sheetCallback = new ExcelSheetCallback() {
private int sheetNumber = 0;
@Override
public void startSheet(int sheetNum, String sheetName) {
this.sheetNumber = sheetNum;
System.out.println("Started processing sheet number=" + sheetNumber
+ " and Sheet Name is '" + sheetName + "'");
}
@Override
public void endSheet() {
System.out.println("Processing completed for sheet number=" + sheetNumber);
}
};
System.out.println("Constructor: pkg, sheetRowCallbackHandler, sheetCallback");
ExcelReader example1 = new ExcelReader(pkg, sheetRowCallbackHandler, sheetCallback);
example1.process();
System.out.println("\nConstructor: filePath, sheetRowCallbackHandler, sheetCallback");
ExcelReader example2 =
new ExcelReader(SAMPLE_PERSON_DATA_FILE_PATH, sheetRowCallbackHandler, sheetCallback);
example2.process();
System.out.println("\nConstructor: file, sheetRowCallbackHandler, sheetCallback");
ExcelReader example3 = new ExcelReader(file, sheetRowCallbackHandler, null);
example3.process();
} catch (RuntimeException are) {
LOG.error(are.getMessage(), are.getCause());
} catch (InvalidFormatException ife) {
LOG.error(ife.getMessage(), ife.getCause());
} catch (IOException ioe) {
LOG.error(ioe.getMessage(), ioe.getCause());
} finally {
IOUtils.closeQuietly(inputStream);
try {
if (null != pkg) {
pkg.close();
}
} catch (IOException e) {
// just ignore IO exception
}
}
}