Java Code Examples for org.apache.poi.hssf.usermodel.HSSFRow#getHeightInPoints()

The following examples show how to use org.apache.poi.hssf.usermodel.HSSFRow#getHeightInPoints() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XLSPrinter.java    From unitime with Apache License 2.0 5 votes vote down vote up
private ClientAnchorDetail fitImageToRows(HSSFSheet sheet, int rowNumber, double reqImageHeightMM, int resizeBehaviour) {
    double rowCoordinatesPerMM;
    int pictureHeightCoordinates;
    ClientAnchorDetail rowClientAnchorDetail = null;

    HSSFRow row = sheet.getRow(rowNumber);
    if (row == null) {
    	row = sheet.createRow(rowNumber);
    }

    double rowHeightMM = row.getHeightInPoints() / ConvertImageUnits.POINTS_PER_MILLIMETRE;

    if (rowHeightMM < reqImageHeightMM) {
        if (resizeBehaviour == EXPAND_ROW || resizeBehaviour == EXPAND_ROW_AND_COLUMN) {
        	row.setHeightInPoints((float)(reqImageHeightMM * ConvertImageUnits.POINTS_PER_MILLIMETRE));
            rowHeightMM = reqImageHeightMM;
            rowCoordinatesPerMM = ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS / rowHeightMM;
            pictureHeightCoordinates = (int)(reqImageHeightMM * rowCoordinatesPerMM);
            rowClientAnchorDetail = new ClientAnchorDetail(rowNumber, rowNumber, pictureHeightCoordinates);
        } else if (resizeBehaviour == OVERLAY_ROW_AND_COLUMN || resizeBehaviour == EXPAND_COLUMN) {
        	rowClientAnchorDetail = calculateRowLocation(sheet, rowNumber, reqImageHeightMM);
        }
    } else {
        rowCoordinatesPerMM = ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS / rowHeightMM;
        pictureHeightCoordinates = (int)(reqImageHeightMM * rowCoordinatesPerMM);
        rowClientAnchorDetail = new ClientAnchorDetail(rowNumber, rowNumber, pictureHeightCoordinates);
    }
    
    return rowClientAnchorDetail;
}
 
Example 2
Source File: XLSPrinter.java    From unitime with Apache License 2.0 5 votes vote down vote up
private ClientAnchorDetail calculateRowLocation(HSSFSheet sheet, int startingRow, double reqImageHeightMM) {
    ClientAnchorDetail clientAnchorDetail;
    HSSFRow row;
    double rowHeightMM = 0.0D;
    double totalRowHeightMM = 0.0D;
    double overlapMM;
    double rowCoordinatesPerMM;
    int toRow = startingRow;
    int inset;

    while (totalRowHeightMM < reqImageHeightMM) {
        row = sheet.getRow(toRow);
        if(row == null) {
            row = sheet.createRow(toRow);
        }
        rowHeightMM = row.getHeightInPoints() / ConvertImageUnits.POINTS_PER_MILLIMETRE;
        totalRowHeightMM += rowHeightMM;
        toRow++;
    }
    toRow--;

    if ((int)totalRowHeightMM == (int)reqImageHeightMM) {
        clientAnchorDetail = new ClientAnchorDetail(startingRow, toRow, ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS);
    } else {
        overlapMM = reqImageHeightMM - (totalRowHeightMM - rowHeightMM);
        if(overlapMM < 0) {
            overlapMM = 0.0D;
        }
        rowCoordinatesPerMM = ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS / rowHeightMM;
        inset = (int)(overlapMM * rowCoordinatesPerMM);
        clientAnchorDetail = new ClientAnchorDetail(startingRow, toRow, inset);
    }
    
    return clientAnchorDetail;
}
 
Example 3
Source File: AddDimensionedImage.java    From kbase-doc with Apache License 2.0 4 votes vote down vote up
/**
 * Determines whether the sheet's row should be re-sized to accomodate
 * the image, adjusts the rows height if necessary and creates then
 * returns a ClientAnchorDetail object that facilitates construction of
 * an HSSFClientAnchor that will fix the image on the sheet and establish
 * it's size.
 *
 * @param sheet A reference to the sheet that will 'contain' the image.
 * @param rowNumber A primtive int that contains the index number of a
 *                  row on the sheet.
 * @param reqImageHeightMM A primtive double that contains the required
 *                         height of the image in millimetres
 * @param resizeBehaviour A primitve int whose value will indicate how the
 *                        height of the row should be adjusted if the
 *                        required height of the image is greater than the
 *                        height of the row.
 * @return An instance of the ClientAnchorDetail class that will contain
 *         the index number of the row containing the cell whose top
 *         left hand corner also defines the top left hand corner of the
 *         image, the index number of the row containing the cell whose
 *         top left hand corner also defines the bottom right hand
 *         corner of the image and an inset that determines how far the
 *         bottom edge of the image can protrude into the next (lower)
 *         row - expressed as a specific number of co-ordinate positions.
 */
