ParagraphProperties Class
Paragraph Properties.When the object is serialized out as xml, its qualified name is w:pPr.
Inheritance Hierarchy
System.Object
DocumentFormat.OpenXml.OpenXmlElement
DocumentFormat.OpenXml.OpenXmlCompositeElement
DocumentFormat.OpenXml.Wordprocessing.ParagraphProperties
Namespace: DocumentFormat.OpenXml.Wordprocessing
Assembly: DocumentFormat.OpenXml (in DocumentFormat.OpenXml.dll)
Syntax
'宣言
<ChildElementInfoAttribute(GetType(Shading))> _
<ChildElementInfoAttribute(GetType(SnapToGrid))> _
<ChildElementInfoAttribute(GetType(SpacingBetweenLines))> _
<ChildElementInfoAttribute(GetType(MirrorIndents))> _
<ChildElementInfoAttribute(GetType(SuppressOverlap))> _
<ChildElementInfoAttribute(GetType(ContextualSpacing))> _
<ChildElementInfoAttribute(GetType(AdjustRightIndent))> _
<ChildElementInfoAttribute(GetType(AutoSpaceDE))> _
<ChildElementInfoAttribute(GetType(AutoSpaceDN))> _
<ChildElementInfoAttribute(GetType(ParagraphStyleId))> _
<ChildElementInfoAttribute(GetType(KeepNext))> _
<ChildElementInfoAttribute(GetType(KeepLines))> _
<ChildElementInfoAttribute(GetType(PageBreakBefore))> _
<ChildElementInfoAttribute(GetType(FrameProperties))> _
<ChildElementInfoAttribute(GetType(WidowControl))> _
<ChildElementInfoAttribute(GetType(NumberingProperties))> _
<ChildElementInfoAttribute(GetType(SuppressLineNumbers))> _
<ChildElementInfoAttribute(GetType(ParagraphBorders))> _
<ChildElementInfoAttribute(GetType(Tabs))> _
<ChildElementInfoAttribute(GetType(SuppressAutoHyphens))> _
<ChildElementInfoAttribute(GetType(Kinsoku))> _
<ChildElementInfoAttribute(GetType(WordWrap))> _
<ChildElementInfoAttribute(GetType(OverflowPunctuation))> _
<ChildElementInfoAttribute(GetType(TopLinePunctuation))> _
<ChildElementInfoAttribute(GetType(BiDi))> _
<ChildElementInfoAttribute(GetType(Indentation))> _
<ChildElementInfoAttribute(GetType(Justification))> _
<ChildElementInfoAttribute(GetType(TextDirection))> _
<ChildElementInfoAttribute(GetType(TextAlignment))> _
<ChildElementInfoAttribute(GetType(TextBoxTightWrap))> _
<ChildElementInfoAttribute(GetType(OutlineLevel))> _
<ChildElementInfoAttribute(GetType(DivId))> _
<ChildElementInfoAttribute(GetType(ConditionalFormatStyle))> _
<ChildElementInfoAttribute(GetType(ParagraphMarkRunProperties))> _
<ChildElementInfoAttribute(GetType(SectionProperties))> _
<ChildElementInfoAttribute(GetType(ParagraphPropertiesChange))> _
Public Class ParagraphProperties _
Inherits OpenXmlCompositeElement
'使用
Dim instance As ParagraphProperties
[ChildElementInfoAttribute(typeof(Shading))]
[ChildElementInfoAttribute(typeof(SnapToGrid))]
[ChildElementInfoAttribute(typeof(SpacingBetweenLines))]
[ChildElementInfoAttribute(typeof(MirrorIndents))]
[ChildElementInfoAttribute(typeof(SuppressOverlap))]
[ChildElementInfoAttribute(typeof(ContextualSpacing))]
[ChildElementInfoAttribute(typeof(AdjustRightIndent))]
[ChildElementInfoAttribute(typeof(AutoSpaceDE))]
[ChildElementInfoAttribute(typeof(AutoSpaceDN))]
[ChildElementInfoAttribute(typeof(ParagraphStyleId))]
[ChildElementInfoAttribute(typeof(KeepNext))]
[ChildElementInfoAttribute(typeof(KeepLines))]
[ChildElementInfoAttribute(typeof(PageBreakBefore))]
[ChildElementInfoAttribute(typeof(FrameProperties))]
[ChildElementInfoAttribute(typeof(WidowControl))]
[ChildElementInfoAttribute(typeof(NumberingProperties))]
[ChildElementInfoAttribute(typeof(SuppressLineNumbers))]
[ChildElementInfoAttribute(typeof(ParagraphBorders))]
[ChildElementInfoAttribute(typeof(Tabs))]
[ChildElementInfoAttribute(typeof(SuppressAutoHyphens))]
[ChildElementInfoAttribute(typeof(Kinsoku))]
[ChildElementInfoAttribute(typeof(WordWrap))]
[ChildElementInfoAttribute(typeof(OverflowPunctuation))]
[ChildElementInfoAttribute(typeof(TopLinePunctuation))]
[ChildElementInfoAttribute(typeof(BiDi))]
[ChildElementInfoAttribute(typeof(Indentation))]
[ChildElementInfoAttribute(typeof(Justification))]
[ChildElementInfoAttribute(typeof(TextDirection))]
[ChildElementInfoAttribute(typeof(TextAlignment))]
[ChildElementInfoAttribute(typeof(TextBoxTightWrap))]
[ChildElementInfoAttribute(typeof(OutlineLevel))]
[ChildElementInfoAttribute(typeof(DivId))]
[ChildElementInfoAttribute(typeof(ConditionalFormatStyle))]
[ChildElementInfoAttribute(typeof(ParagraphMarkRunProperties))]
[ChildElementInfoAttribute(typeof(SectionProperties))]
[ChildElementInfoAttribute(typeof(ParagraphPropertiesChange))]
public class ParagraphProperties : OpenXmlCompositeElement
Remarks
The following table lists the possible child types:
[ISO/IEC 29500-1 初版]
17.3.1.26 pPr (Paragraph Properties)
This element specifies a set of paragraph properties which shall be applied to the contents of the parent paragraph after all style/numbering/table properties have been applied to the text. These properties are defined as direct formatting, since they are directly applied to the paragraph and supersede any formatting from styles.
[Example: Consider a paragraph which should have a set of paragraph formatting properties. This set of properties is specified in the paragraph properties as follows:
<w:p>
<w:pPr>
<w:pBdr>
<w:bottom w:val="single" w:sz="8" w:space="4" w:color="4F81BD" />
</w:pBdr>
<w:spacing w:after="300" />
<w:contextualSpacing />
</w:pPr>
</w:p>
The pPr element specifies the properties which are applied to the current paragraph - in this case, a bottom paragraph border using the bottom element (§17.3.1.7), spacing after the paragraph using the spacing element (§17.3.1.33), and that spacing should be ignored for paragraphs above/below of the same style using the contextualSpacing element (§17.3.1.9). end example]
Parent Elements |
---|
p (§17.3.1.22) |
Child Elements |
Subclause |
---|---|
adjustRightInd (Automatically Adjust Right Indent When Using Document Grid) |
§17.3.1.1 |
autoSpaceDE (Automatically Adjust Spacing of Latin and East Asian Text) |
§17.3.1.2 |
autoSpaceDN (Automatically Adjust Spacing of East Asian Text and Numbers) |
§17.3.1.3 |
bidi (Right to Left Paragraph Layout) |
§17.3.1.6 |
cnfStyle (Paragraph Conditional Formatting) |
§17.3.1.8 |
contextualSpacing (Ignore Spacing Above and Below When Using Identical Styles) |
§17.3.1.9 |
divId (Associated HTML div ID) |
§17.3.1.10 |
framePr (Text Frame Properties) |
§17.3.1.11 |
ind (Paragraph Indentation) |
§17.3.1.12 |
jc (Paragraph Alignment) |
§17.3.1.13 |
keepLines (Keep All Lines On One Page) |
§17.3.1.14 |
keepNext (Keep Paragraph With Next Paragraph) |
§17.3.1.15 |
kinsoku (Use East Asian Typography Rules for First and Last Character per Line) |
§17.3.1.16 |
mirrorIndents (Use Left/Right Indents as Inside/Outside Indents) |
§17.3.1.18 |
numPr (Numbering Definition Instance Reference) |
§17.3.1.19 |
outlineLvl (Associated Outline Level) |
§17.3.1.20 |
overflowPunct (Allow Punctuation to Extend Past Text Extents) |
§17.3.1.21 |
pageBreakBefore (Start Paragraph on Next Page) |
§17.3.1.23 |
pBdr (Paragraph Borders) |
§17.3.1.24 |
pPrChange (Revision Information for Paragraph Properties) |
§17.13.5.29 |
pStyle (Referenced Paragraph Style) |
§17.3.1.27 |
rPr (Run Properties for the Paragraph Mark) |
§17.3.1.29 |
sectPr (Section Properties) |
§17.6.18 |
shd (Paragraph Shading) |
§17.3.1.31 |
snapToGrid (Use Document Grid Settings for Inter-Line Paragraph Spacing) |
§17.3.1.32 |
spacing (Spacing Between Lines and Above/Below Paragraph) |
§17.3.1.33 |
suppressAutoHyphens (Suppress Hyphenation for Paragraph) |
§17.3.1.34 |
suppressLineNumbers (Suppress Line Numbers for Paragraph) |
§17.3.1.35 |
suppressOverlap (Prevent Text Frames From Overlapping) |
§17.3.1.36 |
tabs (Set of Custom Tab Stops) |
§17.3.1.38 |
textAlignment (Vertical Character Alignment on Line) |
§17.3.1.39 |
textboxTightWrap (Allow Surrounding Paragraphs to Tight Wrap to Text Box Contents) |
§17.3.1.40 |
textDirection (Paragraph Text Flow Direction) |
§17.3.1.41 |
topLinePunct (Compress Punctuation at Start of a Line) |
§17.3.1.43 |
widowControl (Allow First/Last Line to Display on a Separate Page) |
§17.3.1.44 |
wordWrap (Allow Line Breaking At Character Level) |
§17.3.1.45 |
[Note: The W3C XML Schema definition of this element's content model (CT_PPr) is located in §A.1. end note]
ParagraphStyleId <w:pStyle>
KeepNext <w:keepNext>
KeepLines <w:keepLines>
PageBreakBefore <w:pageBreakBefore>
FrameProperties <w:framePr>
WidowControl <w:widowControl>
NumberingProperties <w:numPr>
SuppressLineNumbers <w:suppressLineNumbers>
ParagraphBorders <w:pBdr>
Shading <w:shd>
Tabs <w:tabs>
SuppressAutoHyphens <w:suppressAutoHyphens>
Kinsoku <w:kinsoku>
WordWrap <w:wordWrap>
OverflowPunctuation <w:overflowPunct>
TopLinePunctuation <w:topLinePunct>
AutoSpaceDE <w:autoSpaceDE>
AutoSpaceDN <w:autoSpaceDN>
BiDi <w:bidi>
AdjustRightIndent <w:adjustRightInd>
SnapToGrid <w:snapToGrid>
SpacingBetweenLines <w:spacing>
Indentation <w:ind>
ContextualSpacing <w:contextualSpacing>
MirrorIndents <w:mirrorIndents>
SuppressOverlap <w:suppressOverlap>
Justification <w:jc>
TextDirection <w:textDirection>
TextAlignment <w:textAlignment>
TextBoxTightWrap <w:textboxTightWrap>
OutlineLevel <w:outlineLvl>
DivId <w:divId>
ConditionalFormatStyle <w:cnfStyle>
ParagraphMarkRunProperties <w:rPr>
SectionProperties <w:sectPr>
ParagraphPropertiesChange <w:pPrChange>
© ISO/IEC29500: 2008. 上記の引用はマイクロソフト (またはその代理) によって英語から日本語に翻訳されたものであり、ISO はこうした翻訳に対する責任を一切負いません。
Examples
The following example opens an existing word processing document, searches it for a Heading1 styled paragraph, and inserts an outline descendant before that paragraph.
using System;
using System.Collections.Generic;
using System.Linq;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace ParagraphPropertiesEx
{
class Program
{
// Search all paragraphs of the specified style and make an outline descendant.
static void Main(string[] args)
{
string fileName = @"C:\Users\Public\Documents\ParagraphPropertiesEx.docx";
using (WordprocessingDocument wordprocessingDocument =
WordprocessingDocument.Open(fileName, true))
{
// Get the body element.
var body = wordprocessingDocument.MainDocumentPart.Document.Body;
//Define a list to store outline Paragraphs
var paragraphs = new List<Paragraph>();
// Search all Paragraphs that is "Heading1" style.
foreach (Paragraph para in body.Descendants<Paragraph>().
Where(e => e.ParagraphProperties != null
&& e.ParagraphProperties.ParagraphStyleId != null
&& e.ParagraphProperties.ParagraphStyleId.Val == "Heading1"))
{
paragraphs.Add(new Paragraph(new Run(new Text(para.InnerText))));
}
// Need to find whether first child is null, if so, add the paragragh collections to Body.
if (body.FirstChild == null)
{
body.Append(paragraphs.ToArray());
}
// Else, get first child and always insert before it.
else
{
OpenXmlElement first = body.FirstChild;
foreach (Paragraph p in paragraphs)
{
first.InsertBeforeSelf<Paragraph>(p);
}
}
}
Console.WriteLine("All done. Press a key");
Console.ReadKey();
}
}
}
Imports System.Collections.Generic
Imports System.Linq
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Wordprocessing
Module Module1
' Search all paragraphs of the specified style and make an outline descendant.
Sub Main(ByVal args As String())
Dim fileName As String = "C:\Users\Public\Documents\ParagraphPropertiesEx.docx"
Using wordprocessingDocument As WordprocessingDocument = wordprocessingDocument.Open(fileName, True)
' Get the body element.
Dim body = wordprocessingDocument.MainDocumentPart.Document.Body
'Define a list to store outline Paragraphs
Dim paragraphs = New List(Of Paragraph)()
' Search all Paragraphs that is "Heading1" style.
For Each para As Paragraph In body.Descendants(Of Paragraph)().Where(Function(e) e.ParagraphProperties IsNot Nothing AndAlso e.ParagraphProperties.ParagraphStyleId IsNot Nothing AndAlso e.ParagraphProperties.ParagraphStyleId.Val = "Heading1")
paragraphs.Add(New Paragraph(New Run(New Text(para.InnerText))))
Next
' Need to find whether first child is null, if so, add the paragragh collections to Body.
If body.FirstChild Is Nothing Then
body.Append(paragraphs.ToArray())
Else
' Else, get first child and always insert before it.
Dim first As OpenXmlElement = body.FirstChild
For Each p As Paragraph In paragraphs
first.InsertBeforeSelf(Of Paragraph)(p)
Next
End If
End Using
Console.WriteLine("All done. Press a key")
Console.ReadKey()
End Sub
End Module
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.