PowerPoint
A family of Microsoft presentation graphics products that offer tools for creating presentations and adding graphic effects like multimedia objects and special effects with text.
301 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
private void AddSlideContent(SlidePart slidePart, string title, string text)
{
var shapeTree = slidePart.Slide.CommonSlideData.ShapeTree;
var titleShape = shapeTree.AppendChild(new DocumentFormat.OpenXml.Presentation.Shape());
var titleTextBody = titleShape.AppendChild(new DocumentFormat.OpenXml.Drawing.TextBody());
var titleParagraph = titleTextBody.AppendChild(new DocumentFormat.OpenXml.Drawing.Paragraph());
var titleRun = new DocumentFormat.OpenXml.Drawing.Run();
titleRun.Append(new DocumentFormat.OpenXml.Drawing.Text(title));
titleParagraph.Append(titleRun);
var contentShape = shapeTree.AppendChild(new DocumentFormat.OpenXml.Presentation.Shape());
var contentTextBody = contentShape.AppendChild(new DocumentFormat.OpenXml.Drawing.TextBody());
var contentParagraph = contentTextBody.AppendChild(new DocumentFormat.OpenXml.Drawing.Paragraph());
var contentRun = new DocumentFormat.OpenXml.Drawing.Run();
contentRun.Append(new DocumentFormat.OpenXml.Drawing.Text(text));
contentParagraph.Append(contentRun);
// Set additional properties and styles as needed
}
private void CreatePresentation(string content, PresentationDocument presentationDocument)
{
var presentationPart = presentationDocument.AddPresentationPart();
presentationPart.Presentation = new Presentation();
var slideContents = Regex.Split(content, @"Slide \d+:").Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
for (int i = 0; i < slideContents.Length; i++)
{
var slidePart = presentationPart.AddNewPart<SlidePart>("rId" + (i + 1));
slidePart.Slide = new Slide(new CommonSlideData(new ShapeTree()));
var slideContent = slideContents[i].Trim();
var titleEndIndex = slideContent.IndexOf('-');
var title = slideContent.Substring(0, titleEndIndex).Trim();
var slideText = slideContent.Substring(titleEndIndex + 1).Trim();
//AddSlideContent(slidePart, title, slideText);
CreateSimpleSlide(slidePart);
}
presentationPart.Presentation.Save();
}
In runtime contentParagraph.Append(contentRun); contentRun has text. but not going to ppt.
tried a simple method which also did not work.
private void CreateSimpleSlide(SlidePart slidePart)
{
// Create a new shape tree for the slide
var shapeTree = new DocumentFormat.OpenXml.Presentation.ShapeTree();
// Create and append a new shape for the title
var titleShape = shapeTree.AppendChild(new DocumentFormat.OpenXml.Presentation.Shape());
var titleTextBody = titleShape.AppendChild(new DocumentFormat.OpenXml.Drawing.TextBody());
var titleParagraph = titleTextBody.AppendChild(new DocumentFormat.OpenXml.Drawing.Paragraph());
var titleRun = titleParagraph.AppendChild(new DocumentFormat.OpenXml.Drawing.Run());
titleRun.AppendChild(new DocumentFormat.OpenXml.Drawing.Text("Slide 1"));
// Set the slide's shape tree
slidePart.Slide.CommonSlideData = new DocumentFormat.OpenXml.Presentation.CommonSlideData(shapeTree);
// Save changes to the slide part
slidePart.Slide.Save();
}