Style クラス

定義

スタイルの定義です。 オブジェクトを xml としてシリアル化されるときに、修飾名は、w:style です。

[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.StyleName))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.Aliases))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.BasedOn))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.NextParagraphStyle))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.LinkedStyle))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.AutoRedefine))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.StyleHidden))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.UIPriority))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.SemiHidden))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.UnhideWhenUsed))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.PrimaryStyle))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.Locked))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.Personal))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.PersonalCompose))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.PersonalReply))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.Rsid))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.StyleParagraphProperties))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.StyleRunProperties))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.StyleTableProperties))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.TableStyleConditionalFormattingTableRowProperties))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.StyleTableCellProperties))]
[DocumentFormat.OpenXml.ChildElementInfo(typeof(DocumentFormat.OpenXml.Wordprocessing.TableStyleProperties))]
public class Style : DocumentFormat.OpenXml.OpenXmlCompositeElement
type Style = class
    inherit OpenXmlCompositeElement
Public Class Style
Inherits OpenXmlCompositeElement
継承
属性

次のコード例では、一部のテキストが含まれていて、最初の段落に [見出し 1] スタイルを適用するワード プロセッシング ファイルを開きます。

using System;  
using System.Linq;  
using DocumentFormat.OpenXml.Packaging;  
using DocumentFormat.OpenXml.Wordprocessing;  

namespace StyleEx  
{  
    class Program  
    {  
        // Apply the Heading 1 style to a paragraph.  
        static void Main(string[] args)  
        {  
            string fileName = @"C:\users\public\documents\StyleEx.docx";  

            using (WordprocessingDocument document =   
                WordprocessingDocument.Open(fileName, true))  
            {  
                // Get the first paragraph.  
                Paragraph p =  
                    document.MainDocumentPart.Document.Body.Elements<Paragraph>().First();  

                // If the paragraph has no ParagraphProperties objects, create a new one for it.  
                if (p.Elements<ParagraphProperties>().Count() == 0)  
                {  
                    p.PrependChild<ParagraphProperties>(new ParagraphProperties());  
                }  

                // Get the paragraph properties element of the paragraph.  
                ParagraphProperties pPr = p.Elements<ParagraphProperties>().First();  

                // Set the paragraph style ID to "Heading1".  
                pPr.ParagraphStyleId = new ParagraphStyleId() { Val = "Heading1" };                
            }  
        }  
    }  
}  
Imports System.Linq  
Imports DocumentFormat.OpenXml.Wordprocessing  
Imports DocumentFormat.OpenXml.Packaging  

Module Module1  
    ' Apply the Heading 1 style to a paragraph.  
    Sub Main()  
        Dim fileName As String = "C:\Users\Public\Documents\StyleEx.docx"  

        Using doc As WordprocessingDocument = _  
            WordprocessingDocument.Open(fileName, True)  
            ' Get the first paragraph.  
            Dim p As Paragraph = doc.MainDocumentPart.Document.Body.Elements _  
                (Of Paragraph).First()  

            ' If the paragraph has no ParagraphProperties objects, create a new one for it.  
            If p.Elements(Of ParagraphProperties).Count() = 0 Then  
                p.PrependChild(Of ParagraphProperties)(New ParagraphProperties())  
            End If  

            ' Get the paragraph properties element of the paragraph.  
            Dim pPr As ParagraphProperties = p.Elements(Of ParagraphProperties).First()  

            ' Set the paragraph style ID to "Heading1".  
            pPr.ParagraphStyleId = New ParagraphStyleId() With {.Val = "Heading1"}  
        End Using  
    End Sub  
End Module  

注釈

[ISO/IEC 29500-1 1st Edition]

スタイル (スタイル定義)

WordprocessingML ドキュメント内の 1 つのスタイルの定義を指定します。 スタイルとは、表、段落番号、段落、文字プロパティは、ドキュメント内の領域に適用できる一連の定義済みです。

スタイル定義のすべてのスタイル定義は、3 つのセグメントに分割できます。

  • 一般的なスタイルのプロパティ

  • スタイルの種類

  • スタイルの種類に固有のプロパティ

一般的なスタイルのプロパティは、スタイルの種類に関係なく使用できるプロパティのセットを参照します。などのスタイルの別名を追加 (スタイルを参照するドキュメントのコンテンツで使用される)、スタイル ID、スタイルのスタイルが表示されていない場合、スタイルがロックされている場合などです。

