简体   繁体   中英

How to embed a picture into a comment using OpenXml or EPPlus?

I'm pretty new to OpenXML and have found the EPPlus project extremely helpful, however I have a need to set the background image of a comment to a picture. I can do this in Excel, however, I do not see any interfaces exposed for doing this.

Has anyone done this before in OpenXML? Or can point me to a good starting point?

Thanks, much appreciated

I believe EPPlus only allows you to set the background colour, but not with a picture. In OpenXML, comment styling (including the background image) is stored in a VML file.

If you use the Open XML SDK, then it's the LegacyDrawing under the Worksheet class. You'll have to get the ID from the LegacyDrawing class, then retrieve the VmlDrawingPart class and manipulate the contents. You'll also have to work with ImageParts of the VmlDrawingPart. It's kind of a mess to work with, actually...

For convenience, you might want to consider SpreadsheetLight . Here's how to do comments:

SLDocument sl = new SLDocument();

SLComment comm = sl.CreateComment();
comm.SetText("There's a picture background.");
comm.Fill.SetPictureFill("julia.png", 0, 0, 0, 0, 0);
sl.InsertComment(2, 2, comm);

sl.SaveAs("CommentBackground.xlsx");

That will stretch the picture fully across the comment box background.

Disclaimer: I wrote SpreadsheetLight.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM