Example usage for org.apache.poi.hssf.usermodel HSSFSheet getColumnWidth

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getColumnWidth

Introduction

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

Prototype

@Override
public int getColumnWidth(int columnIndex) 

Source Link

Document

get the width (in units of 1/256th of a character width )

Usage

From source file:org.gbif.portal.web.view.ExcelView.java

License:Open Source License

/**
 * @see org.springframework.web.servlet.view.document.AbstractExcelView#buildExcelDocument(java.util.Map, org.apache.poi.hssf.usermodel.HSSFWorkbook, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*from  w w w  .  ja v  a 2  s  . co m*/
@SuppressWarnings("unchecked")
protected void buildExcelDocument(Map model, HSSFWorkbook workbook, HttpServletRequest request,
        HttpServletResponse response) {

    Locale locale = RequestContextUtils.getLocale(request);

    //create results sheet
    String sheetTitle = messageSource.getMessage(resultsSheetTitleI18nKey, null, locale);
    HSSFSheet resultsSheet = workbook.createSheet(sheetTitle);
    resultsSheet.setDefaultColumnWidth((short) (defaultColumnWidth));

    //create a titles style
    HSSFCellStyle titlesStyle = workbook.createCellStyle();
    titlesStyle.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
    titlesStyle.setFillBackgroundColor(HSSFColor.DARK_GREEN.index);
    HSSFFont font = workbook.createFont();
    font.setColor(HSSFColor.WHITE.index);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    titlesStyle.setFont(font);

    //create a hyperlink style
    HSSFCellStyle hyperlinkStyle = workbook.createCellStyle();
    HSSFFont hyperLinkFont = workbook.createFont();
    hyperLinkFont.setColor(HSSFColor.BLUE.index);
    hyperlinkStyle.setFont(hyperLinkFont);

    //reused cell reference
    HSSFCell cell = null;

    //write results sheet
    List<Field> fields = (List<Field>) request.getAttribute("requestedFields");
    List results = (List) request.getAttribute("results");

    int currentRow = 0;

    //column headings
    for (int i = 0; i < fields.size(); i++) {
        cell = getCell(resultsSheet, currentRow, i);
        cell.setCellStyle(titlesStyle);
        String title = messageSource.getMessage(fields.get(i).getFieldI18nNameKey(), null, locale);
        setText(cell, title);
        short titleLength = (short) (title.length() * charWidth);
        short columnWidth = resultsSheet.getColumnWidth((short) i);
        //update column width for long columns
        if (columnWidth < titleLength) {
            resultsSheet.setColumnWidth((short) i, (short) (titleLength));
        }
    }

    currentRow++;
    //results
    for (int i = 0; i < results.size(); i++) {

        Object result = results.get(i);

        for (int j = 0; j < fields.size(); j++) {

            Field field = fields.get(j);
            cell = getCell(resultsSheet, currentRow, j);

            try {
                short textWidth = defaultColumnWidth;
                String propertyValue = field.getRenderValue(request, messageSource, locale, result);
                if (propertyValue != null)
                    setText(cell, propertyValue);
                if (field instanceof UrlField) {
                    if (propertyValue != null && propertyValue.length() < urlMaxLength) {
                        String linkFormula = "HYPERLINK(\"" + propertyValue + "\")";
                        cell.setCellFormula(linkFormula);
                        cell.setCellStyle(hyperlinkStyle);
                    }
                }
                if (propertyValue != null) {

                    int textWidthInt = propertyValue.length() * charWidth;
                    if (textWidthInt > 32768) {
                        textWidth = Short.MAX_VALUE;
                    } else {
                        textWidth = (short) textWidthInt;
                    }
                }

                //update column width for long columns
                short columnWidth = resultsSheet.getColumnWidth((short) j);

                if (textWidth > columnWidth) {
                    resultsSheet.setColumnWidth((short) j, (short) textWidth);
                }
            } catch (Exception e) {
                logger.warn(e.getMessage(), e);
            }
        }
        currentRow++;
    }

    //set up details sheet
    HSSFSheet detailsSheet = workbook
            .createSheet(messageSource.getMessage(detailsSheetTitleI18nKey, null, locale));
    detailsSheet.setColumnWidth((short) 0, (short) 6000);
    detailsSheet.setColumnWidth((short) 1, (short) Short.MAX_VALUE);
    ;
    List<FilterDTO> filters = (List) request.getAttribute("filters");
    CriteriaDTO criteria = (CriteriaDTO) request.getAttribute("criteria");
    String query = FilterUtils.getQueryDescription(filters, criteria, messageSource, locale);
    cell = getCell(detailsSheet, 0, 0);
    cell.setCellStyle(titlesStyle);
    setText(cell, messageSource.getMessage("occurrence.search.description", null, locale));
    cell = getCell(detailsSheet, 0, 1);
    setText(cell, query);
    //add url for search
    cell = getCell(detailsSheet, 1, 0);
    cell.setCellStyle(titlesStyle);
    setText(cell, messageSource.getMessage("occurrence.search.url", null, locale));
    cell = getCell(detailsSheet, 1, 1);
    cell.setCellStyle(hyperlinkStyle);
    String url = "http://" + request.getHeader("host") + request.getContextPath() + "/occurrences/search.htm?"
            + CriteriaUtil.getUrl(criteria);
    setText(cell, url);
    //there is a formula limit in Excel of 255 characters
    if (url != null && url.length() < urlMaxLength) {
        String link = "HYPERLINK(\"" + url + "\")";
        cell.setCellFormula(link);
    }
    //add url for download page
    cell = getCell(detailsSheet, 2, 0);
    cell.setCellStyle(titlesStyle);
    setText(cell, messageSource.getMessage("occurrence.search.download.url", null, locale));
    cell = getCell(detailsSheet, 2, 1);
    cell.setCellStyle(hyperlinkStyle);
    String downloadurl = "http://" + request.getHeader("host") + request.getContextPath()
            + "/occurrences/download.htm?" + CriteriaUtil.getUrl(criteria);
    setText(cell, downloadurl);
    if (downloadurl != null && downloadurl.length() < urlMaxLength) {
        String link = "HYPERLINK(\"" + downloadurl + "\")";
        cell.setCellFormula(link);
    }
    //add date for this download
    cell = getCell(detailsSheet, 3, 0);
    cell.setCellStyle(titlesStyle);
    setText(cell, messageSource.getMessage("occurrence.search.download.date", null, locale));
    cell = getCell(detailsSheet, 3, 1);
    SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
    setText(cell, sdf.format(new Date(System.currentTimeMillis())));
}

