这是我一直在研究的代码。我想它应该显示一个带有幻灯片中的注释的消息框,但事实并非如此。此外,我不确定如何使用我的一些代码实现语音合成,但可能在错误的位置。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using System.Speech.Synthesis;
namespace FirstPowerPointAddIn
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
SpeechSynthesizer synth = new SpeechSynthesizer();
// Configure the audio output.
synth.SetOutputToDefaultAudioDevice();
PowerPoint.Application oPowerPoint = null;
try
{
oPowerPoint.SlideShowBegin += oPowerPoint_SlideShowBegin;
oPowerPoint.SlideShowNextSlide += oPowerPoint_SlideShowNextSlide;
}
catch(Exception)
{
Console.WriteLine("error");
}
}
private void ThisAddIn_Shutdown(object Pender, System.EventArgs e)
{
}
private void oPowerPoint_SlideShowBegin(SlideShowWindow Wn)
// If the slide has notes, get the notes
{
if (Wn.View.Slide.HasNotesPage == Microsoft.Office.Core.MsoTriState.msoTrue)
{
if (Wn.View.Slide.NotesPage.Shapes[2].TextFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)
System.Windows.Forms.MessageBox.Show(Wn.View.Slide.NotesPage.Shapes[2].TextFrame.TextRange.Text);
}
}
void oPowerPoint_SlideShowNextSlide(PowerPoint.SlideShowWindow Wn)
{
if (Wn.View.Slide.HasNotesPage == Microsoft.Office.Core.MsoTriState.msoTrue)
{
if (Wn.View.Slide.NotesPage.Shapes[2].TextFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)
System.Windows.Forms.MessageBox.Show(Wn.View.Slide.NotesPage.Shapes[2].TextFrame.TextRange.Text);
}
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
答案 0 :(得分:2)
对于那些感兴趣的人来说,Steve Rindsberg的VB代码的C#版本:
PowerPoint.SlideShowWindow ppWindow;
PowerPoint.Slide slide = ppWindow.View.Slide;
if (slide.HasNotesPage == MsoTriState.msoTrue) {
PowerPoint.SlideRange notesPages = slide.NotesPage;
foreach (PowerPoint.Shape shape in notesPages.Shapes) {
if (shape.Type == MsoShapeType.msoPlaceholder) {
if (shape.PlaceholderFormat.Type == PowerPoint.PpPlaceholderType.ppPlaceholderBody) {
Debug.WriteLine("Slide[" + slide.SlideIndex + "] Notes: [" + shape.TextFrame.TextRange.Text + "]");
}
}
}
}
答案 1 :(得分:0)
在较新版本的PPT中,您需要遍历形状,寻找名为Notes Placeholder#的形状(其中#是一个可能是2的数字,也可能不是2)。旧的演示文稿中的形状名称将有所不同。出于这个原因,通常最好这样做:
Sub FindTheNotesText()
Dim oSl As Slide
Dim x As Long
Set oSl = ActivePresentation.Slides(1)
With oSl.NotesPage
For x = 1 To .Shapes.Count
With .Shapes(x)
Debug.Print .Name
Debug.Print .Type
If .Type = msoPlaceholder Then
Debug.Print .PlaceholderFormat.Type
If .PlaceholderFormat.Type = ppPlaceholderBody Then
Debug.Print "^^^^^ This is the notes text placeholder"
Debug.Print .TextFrame.TextRange.Text
End If
End If
End With
Next
End With
End Sub