Package org.apache.poi.ss.usermodel

Examples of org.apache.poi.ss.usermodel.ClientAnchor


    public void testOneSeriePlot() throws Exception {
        Workbook wb = new XSSFWorkbook();
        Sheet sheet = new SheetBuilder(wb, plotData).build();
        Drawing drawing = sheet.createDrawingPatriarch();
        ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
        Chart chart = drawing.createChart(anchor);

        ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
        ChartAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
View Full Code Here


                cell.setCellValue(colIndex * (rowIndex + 1));
            }
        }

        Drawing drawing = sheet.createDrawingPatriarch();
        ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);

        Chart chart = drawing.createChart(anchor);
        ChartLegend legend = chart.getOrCreateLegend();
        legend.setPosition(LegendPosition.TOP_RIGHT);

View Full Code Here

    public void testGetClientAnchor() {
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet();
        HSSFPatriarch drawing = sheet.createDrawingPatriarch();
        HSSFComment comment;
        ClientAnchor anchor;

        comment = drawing.createCellComment(new HSSFClientAnchor(101, 102, 103, 104, (short) 1, 2, (short) 3, 4));
        anchor = comment.getClientAnchor();
        assertEquals(101, anchor.getDx1());
        assertEquals(102, anchor.getDy1());
        assertEquals(103, anchor.getDx2());
        assertEquals(104, anchor.getDy2());
        assertEquals(1, anchor.getCol1());
        assertEquals(2, anchor.getRow1());
        assertEquals(3, anchor.getCol2());
        assertEquals(4, anchor.getRow2());

        comment = drawing.createCellComment(new HSSFClientAnchor());
        anchor = comment.getClientAnchor();
        assertEquals(0, anchor.getDx1());
        assertEquals(0, anchor.getDy1());
        assertEquals(0, anchor.getDx2());
        assertEquals(0, anchor.getDy2());
        assertEquals(0, anchor.getCol1());
        assertEquals(0, anchor.getRow1());
        assertEquals(0, anchor.getCol2());
        assertEquals(0, anchor.getRow2());
    }