[の使用例: ドキュメントを次のように見出しと呼ばれるスタイルを検討してください。

<w:style w:type="paragraph" w:styleId="Heading1">  
  <w:name w:val="Heading 1"/>  
  <w:basedOn w:val="Normal"/>  
  <w:next w:val="Normal"/>  
  <w:link w:val="Heading1Char"/>  
  <w:uiPriority w:val="1"/>  
  <w:qformat/>  
  <w:rsid w:val="00F303CE"/>  
  …</w:style>  

このスタイルの種類に固有の書式情報の上、すべてのスタイルの種類が共有する情報を定義する一般的なスタイル プロパティのセットです。 例終わり]

スタイルの種類とは、このスタイル定義で作成されるスタイルの種類を定義する、スタイルに関するプロパティのことです。 WordprocessingML では、スタイル定義の type 属性の値によって、次の 6 種類のスタイル定義をサポートしています。

  • 段落スタイル

  • 文字スタイル

  • リンクされたスタイル (段落 + 文字) [メモ: link 要素 (§17.7.4.6) により実現。メモ終了]

  • 表スタイル

  • 番号付けスタイル

  • 既定の段落と文字のプロパティ

[の使用例: ドキュメントを次のように見出しと呼ばれるスタイルを検討してください。

<w:style w:type="paragraph" w:styleId="Heading1">  
  <w:name w:val="heading 1"/>  
  <w:basedOn w:val="Normal"/>  
  <w:next w:val="Normal"/>  
  <w:link w:val="Heading1Char"/>  
  <w:uiPriority w:val="1"/>  
  <w:qformat/>  
  <w:rsid w:val="00F303CE"/>  
  …</w:style>  

Type 属性はの段落、次のスタイル定義が段落スタイルであることを示す値を持ちます。 例終わり]

スタイルのペイロードには、スタイルの種類に固有のプロパティ: スタイルの型にのみ適用されるすべてのプロパティと同様にその情報を書式設定します。

[:標準のテーブルは次のように定義されているプライマリの名前のテーブル スタイルを検討してください。

<w:style w:type="table" w:default="1" w:styleId="TableNormal">  
  <w:name w:val="Normal Table"/>  
  …  <w:tblPr>  
    <w:tblInd w:w="0" w:type="dxa"/>  
    <w:tblCellMar>  
      <w:top w:w="0" w:type="dxa"/>  
      <w:left w:w="108" w:type="dxa"/>  
      <w:bottom w:w="0" w:type="dxa"/>  
      <w:right w:w="108" w:type="dxa"/>  
    </w:tblCellMar>  
  </w:tblPr>  
</w:style>  

TblPr 要素には、この表のスタイル、表スタイルにのみ適用されるの書式設定のペイロードが含まれています。 例終わり]

親要素
スタイル (§17.7.4.18)
子要素
エイリアス (別名スタイル) §17.7.4.1
autoRedefine (自動的にマージ ユーザー書式をスタイルの定義) §17.7.4.2
basedOn (親スタイル ID) §17.7.4.3
非表示 (非表示にするスタイルからのユーザー インターフェイス) §17.7.4.4
リンク (リンクされたスタイル参照) §17.7.4.6
ロック (スタイルを適用できません) §17.7.4.7
名 (主スタイル名) §17.7.4.9
次へ (次の段落のスタイル) §17.7.4.10
パーソナル (電子メール メッセージのテキストのスタイル) §17.7.4.11
personalCompose (電子メール メッセージのコンポジションのスタイル) §17.7.4.12
personalReply (電子メール メッセージの返信スタイル) §17.7.4.13
pPr (スタイルの段落のプロパティ) §17.7.8.2
qFormat (主要なスタイル) §17.7.4.14
rPr (実行のプロパティ) §17.7.9.1
rsid (スタイル定義のリビジョン Id) §17.7.4.15
semiHidden (非表示にするスタイルからメインのユーザー インターフェイス) §17.7.4.16
tblPr (表のプロパティをスタイル) §17.7.6.4
tblStylePr (スタイル条件付きの表の書式設定のプロパティ) §17.7.6.6
tcPr (表のセル プロパティのスタイル) §17.7.6.9
trPr (スタイルのテーブル行のプロパティ) §17.7.6.11
uiPriority (省略可能なユーザー インターフェイスの並べ替え順序) §17.7.4.19
(削除 Semi-Hidden プロパティとスタイルを使用) unhideWhenUsed §17.7.4.20

[: この要素のコンテンツ モデル (CT_Style) の W3C XML スキーマ定義は §A.1 であります。 メモの終了)

ISO/IEC29500: 2008。

コンストラクター

Style()

Style クラスの新しいインスタンスを初期化します。

Style(IEnumerable<OpenXmlElement>)

指定された子要素にスタイル クラスの新しいインスタンスを初期化します。

Style(OpenXmlElement[])

指定された子要素にスタイル クラスの新しいインスタンスを初期化します。

Style(String)

外側の XML のスタイル クラスの新しいインスタンスを初期化します。

プロパティ

Aliases

代替スタイルの名前です。 スキーマでは、次の要素タグを表します w:aliases。

AutoRedefine

スタイル定義にユーザーが書式設定を自動的にマージします。 スキーマでは、次の要素タグを表します w:autoRedefine。

BasedOn

親スタイルの id。 スキーマでは、次の要素タグを表します w:basedOn。

ChildElements

現在の要素のすべての子ノードを取得します。

(継承元 OpenXmlElement)
CustomStyle

ユーザー定義のスキーマの属性の次の Style.Represents: w:customStyle

Default

既定のスキーマの属性の次の Style.Represents: w:default

ExtendedAttributes

現在の要素のすべての拡張属性 (スキーマで定義されていない属性) を取得します。

(継承元 OpenXmlElement)
FirstChild

現在の OpenXmlElement 要素の最初の子を取得します。

(継承元 OpenXmlCompositeElement)
HasAttributes

現在の要素に属性が含されているかどうかを示すブール値を取得します。

(継承元 OpenXmlElement)
HasChildren

現在の要素に子要素が含されているかどうかを示す値を取得します。

(継承元 OpenXmlCompositeElement)
InnerText

現在のノードとそのすべての子の連結値を取得または設定します。

(継承元 OpenXmlCompositeElement)
InnerXml

現在のノードの子ノードのみを表すマークアップを取得または設定します。

(継承元 OpenXmlCompositeElement)
LastChild

現在の OpenXmlElement 要素の最後の子を取得します。 このような OpenXmlElement 要素がないVisual Basic null (Nothing in Visual Basic) を返します。

(継承元 OpenXmlCompositeElement)
LinkedStyle

リンクされたスタイルの参照。 スキーマでは、次の要素タグを表します w:link。

LocalName

要素のローカル名を取得します。

Locked

スタイルを適用することはできません。 スキーマでは、次の要素タグを表します w: ロックされている。

MCAttributes

マークアップの互換性属性を設定します。 現在の要素に対してマークアップ互換性属性が定義されていない場合は null を返します。

(継承元 OpenXmlElement)
NamespaceDeclarations

現在の要素で定義されている名前空間宣言を取得します。 名前空間宣言がない場合は、空の列挙子を返します。

(継承元 OpenXmlElement)
NamespaceUri

現在の要素の名前空間 URI を取得します。

(継承元 OpenXmlElement)
NextParagraphStyle

次の段落のスタイルです。 スキーマでは、次の要素タグを表します w:next。

OpenXmlElementContext

現在の要素の OpenXmlEementContext を取得します。

(継承元 OpenXmlElement)
OuterXml

現在の要素とそのすべての子要素を表すマークアップを取得します。

(継承元 OpenXmlElement)
Parent

現在の要素の親要素を取得します。

(継承元 OpenXmlElement)
Personal

電子メール メッセージのテキストのスタイル。 スキーマでは、次の要素タグを表します w:personal。

PersonalCompose

電子メール メッセージのコンポジションのスタイルです。 スキーマでは、次の要素タグを表します w:personalCompose。

PersonalReply

電子メール メッセージの返信スタイルです。 スキーマでは、次の要素タグを表します w:personalReply。

Prefix

現在の要素の名前空間プレフィックスを取得します。

(継承元 OpenXmlElement)
PrimaryStyle

主なスタイルです。 スキーマでは、次の要素タグを表します w:qFormat。

Rsid

スタイル定義のリビジョン Id。 スキーマでは、次の要素タグを表します w:rsid。

SemiHidden

メイン ユーザー インターフェイスからのスタイルを非表示にします。 スキーマでは、次の要素タグを表します w:semiHidden。

StyleHidden

ユーザー ・ インタ フェースからのスタイルを非表示にします。 スキーマでは、次の要素タグを表します w: 非表示。

StyleId

スタイルの id。スキーマでは、次の属性を表します w:styleId。

StyleName

主スタイル名です。 スキーマでは、次の要素タグを表します w:name。

StyleParagraphProperties

スタイルの段落のプロパティです。 スキーマでは、次の要素タグを表します w:pPr。

StyleRunProperties

プロパティを実行します。 スキーマでは、次の要素タグを表します w:rPr。

StyleTableCellProperties

スタイルのテーブルのセルのプロパティです。 スキーマでは、次の要素タグを表します w:tcPr。

StyleTableProperties

スタイルのテーブルのプロパティです。 スキーマでは、次の要素タグを表します w:tblPr。

TableStyleConditionalFormattingTableRowProperties

スタイルのテーブルの行のプロパティです。 スキーマでは、次の要素タグを表します w:trPr。

Type

スタイル Type.Represents のスキーマに次の属性: w:type

UIPriority

オプションのユーザー インターフェイスの並べ替え順序です。 スキーマでは、次の要素タグを表します w:uiPriority。

UnhideWhenUsed

スタイルを使用する場合は、部分的に非表示のプロパティを削除します。 スキーマでは、次の要素タグを表します w:unhideWhenUsed。

XmlQualifiedName

現在の要素の修飾名を取得します。

(継承元 OpenXmlElement)
XName

現在の要素の修飾名を取得します。

(継承元 OpenXmlElement)

メソッド

AddAnnotation(Object)

現在の OpenXmlElement 要素の注釈の一覧にオブジェクトを追加します。

(継承元 OpenXmlElement)
AddNamespaceDeclaration(String, String)

現在のノードに namepace 宣言を追加します。

(継承元 OpenXmlElement)
Ancestors()

現在の要素のすべての先祖を列挙します。

(継承元 OpenXmlElement)
Ancestors<T>()

指定した型を持つ現在の要素の先祖のみを列挙します。

(継承元 OpenXmlElement)
Annotation(Type)

現在の OpenXmlElement 要素から、指定した型の最初の注釈オブジェクトを取得します。

(継承元 OpenXmlElement)
Annotation<T>()

現在の OpenXmlElement 要素から、指定した型の最初の注釈オブジェクトを取得します。

(継承元 OpenXmlElement)
Annotations(Type)

現在の OpenXmlElement 要素の指定した型を持つ注釈のコレクションを取得します。

(継承元 OpenXmlElement)
Annotations<T>()

現在の OpenXmlElement 要素の指定した型を持つ注釈のコレクションを取得します。

(継承元 OpenXmlElement)
Append(IEnumerable<OpenXmlElement>)

要素のリストから、現在の要素の子要素のリストの末尾に各要素を追加します。

(継承元 OpenXmlElement)
Append(OpenXmlElement[])

要素の配列から、現在の要素の子要素のリストの末尾に各要素を追加します。

(継承元 OpenXmlElement)
AppendChild<T>(T)

指定した要素を、現在の要素の子ノードのリストの末尾に追加します。

(継承元 OpenXmlCompositeElement)
ClearAllAttributes()

既知の属性と拡張属性の両方を含む、すべての属性をクリアします。

(継承元 OpenXmlElement)
Clone()

現在のノードの複製を作成します。

(継承元 OpenXmlElement)
CloneNode(Boolean)

このノードの複製を作成します。

Descendants()

現在の要素のすべての子孫を列挙します。

(継承元 OpenXmlElement)
Descendants<T>()

現在の要素の T 型のすべての子孫を列挙します。

(継承元 OpenXmlElement)
Elements()

現在の要素のすべての子を列挙します。

(継承元 OpenXmlElement)
Elements<T>()

指定した型を持つ現在の要素の子のみを列挙します。

(継承元 OpenXmlElement)
ElementsAfter()

現在の要素に従い、現在の要素と同じ親を持つすべての兄弟要素を列挙します。

(継承元 OpenXmlElement)
ElementsBefore()

現在の要素の前に、現在の要素と同じ親を持つすべての兄弟要素を列挙します。

(継承元 OpenXmlElement)
GetAttribute(String, String)

指定したタグ名と名前空間 URI を持つ Open XML 属性を取得します。

(継承元 OpenXmlElement)
GetAttributes()

すべての属性のコピーを含むリストを取得します。

(継承元 OpenXmlElement)
GetEnumerator()

子コレクションを反復処理する列挙子を返します。

(継承元 OpenXmlElement)
GetFirstChild<T>()

型 T の最初の子要素を検索します。

(継承元 OpenXmlElement)
InsertAfter<T>(T, OpenXmlElement)

指定した参照要素の直後に、指定した要素を挿入します。