From source file:org.goobi.production.flow.helper.SearchResultHelper.java

License:Open Source License

@SuppressWarnings("deprecation")
public HSSFWorkbook getResult(List<SearchColumn> columnList, String filter, String order,
        boolean showClosedProcesses, boolean showArchivedProjects) {
    List<SearchColumn> sortedList = new ArrayList<>(columnList.size());
    for (SearchColumn sc : columnList) {
        if (!sc.getTableName().startsWith("metadata")) {
            sortedList.add(sc);// w w  w .j  a v  a2  s .c o m
        }
    }
    for (SearchColumn sc : columnList) {
        if (sc.getTableName().startsWith("metadata")) {
            sortedList.add(sc);
        }
    }
    columnList = sortedList;

    @SuppressWarnings("rawtypes")
    List list = search(columnList, filter, order, showClosedProcesses, showArchivedProjects);

    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Search results");

    // create title row
    int titleColumnNumber = 0;
    HSSFRow title = sheet.createRow(0);
    int columnNumber = 0;
    for (SearchColumn sc : columnList) {
        HSSFCell titleCell = title.createCell(titleColumnNumber++);
        titleCell.setCellValue(Helper.getTranslation(sc.getValue()));
        HSSFCellStyle cellStyle = wb.createCellStyle();
        HSSFFont cellFont = wb.createFont();
        cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        cellStyle.setFont(cellFont);
        titleCell.setCellStyle(cellStyle);
    }

    int rowNumber = 1;
    for (Object obj : list) {
        Object[] objArr = (Object[]) obj;
        HSSFRow row = sheet.createRow(rowNumber++);
        columnNumber = 0;
        for (Object entry : objArr) {
            HSSFCell cell = row.createCell(columnNumber++);
            if (entry != null) {
                cell.setCellValue(((String) entry).replace("\"", ""));
            } else {
                cell.setCellValue("");
            }
        }
    }

    sheet.createFreezePane(0, 1);
    for (int i = 0; i < columnList.size(); i++) {
        sheet.autoSizeColumn(i);
        if (sheet.getColumnWidth(i) > 15000) {
            sheet.setColumnWidth(i, 15000);
        }
    }

    return wb;
}

From source file:org.jxstar.report.util.XlsToHtml.java

public String parserXls(String fileName) throws ReportException {
    ///*from www . ja va  2  s.  co m*/
    HSSFWorkbook hssfWB = ReportXlsUtil.readWorkBook(fileName);
    if (hssfWB == null) {//"?{0}??"
        throw new ReportException(JsMessage.getValue("xlstohtml.hint01"), fileName);
    }

    HSSFSheet sheet = hssfWB.getSheetAt(0);
    //???0
    int lastRowNum = sheet.getLastRowNum();
    if (lastRowNum == 0) {
        _log.showDebug("xls file row num is 0!!");
        return "";
    }

    //?xls?tablehtml
    StringBuilder sbTable = new StringBuilder();
    sbTable.append("<table id='" + PARSERTABLEID + "' class='xls_table' >\n");

    //?
    List<Integer> lsemp = FactoryUtil.newList();

    //?1
    int hasnum = 0, tableColNum = 0;

    //??1IE1?
    //table-layout:fixed;??????1??
    List<Integer> lswidth = FactoryUtil.newList();

    //??
    for (int i = 0; i <= lastRowNum; i++) {
        HSSFRow row = sheet.getRow(i);
        if (row == null) {//??
            lsemp.add(i);
            sbTable.append("<tr height='22px' >\n{EMPTY_LINE}</tr>\n");
            continue;
        }

        //???
        int lastCellNum = row.getLastCellNum();

        //cells-1?
        if (lastCellNum <= 0) {
            lsemp.add(i);
            sbTable.append("<tr height='22px' >\n{EMPTY_LINE}</tr>\n");
            continue;
        } else {
            //?
            if (hasnum == 0)
                tableColNum = lastCellNum + EMPTY_COLNUM;
            hasnum++;
        }

        //tr
        sbTable.append("<tr height='" + getHeightPixel(row.getHeightInPoints()) + "px' >\n");
        //_log.showDebug("row=" + i + "; nums=" + cells);
        for (int j = 0; j < tableColNum; j++) {
            HSSFCell cell = null;
            if (j < lastCellNum)
                cell = row.getCell(j);
            //?ID
            String tdid = i + "," + j;

            //
            if (cell == null) {
                String ls = "";
                if (hasnum == 1) {
                    //?30px
                    int width = (j < lastCellNum) ? 10 : 30;
                    ls = " style='width:" + width + "px;'";
                    lswidth.add(width);
                }
                sbTable.append("\t<td id='" + tdid + "' class='xls_emp'" + ls + " >&nbsp;</td>\n");

                continue;
            }

            //td?
            String style = getCellStyle(cell);

            //???cssName
            String cssName = getTdCss(style);

            //?td
            String value = getCellValue(cell);
            if (value == null || value.length() == 0) {
                value = "&nbsp;";
            } else {
                value = value.replaceAll("\\s", "&nbsp;");
            }

            //1?????
            if (hasnum == 1) {
                //
                int colw = getWidthPixel(sheet.getColumnWidth(j));
                lswidth.add(colw);
                //td
                sbTable.append("\t<td id='" + tdid + "' class='" + cssName + "' style='width:" + colw + "px;' >"
                        + value + "</td>\n");
            } else {
                sbTable.append("\t<td id='" + tdid + "' class='" + cssName + "' >" + value + "</td>\n");
            }
        }
        sbTable.append("</tr>\n");
    }
    //_log.showDebug(sbTable.toString());
    //??
    for (int i = 1; i <= EMPTY_ROWNUM; i++) {
        lsemp.add(lastRowNum + i);
        //tr
        sbTable.append("<tr height='22px' >\n");
        sbTable.append("{EMPTY_LINE}");
        sbTable.append("</tr>\n");
    }

    //cells-1?
    if (tableColNum > 0 && lsemp.size() > 0) {
        sbTable = fillEmptyLine(sbTable, tableColNum, lsemp, lswidth);
        lsemp.clear();
    }

    sbTable.append("</table>\n");

    //?html
    StringBuilder sbHtml = new StringBuilder();
    sbHtml.append("<html>\n<body style='margin:1px;'>\n");
    sbHtml.append(getCssStyle());
    sbHtml.append(sbTable);

    //???
    sbHtml.append(mergedRegion(sheet));

    //html
    sbHtml.append("</body>\n</html>\n");
    //_log.showDebug(sbHtml.toString());

    return sbHtml.toString();
}

From source file:org.metaeffekt.core.inventory.processor.reader.AbstractXlsInventoryReader.java

License:Apache License

protected void readArtifactMetaData(HSSFWorkbook myWorkBook, Inventory inventory) {
    HSSFSheet mySheet = myWorkBook.getSheetAt(0);
    Iterator<?> rows = mySheet.rowIterator();

    List<Artifact> artifacts = new ArrayList<Artifact>();
    inventory.setArtifacts(artifacts);//from   w  w  w .j  a va 2  s.c  o  m

    if (rows.hasNext()) {
        readHeader((HSSFRow) rows.next());
    }

    while (rows.hasNext()) {
        HSSFRow row = (HSSFRow) rows.next();
        Artifact artifact = readArtifactMetaData(row);
        if (artifact != null) {
            artifacts.add(artifact);
        }
    }

    for (int i = 0; i < 15; i++) {
        int width = mySheet.getColumnWidth(i);
        inventory.getContextMap().put("artifacts.column[" + i + "].width", width);
    }
}

From source file:org.metaeffekt.core.inventory.processor.reader.AbstractXlsInventoryReader.java

License:Apache License

protected void readLicenseMetaData(HSSFWorkbook myWorkBook, Inventory inventory) {
    if (myWorkBook.getNumberOfSheets() > 1) {
        HSSFSheet mySheet = myWorkBook.getSheetAt(1);
        if (mySheet != null) {
            Iterator<?> rows = mySheet.rowIterator();

            List<LicenseMetaData> licenseMetaDatas = new ArrayList<LicenseMetaData>();
            inventory.setLicenseMetaData(licenseMetaDatas);

            // skip first line being the header
            if (rows.hasNext()) {
                readLicenseMetaDataHeader((HSSFRow) rows.next());
            }/*from ww w  .  j a  v a 2 s  .co  m*/

            while (rows.hasNext()) {
                HSSFRow row = (HSSFRow) rows.next();
                LicenseMetaData licenseMetaData = readLicenseMetaData(row);
                if (licenseMetaData != null) {
                    licenseMetaDatas.add(licenseMetaData);
                }
            }
        }

        for (int i = 0; i < 5; i++) {
            int width = mySheet.getColumnWidth(i);
            inventory.getContextMap().put("obligations.column[" + i + "].width", width);
        }
    }
}

From source file:org.orbeon.oxf.util.XLSUtils.java

License:Open Source License

public static void copySheet(HSSFWorkbook workbook, HSSFSheet destination, HSSFSheet source) {

    // Copy column width
    short maxCellNum = getMaxCellNum(source);
    for (short i = 0; i <= maxCellNum; i++) {
        destination.setColumnWidth(i, source.getColumnWidth(i));
    }// ww w. j  a v  a  2s .  c  om

    // Copy merged cells
    for (int i = 0; i < source.getNumMergedRegions(); i++) {
        Region region = source.getMergedRegionAt(i);
        destination.addMergedRegion(region);
    }

    // Copy rows
    for (int i = 0; i <= source.getLastRowNum(); i++) {
        HSSFRow sourceRow = source.getRow(i);
        HSSFRow destinationRow = destination.createRow(i);
        copyRow(workbook, destinationRow, sourceRow);
    }
}

From source file:org.unitime.timetable.export.XLSPrinter.java

License:Apache License

private ClientAnchorDetail fitImageToColumns(HSSFSheet sheet, int colNumber, double reqImageWidthMM,
        int resizeBehaviour) {
    double colWidthMM;
    double colCoordinatesPerMM;
    int pictureWidthCoordinates;
    ClientAnchorDetail colClientAnchorDetail = null;

    colWidthMM = ConvertImageUnits.widthUnits2Millimetres((short) sheet.getColumnWidth(colNumber));

    if (colWidthMM < reqImageWidthMM) {
        if (resizeBehaviour == EXPAND_COLUMN || resizeBehaviour == EXPAND_ROW_AND_COLUMN) {
            sheet.setColumnWidth(colNumber, ConvertImageUnits.millimetres2WidthUnits(reqImageWidthMM));
            colWidthMM = reqImageWidthMM;
            colCoordinatesPerMM = ConvertImageUnits.TOTAL_COLUMN_COORDINATE_POSITIONS / colWidthMM;
            pictureWidthCoordinates = (int) (reqImageWidthMM * colCoordinatesPerMM);
            colClientAnchorDetail = new ClientAnchorDetail(colNumber, colNumber, pictureWidthCoordinates);
        } else if (resizeBehaviour == OVERLAY_ROW_AND_COLUMN || resizeBehaviour == EXPAND_ROW) {
            colClientAnchorDetail = calculateColumnLocation(sheet, colNumber, reqImageWidthMM);
        }/*from   w  w w  .  jav a2 s.  c o m*/
    } else {
        colCoordinatesPerMM = ConvertImageUnits.TOTAL_COLUMN_COORDINATE_POSITIONS / colWidthMM;
        pictureWidthCoordinates = (int) (reqImageWidthMM * colCoordinatesPerMM);
        colClientAnchorDetail = new ClientAnchorDetail(colNumber, colNumber, pictureWidthCoordinates);
    }
    return (colClientAnchorDetail);
}

From source file:org.unitime.timetable.export.XLSPrinter.java

License:Apache License

private ClientAnchorDetail calculateColumnLocation(HSSFSheet sheet, int startingColumn,
        double reqImageWidthMM) {
    ClientAnchorDetail anchorDetail;// ww  w  .  j av a 2  s.  c o  m
    double totalWidthMM = 0.0D;
    double colWidthMM = 0.0D;
    double overlapMM;
    double coordinatePositionsPerMM;
    int toColumn = startingColumn;
    int inset;

    while (totalWidthMM < reqImageWidthMM) {
        colWidthMM = ConvertImageUnits.widthUnits2Millimetres((short) (sheet.getColumnWidth(toColumn)));
        totalWidthMM += (colWidthMM + ConvertImageUnits.CELL_BORDER_WIDTH_MILLIMETRES);
        toColumn++;
    }
    toColumn--;

    if ((int) totalWidthMM == (int) reqImageWidthMM) {
        anchorDetail = new ClientAnchorDetail(startingColumn, toColumn,
                ConvertImageUnits.TOTAL_COLUMN_COORDINATE_POSITIONS);
    } else {
        overlapMM = reqImageWidthMM - (totalWidthMM - colWidthMM);
        if (overlapMM < 0) {
            overlapMM = 0.0D;
        }
        coordinatePositionsPerMM = ConvertImageUnits.TOTAL_COLUMN_COORDINATE_POSITIONS / colWidthMM;
        inset = (int) (coordinatePositionsPerMM * overlapMM);
        anchorDetail = new ClientAnchorDetail(startingColumn, toColumn, inset);
    }
    return (anchorDetail);
}

From source file:poi.hssf.usermodel.examples.AddDimensionedImage.java

License:Apache License

/**
 * Determines whether the sheets columns should be re-sized to accomodate
 * the image, adjusts the columns width 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./*from   w ww  . j av a  2s .  co m*/
 *
 * @param sheet A reference to the sheet that will 'contain' the image.
 * @param colNumber A primtive int that contains the index number of a
 *                  column on the sheet.
 * @param reqImageWidthMM A primtive double that contains the required
 *                        width of the image in millimetres
 * @param resizeBehaviour A primitve int whose value will indicate how the
 *                        width of the column should be adjusted if the
 *                        required width of the image is greater than the
 *                        width of the column.
 * @return An instance of the ClientAnchorDetail class that will contain
 *         the index number of the column containing the cell whose top
 *         left hand corner also defines the top left hand corner of the
 *         image, the index number column 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 right hand
 *         edge of the image can protrude into the next column - expressed
 *         as a specific number of co-ordinate positions.
 */
private ClientAnchorDetail fitImageToColumns(HSSFSheet sheet, int colNumber, double reqImageWidthMM,
        int resizeBehaviour) {

    double colWidthMM = 0.0D;
    double colCoordinatesPerMM = 0.0D;
    int pictureWidthCoordinates = 0;
    ClientAnchorDetail colClientAnchorDetail = null;

    // Get the colum's width in millimetres
    colWidthMM = ConvertImageUnits.widthUnits2Millimetres((short) sheet.getColumnWidth(colNumber));

    // Check that the column's width will accomodate the image at the
    // required dimension. If the width of the column is LESS than the
    // required width of the image, decide how the application should
    // respond - resize the column or overlay the image across one or more
    // columns.
    if (colWidthMM < reqImageWidthMM) {

        // Should the column's width simply be expanded?
        if ((resizeBehaviour == AddDimensionedImage.EXPAND_COLUMN)
                || (resizeBehaviour == AddDimensionedImage.EXPAND_ROW_AND_COLUMN)) {
            // Set the width of the column by converting the required image
            // width from millimetres into Excel's column width units.
            sheet.setColumnWidth(colNumber, ConvertImageUnits.millimetres2WidthUnits(reqImageWidthMM));
            // To make the image occupy the full width of the column, convert
            // the required width of the image into co-ordinates. This value
            // will become the inset for the ClientAnchorDetail class that
            // is then instantiated.
            colWidthMM = reqImageWidthMM;
            colCoordinatesPerMM = ConvertImageUnits.TOTAL_COLUMN_COORDINATE_POSITIONS / colWidthMM;
            pictureWidthCoordinates = (int) (reqImageWidthMM * colCoordinatesPerMM);
            colClientAnchorDetail = new ClientAnchorDetail(colNumber, colNumber, pictureWidthCoordinates);
        }
        // If the user has chosen to overlay both rows and columns or just
        // to expand ONLY the size of the rows, then calculate how to lay
        // the image out across one or more columns.
        else if ((resizeBehaviour == AddDimensionedImage.OVERLAY_ROW_AND_COLUMN)
                || (resizeBehaviour == AddDimensionedImage.EXPAND_ROW)) {
            colClientAnchorDetail = this.calculateColumnLocation(sheet, colNumber, reqImageWidthMM);
        }
    }
    // If the column is wider than the image.
    else {
        // Mow many co-ordinate positions are there per millimetre?
        colCoordinatesPerMM = ConvertImageUnits.TOTAL_COLUMN_COORDINATE_POSITIONS / colWidthMM;
        // Given the width of the image, what should be it's co-ordinate?
        pictureWidthCoordinates = (int) (reqImageWidthMM * colCoordinatesPerMM);
        colClientAnchorDetail = new ClientAnchorDetail(colNumber, colNumber, pictureWidthCoordinates);
    }
    return (colClientAnchorDetail);
}

From source file:poi.hssf.usermodel.examples.AddDimensionedImage.java

License:Apache License

/**
 * If the image is to overlie more than one column, calculations need to be
 * performed to determine how many columns and whether the image will
 * overlie just a part of one column in order to be presented at the
 * required size.//from  w  ww.  jav a  2 s  .com
 *
 * @param sheet The sheet that will 'contain' the image.
 * @param startingColumn A primitive int whose value is the index of the
 *                       column that contains the cell whose top left hand
 *                       corner should be aligned with the top left hand
 *                       corner of the image.
 * @param reqImageWidthMM A primitive double whose value will indicate the
 *                        required width of the image in millimetres.
 * @return An instance of the ClientAnchorDetail class that will contain
 *         the index number of the column containing the cell whose top
 *         left hand corner also defines the top left hand corner of the
 *         image, the index number column 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 right hand
 *         edge of the image can protrude into the next column - expressed
 *         as a specific number of co-ordinate positions.
 */
private ClientAnchorDetail calculateColumnLocation(HSSFSheet sheet, int startingColumn,
        double reqImageWidthMM) {
    ClientAnchorDetail anchorDetail = null;
    double totalWidthMM = 0.0D;
    double colWidthMM = 0.0D;
    double overlapMM = 0.0D;
    double coordinatePositionsPerMM = 0.0D;
    int toColumn = startingColumn;
    int inset = 0;

    // Calculate how many columns the image will have to
    // span in order to be presented at the required size.
    while (totalWidthMM < reqImageWidthMM) {
        colWidthMM = ConvertImageUnits.widthUnits2Millimetres((short) (sheet.getColumnWidth(toColumn)));
        // Note use of the cell border width constant. Testing with an image
        // declared to fit exactly into one column demonstrated that it's
        // width was greater than the width of the column the POI returned.
        // Further, this difference was a constant value that I am assuming
        // related to the cell's borders. Either way, that difference needs
        // to be allowed for in this calculation.
        totalWidthMM += (colWidthMM + ConvertImageUnits.CELL_BORDER_WIDTH_MILLIMETRES);
        toColumn++;
    }
    // De-crement by one the last column value.
    toColumn--;
    // Highly unlikely that this will be true but, if the width of a series
    // of columns is exactly equal to the required width of the image, then
    // simply build a ClientAnchorDetail object with an inset equal to the
    // total number of co-ordinate positions available in a column, a
    // from column co-ordinate (top left hand corner) equal to the value
    // of the startingColumn parameter and a to column co-ordinate equal
    // to the toColumn variable.
    //
    // Convert both values to ints to perform the test.
    if ((int) totalWidthMM == (int) reqImageWidthMM) {
        // A problem could occur if the image is sized to fit into one or
        // more columns. If that occurs, the value in the toColumn variable
        // will be in error. To overcome this, there are two options, to
        // ibcrement the toColumn variable's value by one or to pass the
        // total number of co-ordinate positions to the third paramater
        // of the ClientAnchorDetail constructor. For no sepcific reason,
        // the latter option is used below.
        anchorDetail = new ClientAnchorDetail(startingColumn, toColumn,
                ConvertImageUnits.TOTAL_COLUMN_COORDINATE_POSITIONS);
    }
    // In this case, the image will overlap part of another column and it is
    // necessary to calculate just how much - this will become the inset
    // for the ClientAnchorDetail object.
    else {
        // Firstly, claculate how much of the image should overlap into
        // the next column.
        overlapMM = reqImageWidthMM - (totalWidthMM - colWidthMM);

        // When the required size is very close indded to the column size,
        // the calcaulation above can produce a negative value. To prevent
        // problems occuring in later caculations, this is simply removed
        // be setting the overlapMM value to zero.
        if (overlapMM < 0) {
            overlapMM = 0.0D;
        }

        // Next, from the columns width, calculate how many co-ordinate
        // positons there are per millimetre
        coordinatePositionsPerMM = ConvertImageUnits.TOTAL_COLUMN_COORDINATE_POSITIONS / colWidthMM;
        // From this figure, determine how many co-ordinat positions to
        // inset the left hand or bottom edge of the image.
        inset = (int) (coordinatePositionsPerMM * overlapMM);

        // Now create the ClientAnchorDetail object, setting the from and to
        // columns and the inset.
        anchorDetail = new ClientAnchorDetail(startingColumn, toColumn, inset);
    }
    return (anchorDetail);
}