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

StackOverflow https://stackoverflow.com/questions/7361022

  •  28-10-2019
  •  | 
  •  

سؤال

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());

`

هل كانت مفيدة؟

المحلول 2

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")) {

نصائح أخرى

Your best bet is probably just to enumerate all the package parts, and find the ones that interest you from that

Alternately, the logic to identify embedded parts attached to a given sheet is pretty simple:

    List<PackagePart> embedds = new LinkedList<PackagePart>();

    // Get the embeddings for the workbook
    for(PackageRelationship rel : sheet.getSheetPart().getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation()))
            embedds.add(getTargetPart(rel));

    for(PackageRelationship rel : sheet.getSheetPart().getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation()))
            embedds.add(getTargetPart(rel));

    return embedds;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top