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


Java OPCPackage.close方法代碼示例

本文整理匯總了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();
}
 
開發者ID:wuwz,項目名稱:ExcelKit,代碼行數:18,代碼來源:XlsxReader.java

示例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();
}
 
開發者ID:wuwz,項目名稱:ExcelKit,代碼行數:17,代碼來源:XlsxReader.java

示例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;
}
 
開發者ID:ansleliu,項目名稱:GraphicsViewJambi,代碼行數:19,代碼來源:ImportNetworkFromExcel.java

示例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();
}
 
開發者ID:RayleighChen,項目名稱:Improve,代碼行數:17,代碼來源:XxlsAbstract.java

示例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();
}
 
開發者ID:RayleighChen,項目名稱:Improve,代碼行數:22,代碼來源:XxlsAbstract.java

示例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();
}
 
開發者ID:heartsome,項目名稱:translationstudio8,代碼行數:26,代碼來源:Xlsx2TmxHelper.java

示例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();
    }
}
 
開發者ID:heartsome,項目名稱:translationstudio8,代碼行數:21,代碼來源:XlsxRowReader.java

示例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();
}
 
開發者ID:ZuInnoTe,項目名稱:hadoopoffice,代碼行數:10,代碼來源:MSExcelOOXMLSignUtil.java

示例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.");
    }
}
 
開發者ID:ZuInnoTe,項目名稱:hadoopoffice,代碼行數:39,代碼來源:MSExcelOOXMLSignUtil.java

示例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;
}
 
開發者ID:ujmp,項目名稱:universal-java-matrix-package,代碼行數:9,代碼來源:MatrixXLSXImporter.java

示例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();
        }
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:61,代碼來源:OOXMLThumbnailContentTransformer.java

示例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();
}
 
開發者ID:monitorjbl,項目名稱:excel-streaming-reader,代碼行數:6,代碼來源:StreamingReaderTest.java

示例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
      }
    }
  }
 
開發者ID:jeevatkm,項目名稱:excelReader,代碼行數:75,代碼來源:ExcelWorkSheetRowCallbackHandlerTest.java


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