public class XWPFParagraph extends java.lang.Object implements IBodyElement, IRunBody, ISDTContents, Paragraph
A Paragraph within a Document, Table, Header etc.
A paragraph has a lot of styling information, but the
actual text (possibly along with more styling) is held on
the child XWPFRun
s.
Modifier and Type | Field and Description |
---|---|
protected XWPFDocument |
document
For access to the document's hyperlink, comments, tables etc
|
protected java.util.List<IRunElement> |
iruns |
protected IBody |
part |
protected java.util.List<XWPFRun> |
runs |
Constructor and Description |
---|
XWPFParagraph(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP prgrph,
IBody part) |
Modifier and Type | Method and Description |
---|---|
void |
addFootnoteReference(XWPFAbstractFootnoteEndnote footnote)
Add a new run with a reference to the specified footnote.
|
protected void |
addRun(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR run)
add a new run at the end of the position of
the content of parameter run
|
void |
addRun(XWPFRun r)
adds a new Run to the Paragraph
|
XWPFFieldRun |
createFieldRun()
Appends a new field run to this paragraph
|
XWPFHyperlinkRun |
createHyperlinkRun(java.lang.String uri)
Appends a new hyperlink run to this paragraph
|
XWPFRun |
createRun()
Appends a new run to this paragraph
|
ParagraphAlignment |
getAlignment()
Returns the paragraph alignment which shall be applied to text in this
paragraph.
|
IBody |
getBody() |
Borders |
getBorderBetween()
Specifies the border which shall be displayed between each paragraph in a
set of paragraphs which have the same set of paragraph border settings.
|
Borders |
getBorderBottom()
Specifies the border which shall be displayed below a set of
paragraphs which have the same set of paragraph border settings.
|
Borders |
getBorderLeft()
Specifies the border which shall be displayed on the left side of the
page around the specified paragraph.
|
Borders |
getBorderRight()
Specifies the border which shall be displayed on the right side of the
page around the specified paragraph.
|
Borders |
getBorderTop()
Specifies the border which shall be displayed above a set of paragraphs
which have the same set of paragraph border settings.
|
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP |
getCTP() |
XWPFDocument |
getDocument() |
BodyElementType |
getElementType()
returns the type of the BodyElement Paragraph
|
int |
getFirstLineIndent() |
int |
getFontAlignment() |
java.lang.String |
getFootnoteText()
Returns the footnote text of the paragraph
|
int |
getIndentationFirstLine()
Specifies the additional indentation which shall be applied to the first
line of the parent paragraph.
|
int |
getIndentationHanging()
Specifies the indentation which shall be removed from the first line of
the parent paragraph, by moving the indentation on the first line back
towards the beginning of the direction of text flow.
|
int |
getIndentationLeft()
Specifies the indentation which shall be placed between the left text
margin for this paragraph and the left edge of that paragraph's content
in a left to right paragraph, and the right text margin and the right
edge of that paragraph's text in a right to left paragraph
|
int |
getIndentationLeftChars()
Get the indentation which is placed at the left/start of this paragraph
|
int |
getIndentationRight()
Specifies the indentation which shall be placed between the right text
margin for this paragraph and the right edge of that paragraph's content
in a left to right paragraph, and the right text margin and the right
edge of that paragraph's text in a right to left paragraph
|
int |
getIndentationRightChars()
Get the indentation which is placed at the right/end of this paragraph
|
int |
getIndentFromLeft() |
int |
getIndentFromRight() |
java.util.List<IRunElement> |
getIRuns()
Return literal runs and sdt/content control objects.
|
java.lang.String |
getNumFmt()
Returns numbering format for this paragraph, eg bullet or
lowerLetter.
|
java.math.BigInteger |
getNumID()
If style exist for this paragraph
NumId of the paragraph will be returned.
|
java.math.BigInteger |
getNumIlvl()
Returns Ilvl of the numeric style for this paragraph.
|
java.lang.String |
getNumLevelText()
Returns the text that should be used around the paragraph level numbers.
|
java.math.BigInteger |
getNumStartOverride()
Gets the numstartOverride for the paragraph numbering for this paragraph.
|
java.lang.String |
getParagraphText()
Returns the text of the paragraph, but not of any objects in the
paragraph
|
POIXMLDocumentPart |
getPart()
returns the part of the bodyElement
|
BodyType |
getPartType()
returns the partType of the bodyPart which owns the bodyElement
|
java.lang.String |
getPictureText()
Returns any text from any suitable pictures in the paragraph
|
XWPFRun |
getRun(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR r)
return the XWPFRun-Element which owns the CTR run-Element
|
java.util.List<XWPFRun> |
getRuns() |
int |
getSpacingAfter()
Specifies the spacing that should be added after the last line in this
paragraph in the document in absolute units.
|
int |
getSpacingAfterLines()
Specifies the spacing that should be added after the last line in this
paragraph in the document in absolute units.
|
int |
getSpacingBefore()
Specifies the spacing that should be added above the first line in this
paragraph in the document in absolute units.
|
int |
getSpacingBeforeLines()
Specifies the spacing that should be added before the first line in this paragraph in the
document in line units.
|
double |
getSpacingBetween()
Return the spacing between lines of a paragraph.
|
LineSpacingRule |
getSpacingLineRule()
Specifies how the spacing between lines is calculated as stored in the
line attribute.
|
java.lang.String |
getStyle() |
java.lang.String |
getStyleID()
Return styleID of the paragraph if style exist for this paragraph
if not, null will be returned
|
java.lang.String |
getText()
Return the textual content of the paragraph, including text from pictures
and sdt elements in it.
|
java.lang.String |
getText(TextSegment segment)
get a Text
|
TextAlignment |
getVerticalAlignment()
Returns the text vertical alignment which shall be applied to text in
this paragraph.
|
XWPFFieldRun |
insertNewFieldRun(int pos)
insert a new field Run in all runs
|
XWPFHyperlinkRun |
insertNewHyperlinkRun(int pos,
java.lang.String uri)
insert a new hyperlink Run in all runs
|
XWPFRun |
insertNewRun(int pos)
insert a new Run in all runs
|
boolean |
isEmpty() |
boolean |
isKeepNext()
Indicates whether this paragraph should be kept on the same page as the next one.
|
boolean |
isPageBreak()
Specifies that when rendering this document in a paginated
view, the contents of this paragraph are rendered on the start of a new
page in the document.
|
boolean |
isWordWrap() |
boolean |
isWordWrapped()
This element specifies whether a consumer shall break Latin text which
exceeds the text extents of a line by breaking the word across two lines
(breaking on the character level) or by moving the word to the following
line (breaking on the word level).
|
boolean |
removeRun(int pos)
removes a Run at the position pos in the paragraph
|
TextSegment |
searchText(java.lang.String searched,
PositionInParagraph startPos)
this methods parse the paragraph and search for the string searched.
|
void |
setAlignment(ParagraphAlignment align)
Specifies the paragraph alignment which shall be applied to text in this
paragraph.
|
void |
setBorderBetween(Borders border)
Specifies the border which shall be displayed between each paragraph in a
set of paragraphs which have the same set of paragraph border settings.
|
void |
setBorderBottom(Borders border)
Specifies the border which shall be displayed below a set of paragraphs
which have the same set of paragraph border settings.
|
void |
setBorderLeft(Borders border)
Specifies the border which shall be displayed on the left side of the
page around the specified paragraph.
|
void |
setBorderRight(Borders border)
Specifies the border which shall be displayed on the right side of the
page around the specified paragraph.
|
void |
setBorderTop(Borders border)
Specifies the border which shall be displayed above a set of paragraphs
which have the same set of paragraph border settings.
|
void |
setFirstLineIndent(int first) |
void |
setFontAlignment(int align) |
void |
setIndentationFirstLine(int indentation)
Specifies the additional indentation which shall be applied to the first
line of the parent paragraph.
|
void |
setIndentationHanging(int indentation)
Specifies the indentation which shall be removed from the first line of
the parent paragraph, by moving the indentation on the first line back
towards the beginning of the direction of text flow.
|
void |
setIndentationLeft(int indentation)
Specifies the indentation which shall be placed between the left text
margin for this paragraph and the left edge of that paragraph's content
in a left to right paragraph, and the right text margin and the right
edge of that paragraph's text in a right to left paragraph
|
void |
setIndentationLeftChars(int indentation)
Specifies the indentation which shall be placed at the left/start of this paragraph
|
void |
setIndentationRight(int indentation)
Specifies the indentation which shall be placed between the right text
margin for this paragraph and the right edge of that paragraph's content
in a left to right paragraph, and the right text margin and the right
edge of that paragraph's text in a right to left paragraph
|
void |
setIndentationRightChars(int indentation)
Specifies the indentation which shall be placed at the right/end of this paragraph
|
void |
setIndentFromLeft(int dxaLeft) |
void |
setIndentFromRight(int dxaRight) |
void |
setKeepNext(boolean keepNext)
Sets this paragraph to be kept on the same page as the next one or not.
|
void |
setNumID(java.math.BigInteger numPos)
setNumID of Paragraph
|
void |
setNumILvl(java.math.BigInteger iLvl)
setNumILvl of Paragraph
|
void |
setPageBreak(boolean pageBreak)
Specifies that when rendering this document in a paginated
view, the contents of this paragraph are rendered on the start of a new
page in the document.
|
void |
setSpacingAfter(int spaces)
Specifies the spacing that should be added after the last line in this
paragraph in the document in absolute units.
|
void |
setSpacingAfterLines(int spaces)
Specifies the spacing that should be added after the last line in this
paragraph in the document in line units.
|
void |
setSpacingBefore(int spaces)
Specifies the spacing that should be added above the first line in this
paragraph in the document in absolute units.
|
void |
setSpacingBeforeLines(int spaces)
Specifies the spacing that should be added before the first line in this
paragraph in the document in line units.
|
void |
setSpacingBetween(double spacing)
Sets the spacing between lines in a paragraph
|
void |
setSpacingBetween(double spacing,
LineSpacingRule rule)
Sets the spacing between lines in a paragraph
|
void |
setSpacingLineRule(LineSpacingRule rule)
Specifies how the spacing between lines is calculated as stored in the
line attribute.
|
void |
setStyle(java.lang.String styleId)
Set the style ID for the paragraph
|
void |
setVerticalAlignment(TextAlignment valign)
Specifies the text vertical alignment which shall be applied to text in
this paragraph.
|
void |
setWordWrap(boolean wrap)
Deprecated.
|
void |
setWordWrapped(boolean wrap)
This element specifies whether a consumer shall break Latin text which
exceeds the text extents of a line by breaking the word across two lines
(breaking on the character level) or by moving the word to the following
line (breaking on the word level).
|
protected IBody part
protected XWPFDocument document
protected java.util.List<XWPFRun> runs
protected java.util.List<IRunElement> iruns
public XWPFParagraph(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP prgrph, IBody part)
@Internal public org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP getCTP()
public java.util.List<XWPFRun> getRuns()
public java.util.List<IRunElement> getIRuns()
public boolean isEmpty()
public XWPFDocument getDocument()
getDocument
in interface IRunBody
public java.lang.String getText()
public java.lang.String getStyleID()
public java.math.BigInteger getNumID()
public void setNumID(java.math.BigInteger numPos)
numPos
- public void setNumILvl(java.math.BigInteger iLvl)
iLvl
- public java.math.BigInteger getNumIlvl()
public java.lang.String getNumFmt()
public java.lang.String getNumLevelText()
public java.math.BigInteger getNumStartOverride()
public boolean isKeepNext()
public void setKeepNext(boolean keepNext)
public java.lang.String getParagraphText()
public java.lang.String getPictureText()
public java.lang.String getFootnoteText()
public ParagraphAlignment getAlignment()
If this element is not set on a given paragraph, its value is determined by the setting previously set at any level of the style hierarchy (i.e. that previous setting remains unchanged). If this setting is never specified in the style hierarchy, then no alignment is applied to the paragraph.
public void setAlignment(ParagraphAlignment align)
If this element is not set on a given paragraph, its value is determined by the setting previously set at any level of the style hierarchy (i.e. that previous setting remains unchanged). If this setting is never specified in the style hierarchy, then no alignment is applied to the paragraph.
align
- the paragraph alignment to apply to this paragraph.public int getFontAlignment()
getFontAlignment
in interface Paragraph
getAlignment()
is suggestedpublic void setFontAlignment(int align)
setFontAlignment
in interface Paragraph
public TextAlignment getVerticalAlignment()
If the line height (before any added spacing) is larger than one or more characters on the line, all characters will be aligned to each other as specified by this element.
If this element is omitted on a given paragraph, its value is determined by the setting previously set at any level of the style hierarchy (i.e. that previous setting remains unchanged). If this setting is never specified in the style hierarchy, then the vertical alignment of all characters on the line shall be automatically determined by the consumer.
public void setVerticalAlignment(TextAlignment valign)
If the line height (before any added spacing) is larger than one or more characters on the line, all characters will be aligned to each other as specified by this element.
If this element is omitted on a given paragraph, its value is determined by the setting previously set at any level of the style hierarchy (i.e. that previous setting remains unchanged). If this setting is never specified in the style hierarchy, then the vertical alignment of all characters on the line shall be automatically determined by the consumer.
valign
- the paragraph vertical alignment to apply to this
paragraph.public Borders getBorderTop()
setBorderTop(Borders)
,
a list of all types of borders
public void setBorderTop(Borders border)
To determine if any two adjoining paragraphs shall have an individual top and bottom border or a between border, the set of borders on the two adjoining paragraphs are compared. If the border information on those two paragraphs is identical for all possible paragraphs borders, then the between border is displayed. Otherwise, the final paragraph shall use its bottom border and the following paragraph shall use its top border, respectively. If this border specifies a space attribute, that value determines the space above the text (ignoring any spacing above) which should be left before this border is drawn, specified in points.
If this element is omitted on a given paragraph, its value is determined by the setting previously set at any level of the style hierarchy (i.e. that previous setting remains unchanged). If this setting is never specified in the style hierarchy, then no between border shall be applied above identical paragraphs.
This border can only be a line border.border
- one of the defined Border styles, see Borders
for a list of all types of borders
public Borders getBorderBottom()
setBorderBottom(Borders)
,
a list of all types of borders
public void setBorderBottom(Borders border)
To determine if any two adjoining paragraphs shall have an individual top and bottom border or a between border, the set of borders on the two adjoining paragraphs are compared. If the border information on those two paragraphs is identical for all possible paragraphs borders, then the between border is displayed. Otherwise, the final paragraph shall use its bottom border and the following paragraph shall use its top border, respectively. If this border specifies a space attribute, that value determines the space after the bottom of the text (ignoring any space below) which should be left before this border is drawn, specified in points.
If this element is omitted on a given paragraph, its value is determined by the setting previously set at any level of the style hierarchy (i.e. that previous setting remains unchanged). If this setting is never specified in the style hierarchy, then no between border shall be applied below identical paragraphs.
This border can only be a line border.border
- one of the defined Border styles, see Borders
a list of all types of borders
public Borders getBorderLeft()
setBorderLeft(Borders)
,
for a list of all possible borders
public void setBorderLeft(Borders border)
To determine if any two adjoining paragraphs should have a left border which spans the full line height or not, the left border shall be drawn between the top border or between border at the top (whichever would be rendered for the current paragraph), and the bottom border or between border at the bottom (whichever would be rendered for the current paragraph).
If this element is omitted on a given paragraph, its value is determined by the setting previously set at any level of the style hierarchy (i.e. that previous setting remains unchanged). If this setting is never specified in the style hierarchy, then no left border shall be applied.
This border can only be a line border.border
- one of the defined Border styles, see Borders
for a list of all possible borders
public Borders getBorderRight()
setBorderRight(Borders)
,
for a list of all possible borders
public void setBorderRight(Borders border)
To determine if any two adjoining paragraphs should have a right border which spans the full line height or not, the right border shall be drawn between the top border or between border at the top (whichever would be rendered for the current paragraph), and the bottom border or between border at the bottom (whichever would be rendered for the current paragraph).
If this element is omitted on a given paragraph, its value is determined by the setting previously set at any level of the style hierarchy (i.e. that previous setting remains unchanged). If this setting is never specified in the style hierarchy, then no right border shall be applied.
This border can only be a line border.border
- one of the defined Border styles, see Borders
for a list of all possible borders
public Borders getBorderBetween()
setBorderBetween(Borders)
,
for a list of all possible borders
public void setBorderBetween(Borders border)
To determine if any two adjoining paragraphs should have a between border or an individual top and bottom border, the set of borders on the two adjoining paragraphs are compared. If the border information on those two paragraphs is identical for all possible paragraphs borders, then the between border is displayed. Otherwise, each paragraph shall use its bottom and top border, respectively. If this border specifies a space attribute, that value is ignored - this border is always located at the bottom of each paragraph with an identical following paragraph, taking into account any space after the line pitch.
If this element is omitted on a given paragraph, its value is determined by the setting previously set at any level of the style hierarchy (i.e. that previous setting remains unchanged). If this setting is never specified in the style hierarchy, then no between border shall be applied between identical paragraphs.
This border can only be a line border.border
- one of the defined Border styles, see Borders
for a list of all possible borders
public boolean isPageBreak()
If this element is omitted on a given paragraph, its value is determined by the setting previously set at any level of the style hierarchy (i.e. that previous setting remains unchanged). If this setting is never specified in the style hierarchy, then this property shall not be applied. Since the paragraph is specified to start on a new page, it begins page two even though it could have fit on page one.
public void setPageBreak(boolean pageBreak)
If this element is omitted on a given paragraph, its value is determined by the setting previously set at any level of the style hierarchy (i.e. that previous setting remains unchanged). If this setting is never specified in the style hierarchy, then this property shall not be applied. Since the paragraph is specified to start on a new page, it begins page two even though it could have fit on page one.
pageBreak
- -
boolean valuepublic int getSpacingAfter()
public void setSpacingAfter(int spaces)
If the afterLines attribute or the afterAutoSpacing attribute is also specified, then this attribute value is ignored.
spaces
- a positive whole number, whose contents consist of a
measurement in twentieths of a point.public int getSpacingAfterLines()
setSpacingAfterLines(int)
public void setSpacingAfterLines(int spaces)
If the afterAutoSpacing attribute is also specified, then this attribute value is ignored. If this setting is never specified in the style hierarchy, then its value shall be zero (if needed)
spaces
- a positive whole number, whose contents consist of a
measurement in hundredths of a linepublic int getSpacingBefore()
setSpacingBefore(int)
public void setSpacingBefore(int spaces)
If the beforeLines attribute or the beforeAutoSpacing attribute is also specified, then this attribute value is ignored.
spaces
- a positive whole number, whose contents consist of a
measurement in twentieths of a point.public int getSpacingBeforeLines()
setSpacingBeforeLines(int)
public void setSpacingBeforeLines(int spaces)
If the beforeAutoSpacing attribute is also specified, then this attribute value is ignored. If this setting is never specified in the style hierarchy, then its value shall be zero.
spaces
- a positive whole number, whose contents consist of a
measurement in hundredths of a linepublic LineSpacingRule getSpacingLineRule()
LineSpacingRule
,
setSpacingLineRule(LineSpacingRule)
public void setSpacingLineRule(LineSpacingRule rule)
rule
- one of the defined rules, see LineSpacingRule
LineSpacingRule
public double getSpacingBetween()
LineSpacingRule
. If AUTO, the return value is in lines, otherwise the return
value is in pointspublic void setSpacingBetween(double spacing, LineSpacingRule rule)
spacing
- - A double specifying spacing in inches or lines. If rule is
AUTO, then spacing is in lines. Otherwise spacing is in points.rule
- - LineSpacingRule
indicating how spacing is interpreted. If
AUTO, then spacing value is in lines, and the height depends on the
font size. If AT_LEAST, then spacing value is in inches, and is the
minimum size of the line. If the line height is taller, then the
line expands to match. If EXACT, then spacing is the exact line
height. If the text is taller than the line height, then it is
clipped at the top.public void setSpacingBetween(double spacing)
spacing
- - A double specifying spacing in lines.public int getIndentationLeft()
If this attribute is omitted, its value shall be assumed to be zero. Negative values are defined such that the text is moved past the text margin, positive values move the text inside the text margin.
public void setIndentationLeft(int indentation)
If this attribute is omitted, its value shall be assumed to be zero. Negative values are defined such that the text is moved past the text margin, positive values move the text inside the text margin.
indentation
- in twipspublic int getIndentationLeftChars()
public void setIndentationLeftChars(int indentation)
If this attribute is omitted, its value shall be assumed to be zero. if the left/start attribute is specified, then its value is ignored, and is superseded by this value.
indentation
- this value is specified in hundredths of a character unitpublic int getIndentationRight()
If this attribute is omitted, its value shall be assumed to be zero. Negative values are defined such that the text is moved past the text margin, positive values move the text inside the text margin.
public void setIndentationRight(int indentation)
If this attribute is omitted, its value shall be assumed to be zero. Negative values are defined such that the text is moved past the text margin, positive values move the text inside the text margin.
indentation
- in twipspublic int getIndentationRightChars()
public void setIndentationRightChars(int indentation)
If this attribute is omitted, its value shall be assumed to be zero. if the right/end attribute is specified, then its value is ignored, and is superseded by this value.
indentation
- this value is specified in hundredths of a character unitpublic int getIndentationHanging()
public void setIndentationHanging(int indentation)
The firstLine and hanging attributes are mutually exclusive, if both are specified, then the firstLine value is ignored.
indentation
- in twipspublic int getIndentationFirstLine()
public void setIndentationFirstLine(int indentation)
indentation
- in twipspublic int getIndentFromLeft()
getIndentFromLeft
in interface Paragraph
public void setIndentFromLeft(int dxaLeft)
setIndentFromLeft
in interface Paragraph
public int getIndentFromRight()
getIndentFromRight
in interface Paragraph
public void setIndentFromRight(int dxaRight)
setIndentFromRight
in interface Paragraph
public int getFirstLineIndent()
getFirstLineIndent
in interface Paragraph
public void setFirstLineIndent(int first)
setFirstLineIndent
in interface Paragraph
public boolean isWordWrapped()
isWordWrapped
in interface Paragraph
public void setWordWrapped(boolean wrap)
setWordWrapped
in interface Paragraph
wrap
- - booleanpublic boolean isWordWrap()
@Deprecated public void setWordWrap(boolean wrap)
public java.lang.String getStyle()
public void setStyle(java.lang.String styleId)
styleId
- ID (not name) of the style to set for the paragraph, e.g. "Heading1" (not "Heading 1").protected void addRun(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR run)
run
- public XWPFRun createRun()
public XWPFHyperlinkRun createHyperlinkRun(java.lang.String uri)
public XWPFFieldRun createFieldRun()
public XWPFRun insertNewRun(int pos)
pos
- The position at which the new run should be added.public XWPFHyperlinkRun insertNewHyperlinkRun(int pos, java.lang.String uri)
pos
- The position at which the new run should be added.uri
- hyperlink uripublic XWPFFieldRun insertNewFieldRun(int pos)
pos
- The position at which the new run should be added.public TextSegment searchText(java.lang.String searched, PositionInParagraph startPos)
searched
- startPos
- public java.lang.String getText(TextSegment segment)
segment
- public boolean removeRun(int pos)
pos
- public BodyElementType getElementType()
getElementType
in interface IBodyElement
IBodyElement.getElementType()
public IBody getBody()
getBody
in interface IBodyElement
public POIXMLDocumentPart getPart()
getPart
in interface IBodyElement
getPart
in interface IRunBody
IBody.getPart()
public BodyType getPartType()
getPartType
in interface IBodyElement
IBody.getPartType()
public void addRun(XWPFRun r)
r
- public XWPFRun getRun(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR r)
r
- public void addFootnoteReference(XWPFAbstractFootnoteEndnote footnote)
footnote
- Footnote to which to add a reference.Copyright 2021 The Apache Software Foundation or its licensors, as applicable.