Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active September 16, 2021 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/5a740f14f61859a0c6a5b59591e263ac to your computer and use it in GitHub Desktop.
Save aspose-com-gists/5a740f14f61859a0c6a5b59591e263ac to your computer and use it in GitHub Desktop.
Apply Theme in PowerPoint Presentations using C#
using (Presentation pres = new Presentation())
{
// Check number of styles
int numberOfBackgroundFills = pres.MasterTheme.FormatScheme.BackgroundFillStyles.Count;
if (numberOfBackgroundFills > 0)
{
// Select a style
pres.Masters[0].Background.StyleIndex = 1;
}
// Save presentation
pres.Save("theme.pptx", SaveFormat.Pptx);
}
// Load or create presentation
using (Presentation pres = new Presentation())
{
// Add shape and set its color
IAutoShape shape = pres.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 10, 10, 100, 100);
shape.FillFormat.FillType = FillType.Solid;
shape.FillFormat.SolidFillColor.SchemeColor = SchemeColor.Accent1;
// Save presentation
pres.Save("theme.pptx", SaveFormat.Pptx);
}
// Load or create presentation
using (Presentation pres = new Presentation())
{
// Add shape and set its color
IAutoShape shape = pres.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 10, 10, 100, 100);
// Add paragraph
Paragraph paragraph = new Paragraph();
Portion portion = new Portion("Theme text format");
paragraph.Portions.Add(portion);
shape.TextFrame.Paragraphs.Add(paragraph);
// Set font
portion.PortionFormat.LatinFont = new FontData("+mn-lt");
// Save presentation
pres.Save("theme.pptx", SaveFormat.Pptx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment