次の方法で共有


ノート スライドを操作する

このトピックでは、Open XML SDK for Office NotesSlide クラスと、Open XML ファイル形式 PresentationML スキーマとの関係について説明します。


PresentationML 内のノート スライド

ISO/IEC 29500 の仕様には、PresentationML ドキュメント内のノート マスター ID を表す Open XML の PresentationML <notes/> 要素が次のように説明されています。

この要素は、ノート スライドが存在することと共に、対応するデータを指定します。 ノート スライドには、すべての共通スライド要素と、ノート要素に固有の追加プロパティが含まれます。

: 次の PresentationML ノート スライドについて考えます。

<p:notes>
    <p:cSld>
        …
    </p:cSld>
    …
</p:notes>

上の例で notes 要素は、ノート スライドとそのすべての部分の存在を指定しています。 cSld 要素では任意のスライド種類で使用できる共通要素を指定し、次に任意の要素でそのノート スライドの追加の非共通プロパティを指定します。

© ISO/IEC 29500: 2016

<notes/> 要素は、PresentationML ノート スライド パーツのルート要素です。 PresentationML ドキュメントを構成するパーツと要素の全体的な構造の詳細については、「PresentationML ドキュメントの構造」を参照してください。

次の表は、ノート スライドを操作するときに使用される <notes/> 要素の子要素と、それらに対応する Open XML SDK クラスの一覧です。

PresentationML 要素 Open XML SDK クラス
<clrMapOvr/> ColorMapOverride
<cSld/> CommonSlideData
<extLst/> ExtensionListWithModification

ISO/IEC 29500 の仕様に記載されている以下の表は、<notes/> 要素の属性です。

属性 説明
showMasterPhAnim (マスター プレースホルダー アニメーションの表示) マスター スライドからプレースホルダーにアニメーションを表示するかどうかを指定します。

この属性に使用できる値は、W3C XML スキーマ boolean データ型によって定義されます。
showMasterSp (マスター シェイプを表示) マスター スライド上の図形をスライドに表示するかどうかを指定します。

この属性に使用できる値は、W3C XML スキーマ boolean データ型によって定義されます。

© ISO/IEC 29500: 2016


OPEN XML SDK NotesSlide クラス

OXML SDK NotesSlide クラスは、PresentationML ドキュメントの Open XML ファイル形式スキーマで定義されている <notes/> 要素を表します。 PresentationML ドキュメント内の個々の<notes/>要素を操作するには、NotesSlide クラスを使用します。

<notes/> 要素の子要素を表すクラス、したがって一般的に NotesSlide クラスに関連付けられているクラスを次の一覧に示します。

  • ColorMapOverride クラス

    ColorMapOverride クラスは、<clrMapOvr/> 要素に対応します。 ISO/IEC 29500 仕様の次の情報では、<clrMapOvr/>要素について説明します。

    この要素は、<ClrMap/> 要素内で設定されている配色を変更するメカニズムを提供します。 <masterClrMapping/> 子要素が存在する場合は、マスターによって定義される配色が使用されます。 <overrideClrMapping/> 子要素が存在する場合は、親ノート スライド、プレゼンテーションのスライド、またはスライドのレイアウトに固有の新しい配色が定義されます。

© ISO/IEC 29500: 2016

  • CommonSlideData クラス

    CommonSlideData クラスは、<cSld/> 要素に対応します。 ISO/IEC 29500 仕様の次の情報では、<cSld/>要素について説明します。

    この要素は、すべてのスライドの種類に関連する、スライド情報の種類のコンテナーを指定します。 すべてのスライドは、スライドの種類に依存しないプロパティの共通セットを共有します。特定のスライドのこれらのプロパティの説明は、スライドの <cSld/> コンテナー内に格納されます。 親要素によって示されるスライドの種類に固有のスライド データは、別の場所に保存されます。

    <cSld/> の実際のデータには、特定の親スライドだけが記述されています。保存されているのは、すべてのスライドに共通する情報の種類だけです。

    © ISO/IEC 29500: 2016

  • ExtensionListWithModification クラス

    ExtensionListWithModification クラスは、<extLst/>element に対応します。 ISO/IEC 29500 仕様の次の情報では、<extLst/>要素について説明します。

    要素タイプ <ext/> のすべての将来的な拡張が定義された、修正可能な拡張リストを指定します。 拡張リストは、対応する将来的な拡張と共に、PresentationML フレームワークの格納能力を拡張するために使用されます。 これにより、さまざまな新たな種類のデータをこのフレームワークにネイティブに格納できます。

    [注: この extLst 要素を使用すると、生成元アプリケーションではこの拡張プロパティが変更されたかどうかを格納できます。 注の終了]

    © ISO/IEC 29500: 2016


