java.lang.Object
com.aspose.words.ControlChar
public abstract class ControlChar
Example:
// Replace "\r" control character with "\r\n"
text = text.replace(ControlChar.CR, ControlChar.CR_LF);
| Field Summary | ||
|---|---|---|
static final java.lang.String | CELL | |
| End of a table cell or end of a table row character: "\x0007" or "\a". | ||
static final java.lang.String | TAB | |
| Tab character: "\x0009" or "\t". | ||
static final java.lang.String | LF | |
|
Line feed character: "\x000a" or "\n". Same as |
||
static final java.lang.String | LINE_FEED | |
|
Line feed character: "\x000a" or "\n". Same as |
||
static final java.lang.String | LINE_BREAK | |
| Line break character: "\x000b" or "\v". | ||
static final java.lang.String | PAGE_BREAK | |
|
Page break character: "\x000c" or "\f". Note it has the same value as |
||
static final java.lang.String | SECTION_BREAK | |
|
End of section character: "\x000c" or "\f". Note it has the same value as |
||
static final java.lang.String | CR | |
|
Carriage return character: "\x000d" or "\r". Same as |
||
static final java.lang.String | PARAGRAPH_BREAK | |
|
End of paragraph character: "\x000d" or "\r". Same as |
||
static final java.lang.String | COLUMN_BREAK | |
| End of column character: "\x000e". | ||
static final java.lang.String | CR_LF | |
| Carriage return followed by line feed character: "\x000d\x000a" or "\r\n". Not used as such in Microsoft Word documents, but commonly used in text files for paragraph breaks. | ||
static final java.lang.String | NON_BREAKING_SPACE | |
| Non-breaking space character: "\x00a0". | ||
static final char | CELL_CHAR | |
| End of a table cell or end of a table row character: (char)7 or "\a". | ||
static final char | TAB_CHAR | |
| Tab character: (char)9 or "\t". | ||
static final char | LINE_FEED_CHAR | |
| Line feed character: (char)10 or "\n". | ||
static final char | LINE_BREAK_CHAR | |
| Line break character: (char)11 or "\v". | ||
static final char | PAGE_BREAK_CHAR | |
| Page break character: (char)12 or "\f". | ||
static final char | SECTION_BREAK_CHAR | |
| End of section character: (char)12 or "\f". | ||
static final char | PARAGRAPH_BREAK_CHAR | |
| End of paragraph character: (char)13 or "\r". | ||
static final char | COLUMN_BREAK_CHAR | |
| End of column character: (char)14. | ||
static final char | FIELD_START_CHAR | |
| Start of MS Word field character: (char)19. | ||
static final char | FIELD_SEPARATOR_CHAR | |
| Field separator character separates field code from field value. Optional in some fields. Value: (char)20. | ||
static final char | FIELD_END_CHAR | |
| End of MS Word field character: (char)21. | ||
static final char | NON_BREAKING_HYPHEN_CHAR | |
| Nonbreaking Hyphen in Microsoft Word is (char)30. | ||
static final char | OPTIONAL_HYPHEN_CHAR | |
| Optional Hyphen in Microsoft Word is (char)31. | ||
static final char | SPACE_CHAR | |
| Space character: (char)32. | ||
static final char | NON_BREAKING_SPACE_CHAR | |
| Non-breaking space character: (char)160. | ||
static final char | DEFAULT_TEXT_INPUT_CHAR | |
| This is the "o" character used as a default value in text input form fields. | ||
| Field Detail |
|---|
CELL | |
public static final java.lang.String CELL | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);TAB | |
public static final java.lang.String TAB | |
Example:
Changes default tab positions for the document and inserts text with some tab characters.
DocumentBuilder builder = new DocumentBuilder();
// Set default tab stop to 72 points (1 inch).
builder.getDocument().setDefaultTabStop(72);
builder.writeln("Hello" + ControlChar.TAB + "World!");
builder.writeln("Hello" + ControlChar.TAB_CHAR + "World!");LF | |
public static final java.lang.String LF | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);LINE_FEED | |
public static final java.lang.String LINE_FEED | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);LINE_BREAK | |
public static final java.lang.String LINE_BREAK | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);PAGE_BREAK | |
public static final java.lang.String PAGE_BREAK | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);SECTION_BREAK | |
public static final java.lang.String SECTION_BREAK | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);CR | |
public static final java.lang.String CR | |
Example:
Shows how to use control characters.// Replace "\r" control character with "\r\n" text = text.replace(ControlChar.CR, ControlChar.CR_LF);
PARAGRAPH_BREAK | |
public static final java.lang.String PARAGRAPH_BREAK | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);COLUMN_BREAK | |
public static final java.lang.String COLUMN_BREAK | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);CR_LF | |
public static final java.lang.String CR_LF | |
Example:
Shows how to use control characters.// Replace "\r" control character with "\r\n" text = text.replace(ControlChar.CR, ControlChar.CR_LF);
NON_BREAKING_SPACE | |
public static final java.lang.String NON_BREAKING_SPACE | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);CELL_CHAR | |
public static final char CELL_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);TAB_CHAR | |
public static final char TAB_CHAR | |
Example:
Changes default tab positions for the document and inserts text with some tab characters.
DocumentBuilder builder = new DocumentBuilder();
// Set default tab stop to 72 points (1 inch).
builder.getDocument().setDefaultTabStop(72);
builder.writeln("Hello" + ControlChar.TAB + "World!");
builder.writeln("Hello" + ControlChar.TAB_CHAR + "World!");LINE_FEED_CHAR | |
public static final char LINE_FEED_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);LINE_BREAK_CHAR | |
public static final char LINE_BREAK_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);PAGE_BREAK_CHAR | |
public static final char PAGE_BREAK_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);SECTION_BREAK_CHAR | |
public static final char SECTION_BREAK_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);PARAGRAPH_BREAK_CHAR | |
public static final char PARAGRAPH_BREAK_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);COLUMN_BREAK_CHAR | |
public static final char COLUMN_BREAK_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);FIELD_START_CHAR | |
public static final char FIELD_START_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);FIELD_SEPARATOR_CHAR | |
public static final char FIELD_SEPARATOR_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);FIELD_END_CHAR | |
public static final char FIELD_END_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);NON_BREAKING_HYPHEN_CHAR | |
public static final char NON_BREAKING_HYPHEN_CHAR | |
Nonbreaking Hyphen in Microsoft Word does not correspond to the Unicode character U+2011 non-breaking hyphen but instead represents internal information that tells Microsoft Word to display a hyphen and not to break a line.
Useful info: http://www.cs.tut.fi/~jkorpela/dashes.html#linebreaks.
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);OPTIONAL_HYPHEN_CHAR | |
public static final char OPTIONAL_HYPHEN_CHAR | |
Optional Hyphen in Microsoft Word does not correspond to the Unicode character U+00AD soft hyphen. Instead, it inserts internal information that tells Word about a possible hyphenation point.
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);SPACE_CHAR | |
public static final char SPACE_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);NON_BREAKING_SPACE_CHAR | |
public static final char NON_BREAKING_SPACE_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);DEFAULT_TEXT_INPUT_CHAR | |
public static final char DEFAULT_TEXT_INPUT_CHAR | |
Example:
Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't have an automatic line break at its position
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 2);
// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Add a paragraph break, also adding a new paragraph
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. Note that this does not make a new section or paragraph
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);
// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
// Save document to see the characters we added
doc.save(getArtifactsDir() + "ControlChar.Misc.docx");
// There are char and string counterparts for most characters
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);