Changing the size of cell comments in Apache POI

advertisements

I use the following java code to successfully generate cell comments in Apache POI

public static void setComment(String text, Cell cell) {
            final Map<Sheet, HSSFPatriarch> drawingPatriarches = new HashMap<Sheet, HSSFPatriarch>();

            CreationHelper createHelper = cell.getSheet().getWorkbook().getCreationHelper();
            HSSFSheet sheet = (HSSFSheet) cell.getSheet();
            HSSFPatriarch drawingPatriarch = drawingPatriarches.get(sheet);
            if (drawingPatriarch == null) {
                drawingPatriarch = sheet.createDrawingPatriarch();
                drawingPatriarches.put(sheet, drawingPatriarch);
            }

            Comment comment = drawingPatriarch.createComment(new HSSFClientAnchor(100, 100, 100, 100, (short)1, 1, (short) 10, 5));
            comment.setString(createHelper.createRichTextString(text));
            cell.setCellComment(comment);
        }

I copied it from creating cell comments using HSSFClientAnchor in apache poi. Thank you Erik!

How can I change the size of the comment to 300 pixels width and 100 pixels height?

Thanks!


From what I can tell there's not an easy way since comment anchor points are specified by cell (column, row parameters) and offset into cell (dx, dy parameters). So you need to compute the width/height of the cells to figure out the second cell coordinates and then the offsets into that cell to make it exactly the pixel size you want.