NotesSlide クラスを操作する

次の Open XML SDK コード サンプルに示すように、 NotesSlide クラスのすべてのインスタンスは、ノート スライド パーツ、PresentationML プレゼンテーション ファイル パッケージの 1 つの部分、プレゼンテーション ファイル内の各ノート スライドに必要な部分を表す NotesSlidePart クラスのインスタンスに関連付けられます。 各 NotesSlide クラス インスタンスは、 NotesMaster クラスのインスタンスに関連付けることもできます。このインスタンスは、同様の名前のプレゼンテーション パーツに関連付けられ、 NotesMasterPart クラスによって表されます。

したがって、<notes/>要素を表す NotesSlide クラスは、<notes/> 要素の子要素を表す一連の他のクラスにも関連付けられます。 次のコード サンプルに示すように、これらのクラスの中には、 CommonSlideData クラスと ColorMapOverride クラスがあります。 ShapeTree クラスとShape クラスは、CommonSlideData クラスに関連付けられます。


Open XML SDK コード例

次のコード スニペットでは、 P 名前空間を表し、 D 名前空間を表します。

次のスニペットでは、プレゼンテーションがPresentation.Openで開き、プレゼンテーションにSlidePartがまだない場合は、最初のSlidePartが取得または追加されます。

using (PresentationDocument presentationDocument = PresentationDocument.Open(pptxPath, true) ?? throw new Exception("Presentation Document does not exist"))
{
    // Get the first slide in the presentation or use the InsertNewSlide.InsertNewSlideIntoPresentation helper method to insert a new slide.
    SlidePart slidePart = presentationDocument.PresentationPart?.SlideParts.FirstOrDefault() ?? InsertNewSlideNS.InsertNewSlide(presentationDocument, 1, "my new slide");

    // Add a new NoteSlidePart if one does not already exist
    NotesSlidePart notesSlidePart = slidePart.NotesSlidePart ?? slidePart.AddNewPart<NotesSlidePart>();

このスニペットでは、 NoteSlide がまだ存在しない場合は、 NoteSlidePart に追加されます。 NotesSlide クラス コンストラクターは、CommonSlideData クラスのインスタンスを作成します。 CommonSlideData クラス コンストラクターは、ShapeTree クラスのインスタンスを作成します。そのコンストラクターでは、NonVisualGroupShapeProperties クラスのインスタンス、GroupShapeProperties クラスのインスタンス、Shape クラスのインスタンスなどの追加のクラス インスタンスが作成されます。

// Add a NoteSlide to the NoteSlidePart if one does not already exist.
notesSlidePart.NotesSlide ??= new P.NotesSlide(
    new P.CommonSlideData(
        new P.ShapeTree(
            new P.NonVisualGroupShapeProperties(
                new P.NonVisualDrawingProperties() { Id = 1, Name = "" },
                new P.NonVisualGroupShapeDrawingProperties(),
                new P.ApplicationNonVisualDrawingProperties()),
            new P.GroupShapeProperties(
                new D.Transform2D(
                    new D.Offset() { X = 0, Y = 0 },
                    new D.Extents() { Cx = 0, Cy = 0 },
                    new D.ChildOffset() { X = 0, Y = 0 },
                    new D.ChildExtents() { Cx = 0, Cy = 0 })),

Shape コンストラクターは、必要な子要素と共に、NonVisualShapePropertiesShapeProperties、および TextBody クラスのインスタンスを作成します。 TextBodyには、メモのテキストを含むRunを持つParagraphが含まれています。 その後、スライド パーツがノート スライド パーツに追加されます。

            new P.Shape(
                new P.NonVisualShapeProperties(
                    new P.NonVisualDrawingProperties() { Id = 3, Name = "test Placeholder 3" },
                    new P.NonVisualShapeDrawingProperties(),
                    new P.ApplicationNonVisualDrawingProperties(
                        new P.PlaceholderShape() { Type = PlaceholderValues.Body, Index = 1 })),
                new P.ShapeProperties(),
                new P.TextBody(
                    new D.BodyProperties(),
                    new D.Paragraph(
                        new D.Run(
                            new D.Text("This is a test note!"))))))));

notesSlidePart.AddPart(slidePart);

上記のコードで作成したノート スライド パーツには、次の XML が含まれています

<?xml version="1.0" encoding="utf-8"?>
<p:notes xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
  <p:cSld>
    <p:spTree>
      <p:nvGrpSpPr>
        <p:cNvPr id="1" name=""/>
        <p:cNvGrpSpPr/>
        <p:nvPr/>
      </p:nvGrpSpPr>
      <p:grpSpPr>
        <a:xfrm xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
          <a:off x="0" y="0"/>
          <a:ext cx="0" cy="0"/>
          <a:chOff x="0" y="0"/>
          <a:chExt cx="0" cy="0"/>
        </a:xfrm>
      </p:grpSpPr>
      <p:sp>
        <p:nvSpPr>
          <p:cNvPr id="3" name="test Placeholder 3"/>
          <p:cNvSpPr/>
          <p:nvPr/>
        </p:nvSpPr>
        <p:spPr/>
        <p:txBody>
          <a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
          <a:p xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
            <a:r>
              <a:t>This is a test note!</a:t>
            </a:r>
          </a:p>
        </p:txBody>
      </p:sp>
    </p:spTree>
  </p:cSld>
</p:notes>

次のスニペットは、必要な NotesMasterPart を追加し、不足している場合は ThemePart します。

// Add the required NotesMasterPart if it is missing
NotesMasterPart notesMasterPart = notesSlidePart.NotesMasterPart ?? notesSlidePart.AddNewPart<NotesMasterPart>();

// Add a NotesMaster to the NotesMasterPart if not present
notesMasterPart.NotesMaster ??= new NotesMaster(
new P.CommonSlideData(
    new P.ShapeTree(
        new P.NonVisualGroupShapeProperties(
            new P.NonVisualDrawingProperties() { Id = 1, Name = "New Placeholder" },
            new P.NonVisualGroupShapeDrawingProperties(),
            new P.ApplicationNonVisualDrawingProperties()),
        new P.GroupShapeProperties())),
new P.ColorMap()
{
    Background1 = D.ColorSchemeIndexValues.Light1,
    Background2 = D.ColorSchemeIndexValues.Light2,
    Text1 = D.ColorSchemeIndexValues.Dark1,
    Text2 = D.ColorSchemeIndexValues.Dark2,
    Accent1 = D.ColorSchemeIndexValues.Accent1,
    Accent2 = D.ColorSchemeIndexValues.Accent2,
    Accent3 = D.ColorSchemeIndexValues.Accent3,
    Accent4 = D.ColorSchemeIndexValues.Accent4,
    Accent5 = D.ColorSchemeIndexValues.Accent5,
    Accent6 = D.ColorSchemeIndexValues.Accent6,
    Hyperlink = D.ColorSchemeIndexValues.Hyperlink,
    FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink,
});

// Add a new ThemePart for the NotesMasterPart
ThemePart themePart = notesMasterPart.ThemePart ?? notesMasterPart.AddNewPart<ThemePart>();

// Add the Theme if it is missing
themePart.Theme ??= new Theme(
    new ThemeElements(
        new ColorScheme(
            new Dark1Color(
                new SystemColor() { Val = SystemColorValues.WindowText }),
            new Light1Color(
                new SystemColor() { Val = SystemColorValues.Window }),
            new Dark2Color(
                new RgbColorModelHex() { Val = "f1d7be" }),
            new Light2Color(
                new RgbColorModelHex() { Val = "171717" }),
            new Accent1Color(
                new RgbColorModelHex() { Val = "ea9f7d" }),
            new Accent2Color(
                new RgbColorModelHex() { Val = "168ecd" }),
            new Accent3Color(
                new RgbColorModelHex() { Val = "e694db" }),
            new Accent4Color(
                new RgbColorModelHex() { Val = "f0612a" }),
            new Accent5Color(
                new RgbColorModelHex() { Val = "5fd46c" }),
            new Accent6Color(
                new RgbColorModelHex() { Val = "b158d1" }),
            new D.Hyperlink(
                new RgbColorModelHex() { Val = "699f82" }),
            new FollowedHyperlinkColor(
                new RgbColorModelHex() { Val = "699f82" }))
        { Name = "Office2" },
        new D.FontScheme(
            new MajorFont(
                new LatinFont(),
                new EastAsianFont(),
                new ComplexScriptFont()),
            new MinorFont(
                new LatinFont(),
                new EastAsianFont(),
                new ComplexScriptFont()))
        { Name = "Office2" },
        new FormatScheme(
            new FillStyleList(
                new NoFill(),
                new SolidFill(),
                new D.GradientFill(),
                new D.BlipFill(),
                new D.PatternFill(),
                new GroupFill()),
            new LineStyleList(
                new D.Outline(),
                new D.Outline(),
                new D.Outline()),
            new EffectStyleList(
                new EffectStyle(
                    new EffectList()),
                new EffectStyle(
                    new EffectList()),
                new EffectStyle(
                    new EffectList())),
            new BackgroundFillStyleList(
                new NoFill(),
                new SolidFill(),
                new D.GradientFill(),
                new D.BlipFill(),
                new D.PatternFill(),
                new GroupFill()))
        { Name = "Office2" }),
    new ObjectDefaults(),
    new ExtraColorSchemeList());

サンプル コード

以下に、C# と Visual Basic の両方の完全なサンプル コードを示します。

using (PresentationDocument presentationDocument = PresentationDocument.Open(pptxPath, true) ?? throw new Exception("Presentation Document does not exist"))
{
    // Get the first slide in the presentation or use the InsertNewSlide.InsertNewSlideIntoPresentation helper method to insert a new slide.
    SlidePart slidePart = presentationDocument.PresentationPart?.SlideParts.FirstOrDefault() ?? InsertNewSlideNS.InsertNewSlide(presentationDocument, 1, "my new slide");

    // Add a new NoteSlidePart if one does not already exist
    NotesSlidePart notesSlidePart = slidePart.NotesSlidePart ?? slidePart.AddNewPart<NotesSlidePart>();

    // Add a NoteSlide to the NoteSlidePart if one does not already exist.
    notesSlidePart.NotesSlide ??= new P.NotesSlide(
        new P.CommonSlideData(
            new P.ShapeTree(
                new P.NonVisualGroupShapeProperties(
                    new P.NonVisualDrawingProperties() { Id = 1, Name = "" },
                    new P.NonVisualGroupShapeDrawingProperties(),
                    new P.ApplicationNonVisualDrawingProperties()),
                new P.GroupShapeProperties(
                    new D.Transform2D(
                        new D.Offset() { X = 0, Y = 0 },
                        new D.Extents() { Cx = 0, Cy = 0 },
                        new D.ChildOffset() { X = 0, Y = 0 },
                        new D.ChildExtents() { Cx = 0, Cy = 0 })),
                new P.Shape(
                    new P.NonVisualShapeProperties(
                        new P.NonVisualDrawingProperties() { Id = 3, Name = "test Placeholder 3" },
                        new P.NonVisualShapeDrawingProperties(),
                        new P.ApplicationNonVisualDrawingProperties(
                            new P.PlaceholderShape() { Type = PlaceholderValues.Body, Index = 1 })),
                    new P.ShapeProperties(),
                    new P.TextBody(
                        new D.BodyProperties(),
                        new D.Paragraph(
                            new D.Run(
                                new D.Text("This is a test note!"))))))));

    notesSlidePart.AddPart(slidePart);

    // Add the required NotesMasterPart if it is missing
    NotesMasterPart notesMasterPart = notesSlidePart.NotesMasterPart ?? notesSlidePart.AddNewPart<NotesMasterPart>();

    // Add a NotesMaster to the NotesMasterPart if not present
    notesMasterPart.NotesMaster ??= new NotesMaster(
    new P.CommonSlideData(
        new P.ShapeTree(
            new P.NonVisualGroupShapeProperties(
                new P.NonVisualDrawingProperties() { Id = 1, Name = "New Placeholder" },
                new P.NonVisualGroupShapeDrawingProperties(),
                new P.ApplicationNonVisualDrawingProperties()),
            new P.GroupShapeProperties())),
    new P.ColorMap()
    {
        Background1 = D.ColorSchemeIndexValues.Light1,
        Background2 = D.ColorSchemeIndexValues.Light2,
        Text1 = D.ColorSchemeIndexValues.Dark1,
        Text2 = D.ColorSchemeIndexValues.Dark2,
        Accent1 = D.ColorSchemeIndexValues.Accent1,
        Accent2 = D.ColorSchemeIndexValues.Accent2,
        Accent3 = D.ColorSchemeIndexValues.Accent3,
        Accent4 = D.ColorSchemeIndexValues.Accent4,
        Accent5 = D.ColorSchemeIndexValues.Accent5,
        Accent6 = D.ColorSchemeIndexValues.Accent6,
        Hyperlink = D.ColorSchemeIndexValues.Hyperlink,
        FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink,
    });

    // Add a new ThemePart for the NotesMasterPart
    ThemePart themePart = notesMasterPart.ThemePart ?? notesMasterPart.AddNewPart<ThemePart>();

    // Add the Theme if it is missing
    themePart.Theme ??= new Theme(
        new ThemeElements(
            new ColorScheme(
                new Dark1Color(
                    new SystemColor() { Val = SystemColorValues.WindowText }),
                new Light1Color(
                    new SystemColor() { Val = SystemColorValues.Window }),
                new Dark2Color(
                    new RgbColorModelHex() { Val = "f1d7be" }),
                new Light2Color(
                    new RgbColorModelHex() { Val = "171717" }),
                new Accent1Color(
                    new RgbColorModelHex() { Val = "ea9f7d" }),
                new Accent2Color(
                    new RgbColorModelHex() { Val = "168ecd" }),
                new Accent3Color(
                    new RgbColorModelHex() { Val = "e694db" }),
                new Accent4Color(
                    new RgbColorModelHex() { Val = "f0612a" }),
                new Accent5Color(
                    new RgbColorModelHex() { Val = "5fd46c" }),
                new Accent6Color(
                    new RgbColorModelHex() { Val = "b158d1" }),
                new D.Hyperlink(
                    new RgbColorModelHex() { Val = "699f82" }),
                new FollowedHyperlinkColor(
                    new RgbColorModelHex() { Val = "699f82" }))
            { Name = "Office2" },
            new D.FontScheme(
                new MajorFont(
                    new LatinFont(),
                    new EastAsianFont(),
                    new ComplexScriptFont()),
                new MinorFont(
                    new LatinFont(),
                    new EastAsianFont(),
                    new ComplexScriptFont()))
            { Name = "Office2" },
            new FormatScheme(
                new FillStyleList(
                    new NoFill(),
                    new SolidFill(),
                    new D.GradientFill(),
                    new D.BlipFill(),
                    new D.PatternFill(),
                    new GroupFill()),
                new LineStyleList(
                    new D.Outline(),
                    new D.Outline(),
                    new D.Outline()),
                new EffectStyleList(
                    new EffectStyle(
                        new EffectList()),
                    new EffectStyle(
                        new EffectList()),
                    new EffectStyle(
                        new EffectList())),
                new BackgroundFillStyleList(
                    new NoFill(),
                    new SolidFill(),
                    new D.GradientFill(),
                    new D.BlipFill(),
                    new D.PatternFill(),
                    new GroupFill()))
            { Name = "Office2" }),
        new ObjectDefaults(),
        new ExtraColorSchemeList());
}

関連項目

Open XML SDK for Office について

[方法] ファイル名を指定してプレゼンテーションを作成する

[方法] プレゼンテーションに新しいスライドを挿入する

[方法] プレゼンテーションからスライドを削除する

[方法] プレゼンテーションにテーマを適用する