Hi,

Did you try to work with the setDx1/setDy1/... methods? That might allow to
do what you are looking for here when you take into account how it works.

>From the xlsx-Spec:

"... describes the placement of the drawing within the spreadsheet based
upon offsets
as well as a specified column and row. The offset is always in reference to
the specified anchor cell and
acts to offset the shape object from being exactly on top of the anchor
cell. The offset information
determines the actual placement of the drawing within the spreadsheet while
the row and column are
used to specify to which cell the drawing should be anchored. Thus, if the
anchor cell changes positions
then the drawing can be moved as well." and

"colOff (Column Offset)
This element is used to specify the column offset within a cell. The units
for which this attribute is specified in
reside within the simple type definition referenced below."

unfortunately I could not find after a quick look what dimension the
colOffset/rowOffset actually has, so you might need to go by
trial-and-error a bit to find useful values for your case.

Dominik.

On Tue, Jun 7, 2016 at 2:28 PM, Bengt Rodehav <be...@rodehav.com> wrote:

> Hello,
>
> I generated comments for some cells in the Excel document. But, it seems
> like the width of the comment depends on the width of the cell which is
> very unintuitive. I know how wide (in pixels) the comment need to be to
> work visually but sometimes it is attached to a wide cell and sometimes to
> a very narrow cell. How can I set the comment width in pixels?
>
> I found this on Stack Overflow but no answer unfortunately:
>
>
> http://stackoverflow.com/questions/27960873/autosize-excel-comments-with-apache-poi
>
> I use this code to generate comments:
>
>     CreationHelper factory = wb.getCreationHelper();
>     Drawing drawing = theSheet.createDrawingPatriarch();
>
>     // When the comment box is visible, have it show in a 1x3 space
>     ClientAnchor anchor = factory.createClientAnchor();
>     anchor.setCol1(theCell.getColumnIndex());
>     anchor.setCol2(theCell.getColumnIndex() + 1);
>     anchor.setRow1(theCell.getRowIndex());
>     anchor.setRow2(theCell.getRowIndex() + 3);
>
>     // Create the comment and set the text+author
>     Comment comment = drawing.createCellComment(anchor);
>     RichTextString str = factory.createRichTextString("Comment string");
>     comment.setString(str);
>     comment.setAuthor("Author");
>
>
> /Bengt
>

Reply via email to