addText

addText

BASIC / ADVANCED / PREMIUM

Inserts a paragraph into a Word document.

Description
public void addText(String text)
public void addText(OptionsText textOptions)
public void addText(String text, OptionsParagraph paragraphOptions)
public void addText(OptionsText textOptions, OptionsParagraph paragraphOptions)
public void addText(ArrayList textOptions)
public void addText(ArrayList wordFragments, OptionsParagraph paragraphOptions)

This method allows the insertion of a paragraph into a Word document.

You may include in your paragraph:

  • multiple runs of text with diverse formatting
  • inline and floating images
  • inline and floating charts
  • footnotes and endnotes
  • all kinds of different line breaks (line, column, page)
  • all kind of different tabs (light, right, center with leading characters or not)
  • links and bookmarks
  • page numbers
  • date and hour
  • form elements
  • shapes

You may, in general, insert any "inline". If you try to insert a block type element, like a table, its inline contents will be extracted and inserted ignoring the containing block element.

Parameters

paragraphContents

This could be:

  • a simple string of text.
  • a WordFragment.
  • an ArrayList. Each of the elements of this array may be an OptionsText object:
Option Type Description
text String The text to be inserted.
bold Boolean If true the text will be shown in bold characters.
caps Boolean If true displays text in capital letters.
characterBorder HashMap<String, String> Adds a border to the character: type => none, single, double, dashed..., color => ffffff, ff0000, spacing => 0, 1, 2..., width => in eights of a point.
color String Hexadecimal color value: "FF0000", "000000"...
columnBreak String Inserts a column break.
Possible values are: before, after or both.
doubleStrikeThrough Boolean If true displays text in doubleStrikeThrough.
em String Emphasis mark type: "none", "dot", "circle", "comma", "underDot".
font String Font family: "Arial", "Calibri"...
fontSize Integer Font size in points.
highlightColor String Highlights the run of text.
The available colors are: black, blue, cyan, green, magenta, red, yellow, white, darkBlue, darkCyan, darkGreen, darkMagenta, darkRed, darkYellow, darkGray, lightGray, none.
italic Boolean If true displays the text in italics.
lineBreak String Inserts a line break. Possible values are: before, after or both.
position Integer Position value. Positive value for raised and negative value for lowered.
rStyle String Character style to be used.
rtl Boolean Sets to true for right to left languages like Hebrew or Arabic.
scaling String Scaling value, 100 is the default value.
smallCaps Boolean If true displays text in small capital letters.
spaces String Number of additional leading empty spaces before the current run of text.
spacing String character spacing, positive value for expanded and negative value for condensed.
strikeThrough Boolean If true displays text in strikethrough.
subscript Boolean If true displays text in subscript.
superscript Boolean If true displays text in superscript.
tab Boolean Inserts a tab.
underline String Underlines text. Possible values are: single, words, double, dotted, dash and wave.
underlineColor String Underlines text with a color: "FF0000", "000000"...
vanish Boolean Uses a vanish style.

paragraphOptions

Option Type Description
pStyle String Word style to be used. Run parseStyles() method to check all available paragraph styles.
backgroundColor String Hexadecimal color value: FF0000, 000000...
bidi Boolean Sets to true for right to left languages like Hebrew or Arabic.
bold Boolean If true the text will be shown in bold characters.
border String Available values are:
  • none (default)
  • double
  • dashed
  • outset
  • inset
  • threeDEmboss
  • threeDEngrave
borderBottom String Overwrites the general border type for the bottom border of the paragraph.
borderLeft String Overwrites the general border type for the left border of the paragraph.
borderTop String Overwrites the general border type for the top border of the paragraph.
borderRight String Overwrites the general border type for the right border of the paragraph.
borderColor String Hexadecimal color value: FF0000, 000000...
borderBottomColor String Overwrites the general border color for the bottom border of the paragraph.
borderLeftColor String Overwrites the general border color for the left border of the paragraph.
borderTopColor String Overwrites the general border color for the top border of the paragraph.
borderRightColor String Overwrites the general border color for the right border of the paragraph.
borderSpacing Integer Separation between border and text in points.
borderBottomSpacing Integer Overwrites the general border spacing for the bottom border of the paragraph.
borderLeftSpacing Integer Overwrites the general border spacing for the left border of the paragraph.
borderTopSpacing Integer Overwrites the general border spacing for the top border of the paragraph.
borderRightSpacing Integer Overwrites the general border spacing for the right border of the paragraph.
borderWidth Integer Border width in eigths of a point.
borderBottomWidth Integer Overwrites the general border width for the bottom border of the paragraph.
borderLeftWidth Integer Overwrites the general border width for the left border of the paragraph.
borderTopWidth Integer Overwrites the general border width for the top border of the paragraph.
borderRightWidth Integer Overwrites the general border width for the right border of the paragraph.
caps Boolean If true displays text in capital letters.
color String Hexadecimal color value: "FF0000", "000000"...
contextualSpacing String Ignores spacing above and below the paragraph whenever the neighbouring paragraphs use the same Word style.
doubleStrikeThrough Boolean If true displays text in doubleStrikeThrough.
em String Emphasis mark type: "none", "dot", "circle", "comma", "underDot".
firstLineIndent Integer First line indentation in twentieths of a point (twips).
font String Font family: "Arial", "Calibri"...
fontSize Integer Font size in points.
hanging Integer Paragraph hanging in twentieths of a point (twips).
headingLevel Integer The heading level if you want this paragraph to be a heading.
italic Boolean If true displays the text in italics.
indentLeft Integer Left margin in points.
indentRight Integer Right margin in points.
keepLines Boolean Keeps (whenever possible) all the current paragraph lines on the same page (default value is false).
keepNext Boolean Keeps (whenever possible) in the same page the current paragraph with next paragraph (default value is false).
lineSpacing Integer 120, 240 (standard), 360, 480... (in twentieths of a point).
pageBreakBefore Boolean If true forces a page break before the paragraph.
position Integer Position value. Positive value for raised and negative value for lowered.
rtl Boolean Sets to true for right to left languages like Hebrew or Arabic.
scaling Integer Scaling value, 100 is the default value.
smallCaps Boolean If true displays text in small capital letters.
spacingBottom Integer Bottom padding in twentieths of a point.
spacingTop Integer Top padding in twentieths of a point.
strikeThrough Boolean If true displays text in strikethrough.
tabPositions ArrayList<HashMap<String, String>> Each entry is a HashMap array with the following keys and values:
  • type can be clear, left (default), center, right, decimal, bar and num.
  • leader can be none (default), dot, hyphen, underscore, heavy and middleDot.
  • position given in twentieths of a point.
textAlign String Text alignment within paragraph. Possible values are: center, right, both and distribute.
textDirection String Text flow direction within a table cell. Possible values are: lrTb, tbRl, btLr, lrTbV, tbRlV and tbLrV.
underline String Underlines text. Possible values are: single, words, double, dotted, dash and wave.
underlineColor String Underlines text with a color: "FF0000", "000000"...
vanish Boolean Uses a vanish style.
widowControl Boolean Prevents Word from printing the last line of a paragraph by itself at the top of the page (widow) or the first line of a paragraph at the bottom of a page (orphan).
wordWrap Boolean Allows line breaking at character level (default value is false).
Code samples

Example #1

The resulting Word document looks like:

Example #2

The resulting Word document looks like:

Example #3

The resulting Word document looks like:

Example #4

The resulting Word document looks like: