Examples of POIXMLDocumentPart


Examples of org.apache.poi.POIXMLDocumentPart

        assertEquals(3,xwpfHeader.getAllPictures().size());
      assertEquals(5,doc.getAllPackagePictures().size());
     
      byte[] nature1 = XWPFTestDataSamples.getImage("nature1.jpg");
      String id = doc.addPictureData(nature1, Document.PICTURE_TYPE_JPEG);
      POIXMLDocumentPart part1 = xwpfHeader.getRelationById("rId1");
      XWPFPictureData part2 = (XWPFPictureData) doc.getRelationById(id);
      assertSame(part1,part2);
     
      doc.getPackage().revert();
  }
View Full Code Here

Examples of org.apache.poi.POIXMLDocumentPart

     * @param blipID
     * @return XWPFPictureData of a specificID
     * @throws Exception
     */
    public XWPFPictureData getPictureDataByID(String blipID) {
        POIXMLDocumentPart relatedPart = getRelationById(blipID);
        if (relatedPart != null && relatedPart instanceof XWPFPictureData) {
            return (XWPFPictureData) relatedPart;
        }
        return null;  
    }
View Full Code Here

Examples of org.apache.poi.POIXMLDocumentPart

     */
    private int getRelationIndex(XWPFRelation relation) {
        List<POIXMLDocumentPart> relations = getRelations();
        int i = 1;
        for (Iterator<POIXMLDocumentPart> it = relations.iterator(); it.hasNext() ; ) {
           POIXMLDocumentPart item = it.next();
           if (item.getPackageRelationship().getRelationshipType().equals(relation.getRelation())) {
              i++;
           }
        }
        return i;
    }
View Full Code Here

Examples of org.apache.poi.POIXMLDocumentPart

     * returns the PictureData by blipID
     * @param blipID
     * @return XWPFPictureData of a specificID
     */
    public XWPFPictureData getPictureDataByID(String blipID) {
        POIXMLDocumentPart relatedPart = getRelationById(blipID);
        if (relatedPart instanceof XWPFPictureData) {
            XWPFPictureData xwpfPicData = (XWPFPictureData) relatedPart;
            return xwpfPicData;
        }
        return null;
View Full Code Here

Examples of org.apache.poi.POIXMLDocumentPart

    /**
     *
     * @return the XMLSlideShow this sheet belongs to
     */
    public XMLSlideShow getSlideShow() {
        POIXMLDocumentPart p = getParent();
        while(p != null) {
            if(p instanceof XMLSlideShow){
                return (XMLSlideShow)p;
            }
            p = p.getParent();
        }
        throw new IllegalStateException("SlideShow was not found");
    }
View Full Code Here

Examples of org.apache.poi.POIXMLDocumentPart

        }

        if(chart == null) throw new IllegalStateException("chart not found in the template");

        // embedded Excel workbook that holds the chart data
        POIXMLDocumentPart xlsPart = chart.getRelations().get(0);
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet();

        CTChart ctChart = chart.getCTChart();
        CTPlotArea plotArea = ctChart.getPlotArea();

        CTPieChart pieChart = plotArea.getPieChartArray(0);
        //Pie Chart Series
        CTPieSer ser = pieChart.getSerArray(0);

        // Series Text
        CTSerTx tx = ser.getTx();
        tx.getStrRef().getStrCache().getPtArray(0).setV(chartTitle);
        sheet.createRow(0).createCell(1).setCellValue(chartTitle);
        String titleRef = new CellReference(sheet.getSheetName(), 0, 1, true, true).formatAsString();
        tx.getStrRef().setF(titleRef);


        // Category Axis Data
        CTAxDataSource cat = ser.getCat();
        CTStrData strData = cat.getStrRef().getStrCache();

        // Values
        CTNumDataSource valSrc = ser.getVal();
        CTNumData numData = valSrc.getNumRef().getNumCache();

        strData.setPtArray(null)// unset old axis text
        numData.setPtArray(null)// unset old values

        Map<String, Double> pieModel = new LinkedHashMap<String, Double>();
        pieModel.put("First", 1.0);
        pieModel.put("Second", 3.0);
        pieModel.put("Third", 4.0);

        // set model
        int idx = 0;
        int rownum = 1;
        for(String key : pieModel.keySet()){
            double val = pieModel.get(key);

            CTNumVal numVal = numData.addNewPt();
            numVal.setIdx(idx);
            numVal.setV("" + val);

            CTStrVal sVal = strData.addNewPt();
            sVal.setIdx(idx);
            sVal.setV(key);

            idx++;
            XSSFRow row = sheet.createRow(rownum++);
            row.createCell(0).setCellValue(key);
            row.createCell(1).setCellValue(val);
        }
        numData.getPtCount().setVal(idx);
        strData.getPtCount().setVal(idx);

        String numDataRange = new CellRangeAddress(1, rownum-1, 1, 1).formatAsString(sheet.getSheetName(), true);
        valSrc.getNumRef().setF(numDataRange);
        String axisDataRange = new CellRangeAddress(1, rownum-1, 0, 0).formatAsString(sheet.getSheetName(), true);
        cat.getStrRef().setF(axisDataRange);

        // updated the embedded workbook with the data
        OutputStream xlsOut = xlsPart.getPackagePart().getOutputStream();
        wb.write(xlsOut);
        xlsOut.close();

    }
