2011-09-28 95 views
1

我想使用Microsoft.Office.Interop.PowerPoint在PowerPoint幻燈片下的PowerPoint幻燈片註釋部分中添加註釋。想要使用VB.NET在PowerPoint幻燈片中添加註釋

我正在使用VB.NET代碼。現在它創建了PPT文件,我可以在幻燈片中添加文本,註釋和圖像。但是我需要在幻燈片的底部添加筆記。

這是我用來創建幻燈片的代碼。

Dim oApp As Microsoft.Office.Interop.PowerPoint.Application 
    Dim oPres As Microsoft.Office.Interop.PowerPoint.Presentation 
    Dim oSlide As Microsoft.Office.Interop.PowerPoint.Slide 
    Dim bAssistantOn As Boolean 
    Const sTemplate = "C:\Program Files\Microsoft Office\Templates\Presentation Designs\ContemporaryPhotoAlbum.potx" 
    Const sPic = "C:\WINDOWS\Soap Bubbles.bmp" 
    oApp = New Microsoft.Office.Interop.PowerPoint.Application() 
    oApp.Visible = True 
    oApp.WindowState = Microsoft.Office.Interop.PowerPoint.PpWindowState.ppWindowMaximized 
    oApp.Visible = True 
    oPres = oApp.Presentations.Open(sTemplate, , , True) 
    oPres = oApp.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoCTrue) 
    oSlide = oPres.Slides.Add(1, PpSlideLayout.ppLayoutVerticalTitleAndText) 
    oSlide.Comments.Add(1, 1, "f", "sf", "sdfgdfg") 
    With (oSlide.Shapes.Item(1).TextFrame.TextRange) 
     .Text = "Aspire Software Consultancy" 
     .Font.Name = "Comic Sans MS" 
     .Font.Size = 48 
    End With 
    oSlide.Shapes.AddPicture(sPic, False, True, 150, 150, 500, 350) 
    oSlide = oPres.Slides.Add(2, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly) 
    With oSlide.Shapes.Item(1).TextFrame.TextRange 
     .Text = "My Chart" 
     .Font.Name = "Comic Sans MS" 
     .Font.Size = 48 
    End With 
    oSlide.NotesPage.Comments.Add(4, 4, "asd", "a", "gooooooood") 
    oSlide = oPres.Slides.Add(3, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank) 
    oSlide.FollowMasterBackground = False 
    Dim oShape As Microsoft.Office.Interop.PowerPoint.Shape 
    oShape = oSlide.Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect27, 
     "The End", "Impact", 96, False, False, 230, 200) 
    oShape.Shadow.ForeColor.SchemeColor = Microsoft.Office.Interop.PowerPoint.PpColorSchemeIndex.ppForeground 
    oShape.Shadow.Visible = True 
    oShape.Shadow.OffsetX = 3 
    oShape.Shadow.OffsetY = 3 
    oShape = Nothing 
    oSlide = Nothing 

    Dim SlideIdx(3) As Integer 
    SlideIdx(0) = 1 
    SlideIdx(1) = 2 
    SlideIdx(2) = 3 
    With oPres.Slides.Range(SlideIdx).SlideShowTransition 
     .AdvanceOnTime = True 
     .AdvanceTime = 3 
     .EntryEffect = Microsoft.Office.Interop.PowerPoint.PpEntryEffect.ppEffectBoxOut 
    End With 
    Dim oSettings As Microsoft.Office.Interop.PowerPoint.SlideShowSettings 
    oSettings = oPres.SlideShowSettings 
    oSettings.StartingSlide = 1 
    oSettings.EndingSlide = 3 
    bAssistantOn = oApp.Assistant.On 
    oApp.Assistant.On = False 
    oSettings.Run() 
    Do While oApp.SlideShowWindows.Count >= 1 
     System.Windows.Forms.Application.DoEvents() 
    Loop 
    oSettings = Nothing 
    If bAssistantOn Then 
     oApp.Assistant.On = True 
     oApp.Assistant.Visible = False 
    End If 
    oPres.Save() 
    oPres.SaveAs("c:\aspire", PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoTrue) 
    oPres.Saved = True 
    oPres.Close() 
    oPres = Nothing 
    oApp.Quit() 
    oApp = Nothing 

回答

3

我發現下面的解決方案,它爲我的作品:

if (slide.NotesPage.Shapes.Count == 0) 
{ 
    slide.NotesPage.Shapes.AddShape(MsoAutoShapeType.msoShapeRectangle, 0, 0, 0, 0); 
    var footerShape = slide.NotesPage.Shapes[1]; 
    footerShape.TextFrame.TextRange.Text = "your note text"; 
} 
else 
{ 
    foreach (PowerPoint.Shape shape in slide.NotesPage.Shapes) 
    { 
     if (shape.HasTextFrame == MsoTriState.msoTrue) 
      if (shape.TextFrame.HasText == MsoTriState.msoTrue) 
       shape.TextFrame.TextRange.Text = "yout note text"; 
    } 
} 
相關問題