我想使用Microsoft.Office.Interop.PowerPoint
在PowerPoint幻灯片下的PowerPoint幻灯片备注部分添加备注。
我正在使用VB.NET代码。现在它正在创建PPT文件,我可以在幻灯片中添加文本,注释和图像。但我需要在幻灯片底部的PowerPoint幻灯片中添加备注。
以下是我用于创建幻灯片的代码。
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
答案 0 :(得分: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";
}
}