Search code examples
apache-poixlsxxssf

Is there a way to get all embedded objects in .xlsx file using xssf event mdel api


Is there a way to get all embedded objects in .xlsx file using xssf event model api?

Usermodel has the method workbook.getallembedds...similarly is there anything in eventmodel?

This is an example in usermodel.I want to implement the same functionality using eventusermodel.Kindly help.

 for (PackagePart pPart : workbook.getAllEmbedds()) {
 String contentType = pPart.getContentType(); 
 if (contentType.equals(------)

Instead of xssfworkbook(in usermodel), in the eventmodel code i have a containerObject of type OPCPackage.

@Gagravarr : Thanks for your reply. I tried using the method suggested by you...but im unable to get the contents of the embedded excel.Could you please help me find out where I am going wrong.Here is a part of the code:

      ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(container);
      XSSFReader xssfReader = new XSSFReader(container);

      XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator)xssfReader.getSheetsData();
      for(PackageRelationship rel : iter.getSheetPart().getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation()))
                  embedds.add(getTargetPart(rel));

          for (PackagePart pPart :getAllEmbedds()) {

              String contentType = pPart.getContentType();


              // Excel Workbook - OpenXML file format
               if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml")) {
                OPCPackage excelObject = OPCPackage.open(pPart.getInputStream());

`


Solution

  • Finally all I used was this!

      ArrayList<PackagePart> parts = container.getParts();
    
      for (PackagePart pPart :parts) {
    
      String contentType = pPart.getContentType();
    
    
     if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {