public void CreateSlide(string slideTitle, string slideBody) { if (slideBody.Contains("\r\n\r\n") || String.IsNullOrEmpty(slideBody) || slideBody == "\r\n") { return; } float slideWidth = m_pptPres.PageSetup.SlideWidth; float lyricsShapeWidth = 900; float lyricsShapeLeft = slideWidth * 0.5f - lyricsShapeWidth * 0.5f; int textBoxHeight = 0; PowerPoint.Slide pptSlide = m_pptSlides.Add(m_pptSlides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutBlank); PowerPoint.Shapes pptShapes = pptSlide.Shapes; pptShapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, /*left*/ 50, /*top*/ 50, /*width*/ 700, /*height*/ textBoxHeight); PowerPoint.Shape titleTextbox = pptShapes[1]; WriteToTextbox(slideTitle, titleTextbox, 50); pptShapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, lyricsShapeLeft, 150, lyricsShapeWidth, textBoxHeight); PowerPoint.Shape lyricsTextbox = pptShapes[2]; WriteToLyricsTextbox(slideBody, lyricsTextbox, 35); }
/// <summary> /// Fake a copy by creating a similar object with the same formats /// Copy/Pasting MsoPlaceHolder doesn't work. /// Note: Shapes.AddPlaceholder(..) does not work as well. /// It restores a deleted placeholder to the slide, not create a shape /// </summary> /// <param name="formats"></param> /// <param name="msoPlaceHolder"></param> /// <param name="shapesSource">Shapes object, source of shapes</param> /// <returns>returns null if input placeholder is not supported</returns> public static Shape CopyMsoPlaceHolder(Format[] formats, Shape msoPlaceHolder, Shapes shapesSource) { PpPlaceholderType realType = msoPlaceHolder.PlaceholderFormat.Type; // charts, tables, pictures & smart shapes may return a general type, // ppPlaceHolderObject or ppPlaceHolderVerticalObject bool isGeneralType = realType == PpPlaceholderType.ppPlaceholderObject || realType == PpPlaceholderType.ppPlaceholderVerticalObject; if (isGeneralType) { realType = GetSpecificPlaceholderType(msoPlaceHolder); } // create an appropriate shape, based on placeholder type Shape shapeTemplate = null; switch (realType) { // the type never seems to be anything other than subtitle, center title, title, body or object. // still, place the rest here to be safe. case PpPlaceholderType.ppPlaceholderBody: case PpPlaceholderType.ppPlaceholderCenterTitle: case PpPlaceholderType.ppPlaceholderTitle: case PpPlaceholderType.ppPlaceholderSubtitle: case PpPlaceholderType.ppPlaceholderVerticalBody: case PpPlaceholderType.ppPlaceholderVerticalTitle: // not safe to do shape.Duplicate(), the duplicated textbox has differences in configuration // width is one example. more investigation is required to find out the exact differences shapeTemplate = shapesSource.AddTextbox( msoPlaceHolder.TextFrame.Orientation, msoPlaceHolder.Left, msoPlaceHolder.Top, msoPlaceHolder.Width, msoPlaceHolder.Height); break; case PpPlaceholderType.ppPlaceholderChart: case PpPlaceholderType.ppPlaceholderOrgChart: // not much value in copying charts, differed for now break; case PpPlaceholderType.ppPlaceholderTable: // not much value in copying tables, differed for now break; case PpPlaceholderType.ppPlaceholderPicture: case PpPlaceholderType.ppPlaceholderBitmap: // must use duplicate. there is no way to create a replacement picture // as the image's source is not obtainable through the Shape API var tempShape = msoPlaceHolder.Duplicate()[1]; tempShape.Copy(); shapeTemplate = shapesSource.Paste()[1]; tempShape.Delete(); break; case PpPlaceholderType.ppPlaceholderVerticalObject: case PpPlaceholderType.ppPlaceholderObject: // already narrowed down the type // should only perform actions valid for all placeholder objects here // do nothing for now break; default: // types not listed above are types that do not make sense to be copied in pptlabs // eg. footer, header, date placeholders break; } if (shapeTemplate == null) { // placeholder type is not supported, no copy made return(null); } ApplyFormats(formats, msoPlaceHolder, shapeTemplate); return(shapeTemplate); }