*/
public void addImageToSheet(int colNumber, int rowNumber, Sheet sheet, Drawing drawing,
URL imageFile, double reqImageWidthMM, double reqImageHeightMM,
int resizeBehaviour) throws IOException,
IllegalArgumentException {
ClientAnchor anchor = null;
ClientAnchorDetail rowClientAnchorDetail = null;
ClientAnchorDetail colClientAnchorDetail = null;
int imageType = 0;
// 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 ClientAnchor 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 = sheet.getWorkbook().getCreationHelper().createClientAnchor();
anchor.setDx1(0);
anchor.setDy1(0);
anchor.setDx2(colClientAnchorDetail.getInset());
anchor.setDy2(rowClientAnchorDetail.getInset());
anchor.setCol1(colClientAnchorDetail.getFromIndex());
anchor.setRow1(rowClientAnchorDetail.getFromIndex());
anchor.setCol2(colClientAnchorDetail.getToIndex());
anchor.setRow2(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. Please read the note
// above regarding the behaviour of image resizing.
anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE);
// Now, add the picture to the workbook. Note that unlike the similar
// method in the HSSF Examples section, the image type is checked. First,
// the image files location is identified by interrogating the URL passed
// to the method, the images type is identified before it is added to the