2013-04-24 96 views
0
編程

進出口beggineer,我試圖刪除幻燈片母版usign C#的,但它總是會拋出一個異常幻燈片母版「指定的轉換無效」有什麼辦法刪除在主幻燈片母版幻燈片或形狀..請建議。如何刪除從PPT文檔

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; 
           } 

           } 

         } 

        } 

       } 
      } 

回答

0

您無法刪除任何幻燈片所基於的主版面或版式。爲什麼要刪除主幻燈片?

要刪除的形狀:

newslide.Master.Shapes.Range.Delete

將從幻燈片母版中刪除形狀,而不是佈局幻燈片是基於,因此它可能不完全是你需要的。