Adding Drawing part image prevents the cell update #1823
Replies: 6 comments 6 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.
-
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.
-
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.
-
Unfortunately, you can't stop background image tiling with Excel. This Stack Exchange post gives a possible work around with shapes, but I have not tried it. |
Beta Was this translation helpful? Give feedback.
-
Hi Bowen ,
Thanks for the support. Any hint on the below would be a great help
…On Sat, 22 Feb, 2025, 8:13 am Hyder Ali, ***@***.***> wrote:
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.
-
Hi Bowen,
Thanks a lot. I will go through this. Thanks again
…On Sat, 1 Mar, 2025, 2:11 am Michael Bowen, ***@***.***> wrote:
Hi @ZubairImran <https://github.com/ZubairImran>, as I explained in my
earlier post, Excel does not provide a way to prevent background image
tiling. I did find this Stack Overflow post
<https://superuser.com/questions/1729559/how-to-add-a-background-image-to-only-specific-range-of-cells-in-excel>
that contains a possible workaround, but I have not tried to implement it,
so I can't guarantee that it works.
—
Reply to this email directly, view it on GitHub
<#1823 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AECOW2PB7YSV2RPF6I3TVST2SDCW7AVCNFSM6AAAAABRY7BRU6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMZVGY2DCMI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
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