如何从ppt文档中删除主幻灯片

时间:2013-04-24 09:08:21

标签: c#-3.0 powerpoint-2007

我是编程中的beggineer,我正在尝试删除主幻灯片使用c#但它总是抛出异常“指定的强制转换无效”有没有办法删除主幻灯片上的主幻灯片或形状..请建议。

 for (int i = 1; i <= SlideCount; i++)
           {
                int j=i;
                slide = Slides[i];

                //iterate over all the shapes of notespage of given slide to find the notespage's shape which has text.
                 for (int k = 1; k <= slide.NotesPage.Shapes.Count; k++)
                 {
                      var noteShape = slide.NotesPage.Shapes[k];

                     //check if the selected notespage has text or not
                     if (noteShape.Type ==MsoShapeType.msoPlaceholder)
                     {
                         if (noteShape.PlaceholderFormat.Type ==PpPlaceholderType.ppPlaceholderBody)
                         {
                             if (noteShape.HasTextFrame ==MsoTriState.msoTrue)
                             {
                                 if (noteShape.TextFrame2.HasText ==MsoTriState.msoTrue)
                                 {

                                        //create a new slide 
                                        newslide = tempslides.AddSlide(++j, customLayout);

                                        // set the  title of newslide as the text of notepage of previous slide.
                                        newslide.Shapes.Title.TextFrame.TextRange.Text = noteShape.TextFrame.TextRange.Text;

                                        //delete the notepage text; 
                                        noteShape.TextFrame.TextRange.Delete();

                                        //delete footer from slide. 
                                        //if (newslide.HeadersFooters.Footer.Visible == MsoTriState.msoTrue)
                                        //    newslide.HeadersFooters.Footer.Text = string.Empty;
                                        //newslide.HeadersFooters.DateAndTime.Text = string.Empty;
                                        //newslide.HeadersFooters.SlideNumber.Text = string.Empty;
                                        newslide.HeadersFooters.Clear();
                                        newslide.Master.Delete();




                                        //jump to next slide  
                                        i++;

                                        //increase the slide count becoz one slide has been added.
                                        SlideCount = tempslides.Count;
                                 }

                              }

                         }

                     }

                 }
             }

1 个答案:

答案 0 :(得分:0)

您无法删除任何幻灯片所基于的母版或版面。为什么要删除主幻灯片?

删除形状:

newslide.Master.Shapes.Range.Delete

这将删除幻灯片母版中的形状,但不会删除幻灯片所基于的布局,因此可能不完全符合您的需要。