Hi Hi,@乾罡 雷,
There are different kinds of backgrounds, Solid Fill, Gradient Fill, Picture Fill, etc., so I'm not sure exactly which background effect you want to apply, but if you want to, for example, change the background color of all the slides in a PPTX file, you would need to:
- Get a list of all slides for the presentation
- Find the Common Slide Data
p:cSld
for each slide. - Add a [Slide Background]
p:bg
as the first child element to the Common Slide Data element - Add a Background Properties element as the first child of the Slide Background element.
- Add a Solid Fill element
a:solidFill
(ISO-OI29500 20.1.8.54 solidFill (Solid Fill)) element as a child of the Background Properties element - Add an
a:srgbClr
element as a child of the Solid Fill element with a val property of the color you want as a hex.
If you want to do that with the SDK, it would look like this:
string file = @"C:\path\to\your.pptx";
using (PresentationDocument presentationDocument = PresentationDocument.Open(file, true))
{
IEnumerable<SlidePart>? slideParts = presentationDocument?.PresentationPart?.SlideParts;
if (slideParts is not null )
{
foreach(SlidePart slidePart in slideParts)
{
IEnumerable<CommonSlideData> commonSlideDatas = slidePart.Slide.Elements<CommonSlideData>();
foreach (var commonSlideData in commonSlideDatas)
{
commonSlideData.PrependChild(new Background(
new BackgroundProperties(
new SolidFill(
new RgbColorModelHex() { Val = "00B050" }))));
}
}
}
if (presentationDocument is not null)
{
presentationDocument.Save();
}
}