Examples of EmbeddedPackagePart


Examples of org.docx4j.openpackaging.parts.WordprocessingML.EmbeddedPackagePart

       
    /*
     * Get the spreadsheet and find the cell values that need to be updated
     */
   
    EmbeddedPackagePart epp  = (EmbeddedPackagePart) ppt
      .getParts().get(new PartName(xlsPartName));
   
    if (epp==null) {
      throw new Docx4JException("Could find EmbeddedPackagePart: " + xlsPartName);
    }
   
    InputStream is = BufferUtil.newInputStream(epp.getBuffer());
   
    SpreadsheetMLPackage spreadSheet = (SpreadsheetMLPackage) SpreadsheetMLPackage.load(is);

    Map<PartName,Part> partsMap = spreadSheet.getParts().getParts();    
    Iterator<Entry<PartName, Part>> it = partsMap.entrySet().iterator();

    while(it.hasNext()) {
      Map.Entry<PartName, Part> pairs = it.next();
     
      if (partsMap.get(pairs.getKey()) instanceof WorksheetPart) {
       
        WorksheetPart wsp = (WorksheetPart) partsMap.get(pairs.getKey()) ;
       
        List<Row> rows = wsp.getJaxbElement().getSheetData().getRow();

        for (Row row : rows) {
          List<Cell> cells = row.getC();
          for (Cell cell : cells)
          {
            if (cell.getR().equals("B2") && cell.getV() != null) {
              System.out.println("B2 CELL VAL: " + cell.getV());
              // change the B2 cell value
              cell.setT(STCellType.STR);
              cell.setV(firstValue);
            }
            else if (cell.getR().equals("B3") && cell.getV() != null) {
              System.out.println("B3 CELL VAL: " + cell.getV());
              // Change the B3 cell value
              cell.setT(STCellType.STR);
              cell.setV(secondValue);
            }
          }         
        }
      }
    }

    /*
     * Convert the Spreadsheet to a binary format, set it on the
     * EmbeddedPackagePart, add it back onto the deck and save to a file.
     * 
     */   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
   
    SaveToZipFile saver = new SaveToZipFile(spreadSheet);

    saver.save(baos);
    epp.setBinaryData(baos.toByteArray());

    // Write the new file to disk
    ppt.save(new java.io.File(outputfilepath));

    System.out.println("\n\n done .. saved " + outputfilepath);
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.EmbeddedPackagePart

      afip.setContentType(new ContentType(contentType));
      return afip;
     
    } else if (rel!=null && rel.getType().equals(Namespaces.EMBEDDED_PKG) ) {
     
      EmbeddedPackagePart epp = new EmbeddedPackagePart(new PartName(partName) );
      epp.setContentType(new ContentType(contentType));
      return epp;

    } else if (rel!=null && rel.getType().equals(Namespaces.OLE_OBJECT) ) {
     
      OleObjectBinaryPart olePart = new OleObjectBinaryPart(new PartName(partName));
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.EmbeddedPackagePart

       
    /*
     * Get the spreadsheet and find the cell values that need to be updated
     */
   
    EmbeddedPackagePart epp  = (EmbeddedPackagePart) ppt
      .getParts().get(new PartName(xlsPartName));
   
    if (epp==null) {
      throw new Docx4JException("Could find EmbeddedPackagePart: " + xlsPartName);
    }
   
    InputStream is = BufferUtil.newInputStream(epp.getBuffer());
   
    SpreadsheetMLPackage spreadSheet = (SpreadsheetMLPackage) SpreadsheetMLPackage.load(is);

    Map<PartName,Part> partsMap = spreadSheet.getParts().getParts();    
    Iterator<Entry<PartName, Part>> it = partsMap.entrySet().iterator();

    while(it.hasNext()) {
      Map.Entry<PartName, Part> pairs = it.next();
     
      if (partsMap.get(pairs.getKey()) instanceof WorksheetPart) {
       
        WorksheetPart wsp = (WorksheetPart) partsMap.get(pairs.getKey()) ;
       
        List<Row> rows = wsp.getJaxbElement().getSheetData().getRow();

        for (Row row : rows) {
          List<Cell> cells = row.getC();
          for (Cell cell : cells)
          {
            if (cell.getR().equals("B2") && cell.getV() != null) {
              System.out.println("B2 CELL VAL: " + cell.getV());
              // change the B2 cell value
              cell.setT(STCellType.STR);
              cell.setV(firstValue);
            }
            else if (cell.getR().equals("B3") && cell.getV() != null) {
              System.out.println("B3 CELL VAL: " + cell.getV());
              // Change the B3 cell value
              cell.setT(STCellType.STR);
              cell.setV(secondValue);
            }
          }         
        }
      }
    }

    /*
     * Convert the Spreadsheet to a binary format, set it on the
     * EmbeddedPackagePart, add it back onto the deck and save to a file.
     * 
     */   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
   
    SaveToZipFile saver = new SaveToZipFile(spreadSheet);

    saver.save(baos);
    epp.setBinaryData(baos.toByteArray());

    // Write the new file to disk
    ppt.save(new java.io.File(outputfilepath));

    System.out.println("\n\n done .. saved " + outputfilepath);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.