0

这是我一直在处理的代码。我想它应该在幻灯片中显示一个带有注释的消息框,但事实并非如此。此外,我不确定如何使用我拥有的一些代码实现语音合成,但可能位于错误的位置。

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
}

}

4

2 回答 2

3

C# 版本的 Steve Rindsberg 的 VB 代码供有兴趣的人参考:

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 + "]");             
            }
        }
    }
}
于 2014-09-16T18:39:13.887 回答
0

没有看到演示文稿,我无法判断这是否是问题,但您假设便笺页面上的第二个形状是便笺文本占位符。通常是这样,但不一定是这样。

在较新版本的 PPT 中,您需要遍历形状以查找名为 Notes Placeholder # 的形状(其中 # 是一个可能是也可能不是 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
于 2014-01-07T20:28:23.677 回答