Hello,
How do I add an image to a comment?
I want to show an image when the user hover the cell, something like this:
Thank you in advance for the answer
Greetings
Well, to be 100% honest, I wonder how to insert an image into a comment myself too :) There is no place in the xls/xlsx file format to insert images into comments, so I imagine what you are really doing in the example you show is setting the "fill color" of the comment to be an image.
using (TUIImage Img = TUIImage.FromFile("imagename.png"))
{
using (var ImgStream = new FileStream("imagename.png", FileMode.Open))
{
byte[] ImgData = new byte[ImgStream.Length];
ImgStream.Read(ImgData, 0, ImgData.Length);
var sourceRect = new TDrawingRelativeRect(0, 0, 100, 100);
var commentProperties = TCommentProperties.CreateStandard(5, 3, xls);
commentProperties.ShapeFill = new TShapeFill(
true,
new TBlipFill(
192, false,
new TBlip(TBlipCompression.None, ImgData, "", StandardMimeType.Png),
null, new TBlipFillStretch(sourceRect)
)
);
commentProperties.Anchor = new TClientAnchor(
commentProperties.Anchor.AnchorType,
commentProperties.Anchor.Row1,
commentProperties.Anchor.Dy1Pix(xls),
commentProperties.Anchor.Col1,
commentProperties.Anchor.Dx1Pix(xls),
(int)(Img.HeightInPoints * 96.0 / 72.0),
(int)(Img.Width * 96.0 / 72.0),
xls);
xls.SetComment(5, 3, " ", "", commentProperties);
}
}