1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64:
| public string CreateCoverSlide(String template, String title, String[] input) {
String strTemplate; strTemplate = template; 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;
//Create a new presentation based on a template. objApp = new PowerPoint.Application(); objApp.Visible = MsoTriState.msoTrue; objPresSet = objApp.Presentations; objPres = objPresSet.Open(strTemplate, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue); objSlides = objPres.Slides; //Build Slide #1: //Add text to the slide, change the font and insert/position a //picture on the first slide. objSlide = objSlides.Add(1, PowerPoint.PpSlideLayout.ppLayoutText); objTextRng = objSlide.Shapes[1].TextFrame.TextRange; objTextRng.Text = title;
objTextRng = objSlide.Shapes[2].TextFrame.TextRange;
for (int i = 0; i < input.Length; i++) {
objTextRng.Text = input[i]; } bAssistantOn = objApp.Assistant.On; objApp.Assistant.On = false; if (bAssistantOn) { objApp.Assistant.On = true; objApp.Assistant.Visible = false; } objPres.SaveAs(@"C:\Temp\test.ppt", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoCTrue); //Close the presentation without saving changes and quit PowerPoint. //objPres.Close(); objApp.Quit(); |