(継承元 OpenXmlCompositeElement)
InsertAfterSelf<T>(T)

現在の要素の直後に指定した要素を挿入します。

(継承元 OpenXmlElement)
InsertAt<T>(T, Int32)

現在の要素の子の指定したインデックスに、指定した要素を挿入します。

(継承元 OpenXmlCompositeElement)
InsertBefore<T>(T, OpenXmlElement)

指定した参照要素の直前に、指定した要素を挿入します。

(継承元 OpenXmlCompositeElement)
InsertBeforeSelf<T>(T)

現在の要素の直前に指定した要素を挿入します。

(継承元 OpenXmlElement)
IsAfter(OpenXmlElement)

ドキュメントの順序で指定した要素の後に現在の要素が表示されるかどうかを指定します。

(継承元 OpenXmlElement)
IsBefore(OpenXmlElement)

現在の要素が文書の順序で指定された要素の前に表示されるかどうかを指定します。

(継承元 OpenXmlElement)
LookupNamespace(String)

現在のノードのコンテキストで名前空間プレフィックスを解決します。

(継承元 OpenXmlElement)
LookupPrefix(String)

現在の要素スコープ内の名前空間 uri の対応するプレフィックスを検索します。

(継承元 OpenXmlElement)
NextSibling()

現在の OpenXmlElement 要素の直後にある OpenXmlElement 要素を取得します。 次の OpenXmlElement 要素がないVisual Basic null (Nothing in Visual Basic) を返します。

(継承元 OpenXmlElement)
NextSibling<T>()

現在の OpenXmlElement 要素に続く、指定した型を持つ OpenXmlElement 要素を取得します。 次の OpenXmlElement がないVisual Basic null (Nothing in Visual Basic) を返します。

(継承元 OpenXmlElement)
PrependChild<T>(T)

現在の要素の子ノードのリストの先頭に指定した要素を挿入します。

(継承元 OpenXmlCompositeElement)
PreviousSibling()

現在の OpenXmlElement 要素の直前にある OpenXmlElement 要素を取得します。 前の OpenXmlElement 要素がないVisual Basic null ( Nothing in Visual Basic ) を返します。

(継承元 OpenXmlElement)
PreviousSibling<T>()

現在の OpenXmlElement の前に指定された型を持つ OpenXmlElement 要素を取得します。 前の OpenXmlElement 要素がない場合は、null (Visual Basic 内の Nothing) を返します。

(継承元 OpenXmlElement)
Remove()

現在の要素を親から削除します。

(継承元 OpenXmlElement)
RemoveAllChildren()

現在の要素のすべての子要素を削除します。

(継承元 OpenXmlCompositeElement)
RemoveAllChildren<T>()

T 型の現在の要素のすべての子要素を削除します。

(継承元 OpenXmlElement)
RemoveAnnotations(Type)

現在の OpenXmlElement 要素から、指定した型の注釈を削除します。

(継承元 OpenXmlElement)
RemoveAnnotations<T>()

現在の OpenXmlElement 要素から、指定した型の注釈を削除します。

(継承元 OpenXmlElement)
RemoveAttribute(String, String)

現在の要素から属性を削除します。

(継承元 OpenXmlElement)
RemoveChild<T>(T)

指定した子要素を削除します。

(継承元 OpenXmlCompositeElement)
RemoveNamespaceDeclaration(String)

指定したプレフィックスの名前空間宣言を削除します。 プレフィックスがない場合は何も削除しません。

(継承元 OpenXmlElement)
ReplaceChild<T>(OpenXmlElement, T)

現在の要素の子要素の 1 つを別の OpenXmlElement 要素に置き換える。

(継承元 OpenXmlCompositeElement)
SetAttribute(OpenXmlAttribute)

属性を指定した要素に設定します。 属性が既知の属性の場合、属性の値が設定されます。 属性が拡張属性の場合、'openxmlAttribute' が拡張属性リストに追加されます。

(継承元 OpenXmlElement)
SetAttributes(IEnumerable<OpenXmlAttribute>)

要素に対して多数の属性を設定します。 属性が既知の属性の場合、属性の値が設定されます。 属性が拡張属性の場合、'openxmlAttribute' が拡張属性リストに追加されます。

(継承元 OpenXmlElement)
WriteTo(XmlWriter)

現在のノードを指定した XmlWriter に保存します。

(継承元 OpenXmlElement)

明示的なインターフェイスの実装

IEnumerable.GetEnumerator() (継承元 OpenXmlElement)

適用対象