0% found this document useful (0 votes)
318 views5 pages

C# PowerPoint Automation Example

The document discusses code for creating and modifying a PowerPoint presentation programmatically. It includes code to open an existing template, add slides, insert text and pictures, add and format a chart, modify slide transitions, run the slideshow, and close PowerPoint without saving changes. The code adds 3 slides to the presentation, formats objects on each slide, sets slideshow transition properties, and runs the slideshow before quitting PowerPoint.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
318 views5 pages

C# PowerPoint Automation Example

The document discusses code for creating and modifying a PowerPoint presentation programmatically. It includes code to open an existing template, add slides, insert text and pictures, add and format a chart, modify slide transitions, run the slideshow, and close PowerPoint without saving changes. The code adds 3 slides to the presentation, formats objects on each slide, sets slideshow transition properties, and runs the slideshow before quitting PowerPoint.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using using using using

System; [Link]; [Link]; [Link];

using [Link]; using [Link]; using [Link]; using [Link]; using [Link]; using [Link]; using [Link]; //using PowerPoint = [Link]; //using Graph = [Link]; using [Link]; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { ShowPresentation(); [Link](); } private void ShowPresentation() { String strTemplate, strPic; strTemplate ="C:\\Program Files\\Microsoft Office\\Templates\\Presentation Desig ns\\[Link]"; strPic = "C:\\Windows\\Blue Lace [Link]"; bool bAssistantOn; PowerPoint. Application objApp; PowerPoint. Presentations objPresSet;

PowerPoint. _Presentation objPres; PowerPoint. Slides objSlides; PowerPoint. _Slide objSlide; PowerPoint. TextRange objTextRng; PowerPoint. Shapes objShapes; PowerPoint. Shape objShape; PowerPoint. SlideShowWindows objSSWs; PowerPoint. SlideShowTransition objSST; PowerPoint. SlideShowSettings objSSS; PowerPoint. SlideRange objSldRng; Graph. Chart objChart; Graph. DataSheet dataSheet; Graph. Series series; //Create a new presentation based on a template. objApp = new [Link](); [Link] = [Link]; objPresSet = [Link]; objPres = [Link](strTemplate, [Link], [Link], [Link]); objSlides = [Link]; //Build Slide #1: //Add text to the slide, change the font and insert/position a //picture on the first slide. objSlide = [Link](1, [Link]); objTextRng = [Link][1].[Link]; [Link] = "My Sample Presentation";

[Link] = "Comic Sans MS"; [Link] = 48; [Link](strPic, [Link], [Link],150 , 150, 500, 350); //Build Slide #2: //Add text to the slide title, format the text. Also add a chart to the //slide and change the chart type to a 3D pie chart. objSlide = [Link](2, PowerPoint. [Link]); objTextRng = [Link][1].[Link]; [Link] = "My Chart"; [Link] = "Comic Sans MS"; [Link] = 48; objChart = ([Link])[Link](150, 150, 480, 320,"MSGraph .Chart.8", "", [Link], "", 0, "",[Link]).OLEFormat.O bject; dataSheet = [Link]; [Link][1, [Link][2, [Link][2, [Link][2, [Link][2, [Link][3, [Link][3, [Link][3, [Link][3, 2] 2] 3] 4] 5] 2] 3] 4] 5] = = = = = = = = = "abc"; "50"; "40"; "50"; "50"; "60"; "70"; "80"; "60";

//[Link][3, 6] = "0"; [Link][4, [Link][4, [Link][4, [Link][4, 2] 3] 4] 5] = = = = "50"; "40"; "50"; "50";

[Link] = Graph. [Link]; [Link] = Graph. [Link]; series = ([Link])[Link](2); [Link] = true; [Link]([Link]); [Link] = true; [Link] = Graph. [Link]; [Link] = 6; [Link] = 15; [Link] = Graph. [Link]; [Link]([Link],false,false, false,false,false,true,false,false,","); [Link](); [Link] = true;

[Link] = "Here it is..."; //Build Slide #3: //Change the background color of this slide only. Add a text effect to the slide //and apply various color schemes and shadows to the text effect. objSlide = [Link](3, [Link]); [Link] = [Link]; objShapes = [Link]; objShape = [Link](MsoPresetTextEffect.msoTextEffect27,"The End" , "Impact", 96, [Link], [Link], 230, 200); //Modify the slide show transition settings for all 3 slides in //the presentation. int[] SlideIdx = new int[3]; for (int i = 0; i < 3; i++) SlideIdx[i] = i + 1; objSldRng = [Link](SlideIdx); objSST = [Link]; [Link] = [Link]; [Link] = 3; [Link] = [Link]; //Prevent Office Assistant from displaying alert messages: bAssistantOn = [Link]; [Link] = false; //Run the Slide show from slides 1 thru 3. objSSS = [Link]; [Link] = 1; [Link] = 3; [Link](); //Wait for the slide show to end. objSSWs = [Link]; while ([Link] >= 1) [Link](100); //Reenable Office Assisant, if it was on: if (bAssistantOn) { [Link] = true; [Link] = false; } //Close the presentation without saving changes and quit PowerPoint. [Link]("C:\\[Link]", [Link], [Link]); [Link](); [Link](); }

} }

You might also like