private void addImageToSheet(int colNumber, int rowNumber, HSSFSheet sheet,
String imageFile, double reqImageWidthMM, double reqImageHeightMM,
int resizeBehaviour) throws FileNotFoundException, IOException,
IllegalArgumentException {
HSSFRow row = null;
HSSFClientAnchor anchor = null;
HSSFPatriarch patriarch = null;
ClientAnchorDetail rowClientAnchorDetail = null;
ClientAnchorDetail colClientAnchorDetail = null;
// Validate the resizeBehaviour parameter.
if((resizeBehaviour != AddDimensionedImage.EXPAND_COLUMN) &&
(resizeBehaviour != AddDimensionedImage.EXPAND_ROW) &&
(resizeBehaviour != AddDimensionedImage.EXPAND_ROW_AND_COLUMN) &&
(resizeBehaviour != AddDimensionedImage.OVERLAY_ROW_AND_COLUMN)) {
throw new IllegalArgumentException("Invalid value passed to the " +
"resizeBehaviour parameter of AddDimensionedImage.addImageToSheet()");
}
// Call methods to calculate how the image and sheet should be
// manipulated to accomodate the image; columns and then rows.
colClientAnchorDetail = this.fitImageToColumns(sheet, colNumber,
reqImageWidthMM, resizeBehaviour);
rowClientAnchorDetail = this.fitImageToRows(sheet, rowNumber,
reqImageHeightMM, resizeBehaviour);
// Having determined if and how to resize the rows, columns and/or the
// image, create the HSSFClientAnchor object to position the image on
// the worksheet. Note how the two ClientAnchorDetail records are
// interrogated to recover the row/column co-ordinates and any insets.
// The first two parameters are not used currently but could be if the
// need arose to extend the functionality of this code by adding the
// ability to specify that a clear 'border' be placed around the image.
anchor = new HSSFClientAnchor(0,
0,
colClientAnchorDetail.getInset(),
rowClientAnchorDetail.getInset(),
(short)colClientAnchorDetail.getFromIndex(),
rowClientAnchorDetail.getFromIndex(),
(short)colClientAnchorDetail.getToIndex(),
rowClientAnchorDetail.getToIndex());
// For now, set the anchor type to do not move or resize the
// image as the size of the row/column is adjusted. This could easilly
// become another parameter passed to the method.
//anchor.setAnchorType(HSSFClientAnchor.DONT_MOVE_AND_RESIZE);
anchor.setAnchorType(HSSFClientAnchor.MOVE_AND_RESIZE);
// Now, add the picture to the workbook. Note that the type is assumed
// to be a JPEG/JPG, this could easily (and should) be parameterised
// however.
//int index = sheet.getWorkbook().addPicture(this.imageToBytes(imageFile),