View Full Code Here

Examples of org.apache.poi.POIXMLDocumentPart

            // return null if Blip data is missing
            return null;
        }

        String blipId = blipProps.getBlip().getEmbed();
        POIXMLDocumentPart part = run.getParent().getPart();
        if (part != null)
        {
            POIXMLDocumentPart relatedPart = part.getRelationById(blipId);
            if (relatedPart instanceof XWPFPictureData) {
                return (XWPFPictureData) relatedPart;
            }
        }
        return null;
View Full Code Here

Examples of org.apache.poi.POIXMLDocumentPart

        //  feature of the file format yet
        this.doc = doc;
        for(int i=0; i<sectPr.sizeOfHeaderReferenceArray(); i++) {
            // Get the header
            CTHdrFtrRef ref = sectPr.getHeaderReferenceArray(i);
            POIXMLDocumentPart relatedPart = doc.getRelationById(ref.getId());
            XWPFHeader hdr = null;
            if (relatedPart != null && relatedPart instanceof XWPFHeader) {
                hdr = (XWPFHeader) relatedPart;
            }
            // Assign it
            Enum type = ref.getType();
            assignHeader(hdr, type);
        }
        for(int i=0; i<sectPr.sizeOfFooterReferenceArray(); i++) {
            // Get the footer
            CTHdrFtrRef ref = sectPr.getFooterReferenceArray(i);
            POIXMLDocumentPart relatedPart = doc.getRelationById(ref.getId());
            XWPFFooter ftr = null;
            if (relatedPart != null && relatedPart instanceof XWPFFooter)
            {
                ftr = (XWPFFooter) relatedPart;
            }
View Full Code Here

Examples of org.apache.poi.POIXMLDocumentPart

    private int getRelationIndex(XWPFRelation relation) {
        List<POIXMLDocumentPart> relations = doc.getRelations();
        int i = 1;
        for (Iterator<POIXMLDocumentPart> it = relations.iterator(); it.hasNext() ; ) {
            POIXMLDocumentPart item = it.next();
            if (item.getPackageRelationship().getRelationshipType().equals(relation.getRelation())) {
                i++; 
            }
        }
        return i;
    }
View Full Code Here

Examples of org.apache.poi.POIXMLDocumentPart

     * @param blipID
     * @return XWPFPictureData of a specificID
     * @throws Exception
     */
    public XWPFPictureData getPictureDataByID(String blipID) {
        POIXMLDocumentPart relatedPart = getRelationById(blipID);
        if (relatedPart != null && relatedPart instanceof XWPFPictureData) {
            return (XWPFPictureData) relatedPart;
        }
        return null;  
    }
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.