Example usage for org.apache.poi.hssf.usermodel HSSFClientAnchor setDy1

List of usage examples for org.apache.poi.hssf.usermodel HSSFClientAnchor setDy1

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFClientAnchor setDy1.

Prototype

@Override
    public void setDy1(int dy1) 

Source Link

Usage

From source file:com.haulmont.yarg.formatters.impl.xls.HSSFPicturesHelper.java

License:Apache License

public static void searchForAnchors(List escherRecords, List<HSSFClientAnchor> pictures) {
    Iterator recordIter = escherRecords.iterator();
    HSSFClientAnchor anchor = null;
    while (recordIter.hasNext()) {
        Object obj = recordIter.next();
        if (obj instanceof EscherRecord) {
            EscherRecord escherRecord = (EscherRecord) obj;
            if (escherRecord instanceof EscherClientAnchorRecord) {
                EscherClientAnchorRecord anchorRecord = (EscherClientAnchorRecord) escherRecord;
                if (anchor == null)
                    anchor = new HSSFClientAnchor();
                anchor.setDx1(anchorRecord.getDx1());
                anchor.setDx2(anchorRecord.getDx2());
                anchor.setDy1(anchorRecord.getDy1());
                anchor.setDy2(anchorRecord.getDy2());
                anchor.setRow1(anchorRecord.getRow1());
                anchor.setRow2(anchorRecord.getRow2());
                anchor.setCol1(anchorRecord.getCol1());
                anchor.setCol2(anchorRecord.getCol2());
            }/*from   w ww  . ja va  2 s. com*/
            // Recursive call.
            searchForAnchors(escherRecord.getChildRecords(), pictures);
        }
    }
    if (anchor != null)
        pictures.add(anchor);
}

From source file:org.alanwilliamson.openbd.plugin.spreadsheet.functions.SpreadsheetAddImage.java

License:Open Source License

public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
    cfSpreadSheetData spreadsheet = (cfSpreadSheetData) parameters.get(2);
    String imgPath = parameters.get(1).getString();
    String[] anchor = parameters.get(0).getString().split(",");

    // Check the anchor
    if (anchor.length != 4 && anchor.length != 8)
        throwException(_session, "Invalid Anchor parameter. Must be 4 or 8 comma separated numbers");

    // Determine the file type
    String fileExt = imgPath.substring(imgPath.lastIndexOf(".") + 1).toLowerCase();
    int imgTypeIndex = 0;
    if (fileExt.equals("dib")) {
        imgTypeIndex = Workbook.PICTURE_TYPE_DIB;
    } else if (fileExt.equals("jpg")) {
        imgTypeIndex = Workbook.PICTURE_TYPE_JPEG;
    } else if (fileExt.equals("emf")) {
        imgTypeIndex = Workbook.PICTURE_TYPE_EMF;
    } else if (fileExt.equals("pict")) {
        imgTypeIndex = Workbook.PICTURE_TYPE_PICT;
    } else if (fileExt.equals("png")) {
        imgTypeIndex = Workbook.PICTURE_TYPE_PNG;
    } else if (fileExt.equals("wmf")) {
        imgTypeIndex = Workbook.PICTURE_TYPE_WMF;
    } else/*from  www .  j  a va  2s .  c  o m*/
        throwException(_session, "Unknown file type: " + imgPath);

    // Read the file
    FileInputStream fs = null;
    byte[] fileBuffer = null;
    try {
        fs = new FileInputStream(imgPath);
        fileBuffer = org.apache.poi.util.IOUtils.toByteArray(fs);
    } catch (Exception fe) {
        throwException(_session, "Unable to read file: " + imgPath);
    } finally {
        try {
            fs.close();
        } catch (IOException e) {
        }
    }

    // Add the picture
    int imageIndex = spreadsheet.getWorkBook().addPicture(fileBuffer, imgTypeIndex);

    HSSFClientAnchor clientAnchor = new HSSFClientAnchor();
    if (anchor.length == 4) {
        clientAnchor.setRow1(Integer.valueOf(anchor[0]) - 1);
        clientAnchor.setCol1(Integer.valueOf(anchor[1]) - 1);
        clientAnchor.setRow2(Integer.valueOf(anchor[2]) - 1);
        clientAnchor.setCol2(Integer.valueOf(anchor[3]) - 1);
    } else {
        clientAnchor.setDx1(Integer.valueOf(anchor[0]) - 1);
        clientAnchor.setDy1(Integer.valueOf(anchor[1]) - 1);
        clientAnchor.setDx2(Integer.valueOf(anchor[2]) - 1);
        clientAnchor.setDy2(Integer.valueOf(anchor[3]) - 1);

        clientAnchor.setRow1(Integer.valueOf(anchor[4]) - 1);
        clientAnchor.setCol1(Integer.valueOf(anchor[5]) - 1);
        clientAnchor.setRow2(Integer.valueOf(anchor[6]) - 1);
        clientAnchor.setCol2(Integer.valueOf(anchor[7]) - 1);
    }

    // finalise the image to the sheet
    spreadsheet.getActiveSheet().createDrawingPatriarch().createPicture(clientAnchor, imageIndex);

    return cfBooleanData.TRUE;
}

From source file:org.seasar.fisshplate.core.element.Picture.java

License:Apache License

/**
 * ???//from w w  w.  j a v a2s  .  co  m
 *
 * @param width
 * @param height
 * @param cellNo
 * @param rowNo
 * @param rowRangeIntVal
 * @param cellRangeIntVal
 * @return
 */
private ClientAnchor createAnchor(int width, int height, int cellNo, int rowNo, int cellRangeIntVal,
        int rowRangeIntVal) {
    HSSFClientAnchor anchor = new HSSFClientAnchor();
    // TODO ????????
    anchor.setDx1(0);
    anchor.setDx2(0);
    anchor.setDy1(0);
    anchor.setDy2(255);

    int fromCellNo = cellNo;
    int toCellNo = cellNo + cellRangeIntVal;
    int fromRowNo = rowNo;
    int toRowNo = rowNo + rowRangeIntVal;

    anchor.setCol1((short) fromCellNo);
    anchor.setCol2((short) toCellNo);
    anchor.setRow1(fromRowNo);
    anchor.setRow2(toRowNo);
    anchor.setAnchorType(2);
    return anchor;
}