/// <summary> /// allShapes collects all the shapes on the current slide into a ShapeRange object, and /// returns that. /// </summary> /// <returns>a shaperange containing all the shapes currently selected</returns> public List <PowerPoint.Shape> allShapes() { PowerPoint.Slide slide = pptApp.ActivePresentation.Slides[getCurSlide()]; List <PowerPoint.Shape> shapes = new List <PowerPoint.Shape>(); foreach (PowerPoint.Shape s in slide.Shapes) { shapes.Add(s); } return(shapes); /* * PowerPoint.Slide slide = pptApp.ActivePresentation.Slides[getCurSlide()]; * slide.Shapes.SelectAll(); // built in method that selects all object on the slide * PowerPoint.Selection selection = pptApp.ActiveWindow.Selection; // need the selection to get shapes * * List<int> ids = new List<int>(); * try * { * // go through each shape in selection and save those in range * PowerPoint.ShapeRange range = selection.HasChildShapeRange ? selection.ChildShapeRange : selection.ShapeRange; * selection.Unselect(); // unselect the entire selection after this call to return to initial situation * return range; * } * catch (Exception) * { * return null; * } * */ }
// Test driver. public static bool Test() { bool passed = true; PowerPoint.Application app = new PowerPoint.Application(); //PowerPoint.Application app = new PowerPoint.ApplicationClass(); app.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; PowerPoint.Presentation presentation = app.Presentations.Add(Core.MsoTriState.msoFalse); PowerPoint.Slide slide = presentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank); PowerPoint.Shape shape = slide.Shapes.AddLine(0, 0, 100, 100); Console.WriteLine("Test on presentation."); passed = passed && TestTags(presentation.Tags); Console.WriteLine("Test on slide."); passed = passed && TestTags(slide.Tags); Console.WriteLine("Test on shape."); passed = passed && TestTags(shape.Tags); app = null; return(passed); }
private void addFirstSlide() { PowerPoint.Slide firstSlide = Globals.ThisAddIn.Application.ActivePresentation.Slides[1]; PowerPoint.Shape textBox2 = firstSlide.Shapes.AddTextbox( Office.MsoTextOrientation.msoTextOrientationHorizontal, 50, 50, 500, 500); textBox2.TextFrame.TextRange.InsertAfter("firstSlide"); }
/// <summary> /// paste acts just like the real paste. It adds a shape of the specified MsoAutoShapeType at /// the specified location with the specified dimension. This is implemented because there /// is no built in paste for the Shape object that we are interested in /// </summary> /// <param name="type">the type of the shape</param> /// <param name="x">x coordinate</param> /// <param name="y">y coordinate</param> /// <param name="width">width of the shape</param> /// <param name="height">height of the shape</param> /// <returns></returns> public PowerPoint.Shape paste(Microsoft.Office.Core.MsoAutoShapeType type, int x, int y, float width, float height, int color, float angle) { int XCORRECTION = 5; PowerPoint.Slide slide = pptApp.ActivePresentation.Slides[getCurSlide()]; PowerPoint.Shape shape = slide.Shapes.AddShape(type, (float)(x + XCORRECTION), y, (int)width, (int)height); shape.Fill.ForeColor.RGB = color; shape.Rotation = angle; return(shape); }
public void GoToSlide(int slideNumber) { if (slideNumber <= slidesCount && slideNumber > 0) { try { slide = slides[slideNumber]; slides[slideNumber].Select(); } catch { pptApplication.SlideShowWindows[slideNumber].View.Previous(); slide = pptApplication.SlideShowWindows[slideNumber].View.Slide; } } }
public bool GetOpenPpt() { bool success = false; try { // Get Running PowerPoint Application object pptApplication = Marshal.GetActiveObject("PowerPoint.Application") as PowerPoint.Application; } catch { } if (pptApplication != null) { success = true; // Get Presentation Object presentation = pptApplication.ActivePresentation; // Get Slide collection object slides = presentation.Slides; // Get Slide count slidesCount = slides.Count; // Get current selected slide try { // Get selected slide object in normal view slide = slides[pptApplication.ActiveWindow.Selection.SlideRange.SlideNumber]; } catch { // Get selected slide object in reading view slide = pptApplication.SlideShowWindows[1].View.Slide; } } return(success); }
private void ShowPresentation() { String strDest = Environment.CurrentDirectory + "\\" + txtSaveAs.Text + ".ppt"; PowerPoint.Application objApp; PowerPoint.Presentations objPresSet; PowerPoint._Presentation objPres; PowerPoint.SlideShowSettings objSSS; PowerPoint.SlideShowWindows objSSWs; //Create a new presentation based on a template. objApp = new PowerPoint.Application(); objApp.Visible = MsoTriState.msoTrue; objPresSet = objApp.Presentations; int iCurCnt = 1; int iSlideCnt = 0; objPres = objPresSet.Add(Microsoft.Office.Core.MsoTriState.msoFalse); for (int i = 0; i < lstList.Items.Count; i++) { PowerPoint._Presentation objPresOpen; objPresOpen = objPresSet.Open(lstList.Items[i].Text, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse); iSlideCnt = objPresOpen.Slides.Count; objPres.Slides.InsertFromFile(lstList.Items[i].Text, iCurCnt - 1, 1, iSlideCnt); for (int j = 1, iCount = iCurCnt; j <= iSlideCnt; j++, iCount++) { PowerPoint.Slide slide = objPres.Slides.Item(iCount); slide.Design = objPresOpen.Slides.Item(j).Design; slide.ColorScheme = objPresOpen.Slides.Item(j).ColorScheme; slide.FollowMasterBackground = MsoTriState.msoTrue; slide.DisplayMasterShapes = MsoTriState.msoTrue; } objPresOpen.Close(); iCurCnt += iSlideCnt; } objPres.SaveAs(strDest, PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, MsoTriState.msoTrue); objPres.Close(); objPres = objPresSet.Open(strDest, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoTrue); //Prevent Office Assistant from displaying alert messages: objApp.Assistant.On = false; objApp.Assistant.Visible = false; //Run the Slide show from slides 1 thru 3. objSSS = objPres.SlideShowSettings; objSSS.StartingSlide = 1; objSSS.EndingSlide = iCurCnt - 1; objSSS.Run(); //Wait for the slide show to end. objSSWs = objApp.SlideShowWindows; while (objSSWs.Count >= 1) { System.Threading.Thread.Sleep(100); } //Close the presentation without saving changes and quit PowerPoint. objPres.Close(); objApp.Quit(); }
}// end newslide method #endregion #region Add Objects /// <summary> /// addMessage takes in a set or coordinates and a string. It adds the string to the /// coordinates on the current slide. The width of the textbox containing the string /// is dependent on the length of the text. /// </summary> /// <param name="x">x coordinate</param> /// <param name="y">y coordinate</param> /// <param name="s">a string containing the message to be added</param> public PowerPoint.Shape addMessage(int x, int y, string s, Rectangle bound, bool sizeDependent) { PowerPoint.Slide slide = pptApp.ActivePresentation.Slides[getCurSlide()]; PowerPoint.Shape textbox; int width = s.Length * 17; // approximate an initial width for the text added textbox = slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, x, y, width, 30); // allow AutoSize and disableing WordWrap allows the textbox to auto fit to the content textbox.TextFrame.WordWrap = Microsoft.Office.Core.MsoTriState.msoFalse; textbox.TextFrame.AutoSize = PowerPoint.PpAutoSize.ppAutoSizeShapeToFitText; // font and font size are obtained from the default PowerPoint font and font size combo box if (myForm.isBold()) { textbox.TextFrame.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoTrue; } else { textbox.TextFrame.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoFalse; } if (myForm.isItalicize()) { textbox.TextFrame.TextRange.Font.Italic = Microsoft.Office.Core.MsoTriState.msoTrue; } else { textbox.TextFrame.TextRange.Font.Italic = Microsoft.Office.Core.MsoTriState.msoFalse; } if (myForm.isUnderline()) { textbox.TextFrame.TextRange.Font.Underline = Microsoft.Office.Core.MsoTriState.msoTrue; } else { textbox.TextFrame.TextRange.Font.Underline = Microsoft.Office.Core.MsoTriState.msoFalse; } textbox.TextFrame.TextRange.Text = s; textbox.Width = textbox.TextFrame.TextRange.BoundWidth + 10; // textbox.TextFrame.TextRange.Font.Size = int.Parse(myForm.pptFontSize()); string name = myForm.pptFont(); textbox.TextFrame.TextRange.Font.Name = name; if (sizeDependent) { textbox.TextFrame.TextRange.Font.Size = analyzeSize(s, bound, name); textbox.Height = textbox.TextFrame.TextRange.BoundHeight; textbox.Width = textbox.TextFrame.TextRange.BoundWidth + 10; } else { textbox.TextFrame.TextRange.Font.Size = int.Parse(myForm.pptFontSize()); } return(textbox); }