C'è un modo per ottenere tutti gli oggetti incorporati nel file .xlsx utilizzando l'API di evento XSSF MDEL

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

  •  28-10-2019
  •  | 
  •  

Domanda

C'è un modo per ottenere tutti gli oggetti incorporati nel file .xlsx utilizzando l'API del modello di evento XSSF?

UserModel ha la cartella di lavoro del metodo.getAlleMbeddds ... Allo stesso modo c'è qualcosa in EventModel?

Questo è un esempio in UserModel. Voglio implementare la stessa funzionalità utilizzando EventUserModel. Aiuto.

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

Invece di XSSFWorkbook (in UserModel), nel codice EventModel ho un containerObject di tipo opcpackage.

@Gagravarr: grazie per la tua risposta. Ho provato a usare il metodo suggerito da te ... ma non sono in grado di ottenere il contenuto di Excel incorporato. Dovresti per favore aiutami a scoprire dove sto sbagliando. Ecco parte del codice:

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

`

È stato utile?

Soluzione 2

Finalmente tutto quello che ho usato è stato questo!

  ArrayList<PackagePart> parts = container.getParts();

  for (PackagePart pPart :parts) {

  String contentType = pPart.getContentType();


 if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {

Altri suggerimenti

La tua scommessa migliore è probabilmente solo per elencare tutte le parti del pacchetto e trovare quelli che ti interessano da quello

In alternativa, la logica per identificare le parti incorporate allegate a un determinato foglio è piuttosto semplice:

    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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top