Thanks for your reply Dominik.

However, this only seems to enable putting the anchor in a certain place in
a cell. What I would like is not to specify the width of the comment as "a
number of cells" but as pixels (or some other unit). I need to know that
the comment text actually fits into the comment.

The problem with specifying the width in "number of columns" is that it
doesn't make the width determinable - it varies depending on the width of
this (and the following columns). It's very strange to specify the width in
number of columns I think.

The only thing I can think of is, if it is possible to determine the width
of a column in pixels, to:

1. Start with one column width
2. If the width is too small then try with two columns width
3. If the width is still too small then try with three columns width
4. And so on

Question then is how do you determine the width of a column in pixels?

If you want the width to be exactly a number of pixels (and not just wide
enough as above) then I guess that the dX1/dX2/dY1/dY2 could be used.

/Bengt

2016-06-07 22:20 GMT+02:00 Dominik Stadler <dominik.stad...@gmx.at>:

> 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