private ClientAnchorDetail fitImageToRows(HSSFSheet sheet, int rowNumber,
        double reqImageHeightMM, int resizeBehaviour) {
    double rowCoordinatesPerMM;
    int pictureHeightCoordinates;
    ClientAnchorDetail rowClientAnchorDetail = null;

    // Get the row and it's height
    HSSFRow row = sheet.getRow(rowNumber);
    if(row == null) {
        // Create row if it does not exist.
        row = sheet.createRow(rowNumber);
    }

    // Get the row's height in millimetres
    double rowHeightMM = row.getHeightInPoints() / ConvertImageUnits.POINTS_PER_MILLIMETRE;

    // Check that the row's height will accomodate the image at the required
    // dimensions. If the height of the row is LESS than the required height
    // of the image, decide how the application should respond - resize the
    // row or overlay the image across a series of rows.
    if(rowHeightMM < reqImageHeightMM) {
        if((resizeBehaviour == AddDimensionedImage.EXPAND_ROW) ||
           (resizeBehaviour == AddDimensionedImage.EXPAND_ROW_AND_COLUMN)) {
            row.setHeightInPoints((float)(reqImageHeightMM *
                    ConvertImageUnits.POINTS_PER_MILLIMETRE));
            rowHeightMM = reqImageHeightMM;
            rowCoordinatesPerMM = ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS /
                rowHeightMM;
            pictureHeightCoordinates = (int)(reqImageHeightMM * rowCoordinatesPerMM);
            rowClientAnchorDetail = new ClientAnchorDetail(rowNumber,
                    rowNumber, pictureHeightCoordinates);
        }
        // If the user has chosen to overlay both rows and columns or just
        // to expand ONLY the size of the columns, then calculate how to lay
        // the image out ver one or more rows.
        else if((resizeBehaviour == AddDimensionedImage.OVERLAY_ROW_AND_COLUMN) ||
                (resizeBehaviour == AddDimensionedImage.EXPAND_COLUMN)) {
            rowClientAnchorDetail = this.calculateRowLocation(sheet,
                    rowNumber, reqImageHeightMM);
        }
    }
    // Else, if the image is smaller than the space available
    else {
        rowCoordinatesPerMM = ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS /
                rowHeightMM;
        pictureHeightCoordinates = (int)(reqImageHeightMM * rowCoordinatesPerMM);
        rowClientAnchorDetail = new ClientAnchorDetail(rowNumber,
                    rowNumber, pictureHeightCoordinates);
    }
    return(rowClientAnchorDetail);
}
 
Example 4
Source File: AddDimensionedImage.java    From kbase-doc with Apache License 2.0 4 votes vote down vote up
/**
 * If the image is to overlie more than one rows, calculations need to be
 * performed to determine how many rows and whether the image will
 * overlie just a part of one row in order to be presented at the
 * required size.
 *
 * @param sheet The sheet that will 'contain' the image.
 * @param startingRow A primitive int whose value is the index of the row
 *                    that contains the cell whose top left hand corner
 *                    should be aligned with the top left hand corner of
 *                    the image.
 * @param reqImageHeightMM A primitive double whose value will indicate the
 *                         required height of the image in millimetres.
 * @return An instance of the ClientAnchorDetail class that will contain
 *         the index number of the row containing the cell whose top
 *         left hand corner also defines the top left hand corner of the
 *         image, the index number of the row containing the cell whose top
 *         left hand corner also defines the bottom right hand corner of
 *         the image and an inset that determines how far the bottom edge
 *         can protrude into the next (lower) row - expressed as a specific
 *         number of co-ordinate positions.
 */
private ClientAnchorDetail calculateRowLocation(HSSFSheet sheet,
        int startingRow, double reqImageHeightMM) {
    ClientAnchorDetail clientAnchorDetail;
    HSSFRow row;
    double rowHeightMM = 0.0D;
    double totalRowHeightMM = 0.0D;
    double overlapMM;
    double rowCoordinatesPerMM;
    int toRow = startingRow;
    int inset;

    // Step through the rows in the sheet and accumulate a total of their
    // heights.
    while(totalRowHeightMM < reqImageHeightMM) {
        row = sheet.getRow(toRow);
        // Note, if the row does not already exist on the sheet then create
        // it here.
        if(row == null) {
            row = sheet.createRow(toRow);
        }
        // Get the row's height in millimetres and add to the running total.
        rowHeightMM = row.getHeightInPoints() /
                ConvertImageUnits.POINTS_PER_MILLIMETRE;
        totalRowHeightMM += rowHeightMM;
        toRow++;
    }
    // Owing to the way the loop above works, the rowNumber will have been
    // incremented one row too far. Undo that here.
    toRow--;
    // Check to see whether the image should occupy an exact number of
    // rows. If so, build the ClientAnchorDetail record to point
    // to those rows and with an inset of the total number of co-ordinate
    // position in the row.
    //
    // To overcome problems that can occur with comparing double values for
    // equality, cast both to int(s) to truncate the value; VERY crude and
    // I do not really like it!!
    if((int)totalRowHeightMM == (int)reqImageHeightMM) {
        clientAnchorDetail = new ClientAnchorDetail(startingRow, toRow,
                ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS);
    }
    else {
        // Calculate how far the image will project into the next row. Note
        // that the height of the last row assessed is subtracted from the
        // total height of all rows assessed so far.
        overlapMM = reqImageHeightMM - (totalRowHeightMM - rowHeightMM);

        // To prevent an exception being thrown when the required width of
        // the image is very close indeed to the column size.
        if(overlapMM < 0) {
            overlapMM = 0.0D;
        }

        rowCoordinatesPerMM = ConvertImageUnits.TOTAL_ROW_COORDINATE_POSITIONS /
                rowHeightMM;
        inset = (int)(overlapMM * rowCoordinatesPerMM);
        clientAnchorDetail = new ClientAnchorDetail(startingRow,
                    toRow, inset);
    }
    return(clientAnchorDetail);
}