View Full Code Here

     * @param scaleX the amount by which image width is multiplied relative to the original width.
     * @param scaleY the amount by which image height is multiplied relative to the original height.
     * @return the new Dimensions of the scaled picture in EMUs
     */
    public static Dimension setPreferredSize(Picture picture, double scaleX, double scaleY){
        ClientAnchor anchor = picture.getClientAnchor();
        boolean isHSSF = (anchor instanceof HSSFClientAnchor);
        PictureData data = picture.getPictureData();
        Sheet sheet = picture.getSheet();
       
        // in pixel
        Dimension imgSize = getImageDimension(new ByteArrayInputStream(data.getData()), data.getPictureType());
        // in emus
        Dimension anchorSize = ImageUtils.getDimensionFromAnchor(picture);
        final double scaledWidth = (scaleX == Double.MAX_VALUE)
            ? imgSize.getWidth() : anchorSize.getWidth()/EMU_PER_PIXEL * scaleX;
        final double scaledHeight = (scaleY == Double.MAX_VALUE)
            ? imgSize.getHeight() : anchorSize.getHeight()/EMU_PER_PIXEL * scaleY;

        double w = 0;
        int col2 = anchor.getCol1();
        int dx2 = 0;

        //space in the leftmost cell
        w = sheet.getColumnWidthInPixels(col2++);
        if (isHSSF) {
            w *= 1 - anchor.getDx1()/1024d;
        } else {
            w -= anchor.getDx1()/EMU_PER_PIXEL;
        }
       
        while(w < scaledWidth){
            w += sheet.getColumnWidthInPixels(col2++);
        }
       
        if(w > scaledWidth) {
            //calculate dx2, offset in the rightmost cell
            double cw = sheet.getColumnWidthInPixels(--col2);
            double delta = w - scaledWidth;
            if (isHSSF) {
                dx2 = (int)((cw-delta)/cw*1024);
            } else {
                dx2 = (int)((cw-delta)*EMU_PER_PIXEL);
            }
            if (dx2 < 0) dx2 = 0;
        }
        anchor.setCol2(col2);
        anchor.setDx2(dx2);

        double h = 0;
        int row2 = anchor.getRow1();
        int dy2 = 0;
       
        h = getRowHeightInPixels(sheet,row2++);
        if (isHSSF) {
            h *= 1 - anchor.getDy1()/256d;
        } else {
            h -= anchor.getDy1()/EMU_PER_PIXEL;
        }

        while(h < scaledHeight){
            h += getRowHeightInPixels(sheet,row2++);
        }
       
        if(h > scaledHeight) {
            double ch = getRowHeightInPixels(sheet,--row2);
            double delta = h - scaledHeight;
            if (isHSSF) {
                dy2 = (int)((ch-delta)/ch*256);
            } else {
                dy2 = (int)((ch-delta)*EMU_PER_PIXEL);
            }
            if (dy2 < 0) dy2 = 0;
        }

        anchor.setRow2(row2);
        anchor.setDy2(dy2);

        Dimension dim = new Dimension(
            (int)Math.round(scaledWidth*EMU_PER_PIXEL),
            (int)Math.round(scaledHeight*EMU_PER_PIXEL)
        );
View Full Code Here

     *
     * @param picture the picture containing the anchor
     * @return the dimensions in EMUs
     */
    public static Dimension getDimensionFromAnchor(Picture picture) {
        ClientAnchor anchor = picture.getClientAnchor();
        boolean isHSSF = (anchor instanceof HSSFClientAnchor);
        Sheet sheet = picture.getSheet();

        double w = 0;
        int col2 = anchor.getCol1();

        //space in the leftmost cell
        w = sheet.getColumnWidthInPixels(col2++);
        if (isHSSF) {
            w *= 1 - anchor.getDx1()/1024d;
        } else {
            w -= anchor.getDx1()/EMU_PER_PIXEL;
        }
       
        while(col2 < anchor.getCol2()){
            w += sheet.getColumnWidthInPixels(col2++);
        }
       
        if (isHSSF) {
            w += sheet.getColumnWidthInPixels(col2) * anchor.getDx2()/1024d;
        } else {
            w += anchor.getDx2()/EMU_PER_PIXEL;
        }

        double h = 0;
        int row2 = anchor.getRow1();
       
        h = getRowHeightInPixels(sheet,row2++);
        if (isHSSF) {
            h *= 1 - anchor.getDy1()/256d;
        } else {
            h -= anchor.getDy1()/EMU_PER_PIXEL;
        }

        while(row2 < anchor.getRow2()){
            h += getRowHeightInPixels(sheet,row2++);
        }
       
        if (isHSSF) {
            h += getRowHeightInPixels(sheet,row2) * anchor.getDy2()/256;
        } else {
            h += anchor.getDy2()/EMU_PER_PIXEL;
        }

        return new Dimension((int)w*EMU_PER_PIXEL, (int)h*EMU_PER_PIXEL);
    }
View Full Code Here

        HSSFSheet sheet = wb.createSheet();
        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
        CreationHelper ch = wb.getCreationHelper();

        ClientAnchor anchor = ch.createClientAnchor();
        anchor.setCol1(2);
        anchor.setCol2(5);
        anchor.setRow1(1);
        anchor.setRow2(6);
        patriarch.createPicture(anchor, indexEmf);
       
        anchor = ch.createClientAnchor();
        anchor.setCol1(2);
        anchor.setCol2(5);
        anchor.setRow1(10);
        anchor.setRow2(16);
        patriarch.createPicture(anchor, indexPng);

        anchor = ch.createClientAnchor();
        anchor.setCol1(6);
        anchor.setCol2(9);
        anchor.setRow1(1);
        anchor.setRow2(6);
        patriarch.createPicture(anchor, indexWmf);
       
       
        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
        byte pictureDataOut[] = wb.getAllPictures().get(0).getData();
View Full Code Here

    public void testGetClientAnchor() {
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet();
        XSSFDrawing drawing = sheet.createDrawingPatriarch();
        XSSFComment comment;
        ClientAnchor anchor;

        comment = drawing.createCellComment(new XSSFClientAnchor(101, 102, 103, 104, 1, 2, 3, 4));
        anchor = comment.getClientAnchor();
        assertEquals(0, anchor.getDx1());
        assertEquals(0, anchor.getDy1());
        assertEquals(0, anchor.getDx2());
        assertEquals(0, anchor.getDy2());
        assertEquals(1, anchor.getCol1());
        assertEquals(2, anchor.getRow1());
        assertEquals(3, anchor.getCol2());
        assertEquals(4, anchor.getRow2());

        comment = drawing.createCellComment(new XSSFClientAnchor());
        anchor = comment.getClientAnchor();
        assertEquals(0, anchor.getDx1());
        assertEquals(0, anchor.getDy1());
        assertEquals(0, anchor.getDx2());
        assertEquals(0, anchor.getDy2());
        assertEquals(1, anchor.getCol1());
        assertEquals(0, anchor.getRow1());
        assertEquals(3, anchor.getCol2());
        assertEquals(3, anchor.getRow2());
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.usermodel.ClientAnchor

Copyright © 2018 www.massapicom. 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.