Adding Drawing part image prevents the cell update #1823
Closed
ZubairImran
started this conversation in
General
Replies: 3 comments 5 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
-
Hi Bown,
Do Open-XML-SDK supports to keep only one background image meaning can we
delete the above inserted images(by iterating and keep only one)?
…On Fri, Jan 17, 2025 at 10:57 PM Michael Bowen ***@***.***> wrote:
Hi @ZubairImran <https://github.com/ZubairImran>, repeating the image in
the background is the expected behavior, because a sheet has an unlimited
number of rows, i.e. infinite height, there is no way for Excel to know how
to scale the image.
—
Reply to this email directly, view it on GitHub
<#1823 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AECOW2NNHHOA6PGE2D56YFL2LE4PXAVCNFSM6AAAAABRY7BRU6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCOBWHE3TINQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Hi Bowen,
Thanks for your reply. I want to keep.only one background image in a sheet.
Thanks
Hyder
…On Fri, 21 Feb, 2025, 9:47 pm Michael Bowen, ***@***.***> wrote:
Hi @ZubairImran <https://github.com/ZubairImran>, Do you mean you only
want to show one background image and then have no background image below
that first background image?
—
Reply to this email directly, view it on GitHub
<#1823 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AECOW2IO56O5MF5PSDM7QYL2Q5GSTAVCNFSM6AAAAABRY7BRU6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMRXHA2TIOI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 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