public static StringBuilder Start(string filePath) { StringBuilder stringBuilder = new StringBuilder(); PowerPoint.Application powerApplication = new PowerPoint.Application(); PowerPoint.Presentations pptPresentations = powerApplication.Presentations; PowerPoint.Presentation pptPresentation = pptPresentations.Open(filePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); PowerPoint.Slides pptSlides = pptPresentation.Slides; if (pptSlides != null) { //var slidesCount = pptSlides.Count; foreach (PowerPoint.Slide slide in pptSlides) { foreach (PowerPoint.Shape shape in slide.Shapes) { if (shape.HasTextFrame == MsoTriState.msoTrue && shape.TextFrame.HasText == MsoTriState.msoTrue) { PowerPoint.TextRange range = shape.TextFrame.TextRange; if (range != null && range.Length > 0) { stringBuilder.Append(" " + range.Text); } } } } } return(stringBuilder); }
public static void ShapeTextReplace(PowerPoint.TextRange textRange, Dictionary <string, string> replaces) { // var text = textRange.Text; foreach (var replace in replaces) { while (textRange.Text.Contains(replace.Key)) { textRange.Replace(replace.Key, replace.Value); } } }
private void TextReplace(PowerPoint.TextRange textRange, Dictionary <string, string> replaces) { var text = textRange.Text; foreach (var replace in replaces) { if (text.Contains(replace.Key)) { textRange.Replace(replace.Key, replace.Value); } } }