Adding Drawing part image prevents the cell update #1823
Closed
ZubairImran
started this conversation in
General
Replies: 1 comment 4 replies
-
Hi @ZubairImran, This will add an image to the background of a sheet: using DocumentFormat.OpenXml.Packaging;
string xlsxPath = @"path/to/your.xlsx";
string imagePath = @"path/to/your/image.jpg";
using (var doc = SpreadsheetDocument.Open(xlsxPath, true))
{
if (doc?.WorkbookPart is not { } workbookPart ||
workbookPart.WorksheetParts.FirstOrDefault() is not { } worksheetPart)
{
throw new ArgumentException("Can't find worksheet part");
}
ImagePart imagePart = worksheetPart.AddImagePart("image/jpeg");
var id = workbookPart.GetIdOfPart(imagePart);
using (var stream = File.OpenRead(imagePath))
{
imagePart.FeedData(stream);
}
worksheetPart.Worksheet.AddChild(new DocumentFormat.OpenXml.Spreadsheet.Picture() { Id = id});
} |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Team,
I am adding a image using drawing layer(drawing part) in a Excel file. I could able to add the image but the image prevents the cells available in the background. Is there anyway to send the image to background using openxml sdk. Any pointer would be great help.
Beta Was this translation helpful? Give feedback.
All reactions