开发者

Want to add notes in a PowerPoint slides using VB.NET

I want to add notes in the PowerPoint slides notes part under the PowerPoint slide using Microsoft.Office.Interop.PowerPoint.

I'm using VB.NET code. Now it is creating the PPT file, and I can add text, comments, and images in the slide. But I need to add notes in the PowerPoint slide, i开发者_JAVA技巧n the bottom part of the slide.

Here is the code I'm using for creating slides.

    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


I found the following solution and it works for me:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