public class ListFormat
A paragraph in a Microsoft Word document can be bulleted or numbered.
When a paragraph is bulleted or numbered, it is said that list formatting
is applied to the paragraph. You do not create objects of the The list formatting itself is stored inside a The paragraphs do not physically belong to a list. The paragraphs just
reference a particular list object via the Example:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a numbered list based on one of the Microsoft Word list templates and
// apply it to the current paragraph in the document builder
builder.getListFormat().setList(doc.getLists().add(ListTemplate.NUMBER_ARABIC_DOT));
// Insert text at each of the 9 indent levels
for (int i = 0; i < 9; i++) {
builder.getListFormat().setListLevelNumber(i);
builder.writeln("Level " + i);
}
// Create a bulleted list based on one of the Microsoft Word list templates
// and apply it to the current paragraph in the document builder
builder.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DIAMONDS));
for (int i = 0; i < 9; i++) {
builder.getListFormat().setListLevelNumber(i);
builder.writeln("Level " + i);
}
// This is a way to stop list formatting
builder.getListFormat().setList(null);
doc.save(getArtifactsDir() + "Lists.SpecifyListLevel.docx");
Property Getters/Setters Summary | ||
---|---|---|
boolean | isListItem() | |
True when the paragraph has bulleted or numbered formatting applied to it.
|
||
List | getList() | |
void | ||
Gets or sets the list this paragraph is a member of. | ||
ListLevel | getListLevel() | |
Returns the list level formatting plus any formatting overrides applied to the current paragraph.
|
||
int | getListLevelNumber() | |
void | setListLevelNumber(intvalue) | |
Gets or sets the list level number (0 to 8) for the paragraph. |
Method Summary | ||
---|---|---|
void | applyBulletDefault() | |
Starts a new default bulleted list and applies it to the paragraph.
|
||
void | applyNumberDefault() | |
Starts a new default numbered list and applies it to the paragraph.
|
||
void | listIndent() | |
Increases the list level of the current paragraph by one level.
|
||
void | listOutdent() | |
Decreases the list level of the current paragraph by one level.
|
||
void | removeNumbers() | |
Removes numbers or bullets from the current paragraph and sets list level to zero.
|
public boolean isListItem()
Example:
Shows how to output all paragraphs in a document that are bulleted or numbered.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.getListFormat().applyNumberDefault(); builder.writeln("Numbered list item 1"); builder.writeln("Numbered list item 2"); builder.writeln("Numbered list item 3"); builder.getListFormat().removeNumbers(); builder.getListFormat().applyBulletDefault(); builder.writeln("Bulleted list item 1"); builder.writeln("Bulleted list item 2"); builder.writeln("Bulleted list item 3"); builder.getListFormat().removeNumbers(); NodeCollection paras = doc.getChildNodes(NodeType.PARAGRAPH, true); for (Paragraph para : (Iterable<Paragraph>) paras) { if (para.getListFormat().isListItem()) { System.out.println(java.text.MessageFormat.format("*** A paragraph belongs to list {0}", para.getListFormat().getList().getListId())); System.out.println(para.getText()); } }
public List getList() / public void setList(List value)
The list that is being assigned to this property must belong to the current document.
The list that is being assigned to this property must not be a list style definition.
Setting this property to null removes bullets and numbering from the paragraph
and sets the list level number to zero. Setting this property to null is equivalent
to calling
Example:
Shows how to specify list level number when building a list using DocumentBuilder.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a numbered list based on one of the Microsoft Word list templates and // apply it to the current paragraph in the document builder builder.getListFormat().setList(doc.getLists().add(ListTemplate.NUMBER_ARABIC_DOT)); // Insert text at each of the 9 indent levels for (int i = 0; i < 9; i++) { builder.getListFormat().setListLevelNumber(i); builder.writeln("Level " + i); } // Create a bulleted list based on one of the Microsoft Word list templates // and apply it to the current paragraph in the document builder builder.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DIAMONDS)); for (int i = 0; i < 9; i++) { builder.getListFormat().setListLevelNumber(i); builder.writeln("Level " + i); } // This is a way to stop list formatting builder.getListFormat().setList(null); doc.save(getArtifactsDir() + "Lists.SpecifyListLevel.docx");
Example:
Shows how to start a numbered list, add a bulleted list inside it, then return to the numbered list.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create an outline list for the headings List outlineList = doc.getLists().add(ListTemplate.OUTLINE_NUMBERS); builder.getListFormat().setList(outlineList); builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1); builder.writeln("This is my Chapter 1"); // Create a numbered list List numberedList = doc.getLists().add(ListTemplate.NUMBER_DEFAULT); builder.getListFormat().setList(numberedList); builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL); builder.writeln("Numbered list item 1."); // Every paragraph that comprises a list will have this flag Assert.assertTrue(builder.getCurrentParagraph().isListItem()); Assert.assertTrue(builder.getParagraphFormat().isListItem()); // Create a bulleted list List bulletedList = doc.getLists().add(ListTemplate.BULLET_DEFAULT); builder.getListFormat().setList(bulletedList); builder.getParagraphFormat().setLeftIndent(72.0); builder.writeln("Bulleted list item 1."); builder.writeln("Bulleted list item 2."); builder.getParagraphFormat().clearFormatting(); // Revert to the numbered list builder.getListFormat().setList(numberedList); builder.writeln("Numbered list item 2."); builder.writeln("Numbered list item 3."); // Revert to the outline list builder.getListFormat().setList(outlineList); builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1); builder.writeln("This is my Chapter 2"); builder.getParagraphFormat().clearFormatting(); builder.getDocument().save(getArtifactsDir() + "Lists.NestedLists.docx");
public ListLevel getListLevel()
Example:
Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.Document doc = new Document(); // Create a list based on one of the Microsoft Word list templates List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT); // Completely customize one list level ListLevel listLevel = list.getListLevels().get(0); listLevel.getFont().setColor(Color.RED); listLevel.getFont().setSize(24.0); listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT); listLevel.setStartAt(21); listLevel.setNumberFormat("\u0000"); listLevel.setNumberPosition(-36); listLevel.setTextPosition(144.0); listLevel.setTabPosition(144.0); // Customize another list level listLevel = list.getListLevels().get(1); listLevel.setAlignment(ListLevelAlignment.RIGHT); listLevel.setNumberStyle(NumberStyle.BULLET); listLevel.getFont().setName("Wingdings"); listLevel.getFont().setColor(Color.BLUE); listLevel.getFont().setSize(24.0); listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE); listLevel.setNumberPosition(144.0); // Now add some text that uses the list that we created // It does not matter when to customize the list - before or after adding the paragraphs DocumentBuilder builder = new DocumentBuilder(doc); builder.getListFormat().setList(list); builder.writeln("The quick brown fox..."); builder.writeln("The quick brown fox..."); builder.getListFormat().listIndent(); builder.writeln("jumped over the lazy dog."); builder.writeln("jumped over the lazy dog."); builder.getListFormat().listOutdent(); builder.writeln("The quick brown fox..."); builder.getListFormat().removeNumbers(); builder.getDocument().save(getArtifactsDir() + "Lists.CreateCustomList.docx");
public int getListLevelNumber() / public void setListLevelNumber(int value)
In Word documents, lists may consist of 1 or 9 levels, numbered 0 to 8.
Has effect only when the
Example:
Shows how to specify list level number when building a list using DocumentBuilder.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create a numbered list based on one of the Microsoft Word list templates and // apply it to the current paragraph in the document builder builder.getListFormat().setList(doc.getLists().add(ListTemplate.NUMBER_ARABIC_DOT)); // Insert text at each of the 9 indent levels for (int i = 0; i < 9; i++) { builder.getListFormat().setListLevelNumber(i); builder.writeln("Level " + i); } // Create a bulleted list based on one of the Microsoft Word list templates // and apply it to the current paragraph in the document builder builder.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DIAMONDS)); for (int i = 0; i < 9; i++) { builder.getListFormat().setListLevelNumber(i); builder.writeln("Level " + i); } // This is a way to stop list formatting builder.getListFormat().setList(null); doc.save(getArtifactsDir() + "Lists.SpecifyListLevel.docx");
Example:
Shows how to apply default bulleted or numbered list formatting to paragraphs when using DocumentBuilder.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Aspose.Words allows:"); builder.writeln(); // Start a numbered list with default formatting builder.getListFormat().applyNumberDefault(); builder.writeln("Opening documents from different formats:"); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // Go to second list level, add more text builder.getListFormat().listIndent(); Assert.assertEquals(1, builder.getListFormat().getListLevelNumber()); builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); // Outdent to the first list level builder.getListFormat().listOutdent(); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); builder.writeln("Processing documents"); builder.writeln("Saving documents in different formats:"); // Indent the list level again builder.getListFormat().listIndent(); builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); builder.writeln("MHTML"); builder.writeln("Plain text"); // Outdent the list level again builder.getListFormat().listOutdent(); builder.writeln("Doing many other things!"); // End the numbered list builder.getListFormat().removeNumbers(); builder.writeln(); builder.writeln("Aspose.Words main advantages are:"); builder.writeln(); // Start a bulleted list with default formatting builder.getListFormat().applyBulletDefault(); builder.writeln("Great performance"); builder.writeln("High reliability"); builder.writeln("Quality code and working"); builder.writeln("Wide variety of features"); builder.writeln("Easy to understand API"); // End the bulleted list builder.getListFormat().removeNumbers(); doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
public void applyBulletDefault()
This is a shortcut method that creates a new list using the default bulleted template, applies it to the paragraph and selects the 1st list level.
Example:
Shows how to apply default bulleted or numbered list formatting to paragraphs when using DocumentBuilder.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Aspose.Words allows:"); builder.writeln(); // Start a numbered list with default formatting builder.getListFormat().applyNumberDefault(); builder.writeln("Opening documents from different formats:"); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // Go to second list level, add more text builder.getListFormat().listIndent(); Assert.assertEquals(1, builder.getListFormat().getListLevelNumber()); builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); // Outdent to the first list level builder.getListFormat().listOutdent(); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); builder.writeln("Processing documents"); builder.writeln("Saving documents in different formats:"); // Indent the list level again builder.getListFormat().listIndent(); builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); builder.writeln("MHTML"); builder.writeln("Plain text"); // Outdent the list level again builder.getListFormat().listOutdent(); builder.writeln("Doing many other things!"); // End the numbered list builder.getListFormat().removeNumbers(); builder.writeln(); builder.writeln("Aspose.Words main advantages are:"); builder.writeln(); // Start a bulleted list with default formatting builder.getListFormat().applyBulletDefault(); builder.writeln("Great performance"); builder.writeln("High reliability"); builder.writeln("Quality code and working"); builder.writeln("Wide variety of features"); builder.writeln("Easy to understand API"); // End the bulleted list builder.getListFormat().removeNumbers(); doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
public void applyNumberDefault()
This is a shortcut method that creates a new list using the default numbered template, applies it to the paragraph and selects the 1st list level.
Example:
Shows how to apply default bulleted or numbered list formatting to paragraphs when using DocumentBuilder.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Aspose.Words allows:"); builder.writeln(); // Start a numbered list with default formatting builder.getListFormat().applyNumberDefault(); builder.writeln("Opening documents from different formats:"); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // Go to second list level, add more text builder.getListFormat().listIndent(); Assert.assertEquals(1, builder.getListFormat().getListLevelNumber()); builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); // Outdent to the first list level builder.getListFormat().listOutdent(); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); builder.writeln("Processing documents"); builder.writeln("Saving documents in different formats:"); // Indent the list level again builder.getListFormat().listIndent(); builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); builder.writeln("MHTML"); builder.writeln("Plain text"); // Outdent the list level again builder.getListFormat().listOutdent(); builder.writeln("Doing many other things!"); // End the numbered list builder.getListFormat().removeNumbers(); builder.writeln(); builder.writeln("Aspose.Words main advantages are:"); builder.writeln(); // Start a bulleted list with default formatting builder.getListFormat().applyBulletDefault(); builder.writeln("Great performance"); builder.writeln("High reliability"); builder.writeln("Quality code and working"); builder.writeln("Wide variety of features"); builder.writeln("Easy to understand API"); // End the bulleted list builder.getListFormat().removeNumbers(); doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
public void listIndent() throws java.lang.Exception
This method changes the list level and applies formatting properties of the new level.
In Word documents, lists may consist of up to nine levels. List formatting for each level specifies what bullet or number is used, left indent, space between the bullet and text etc.
Example:
Shows how to apply default bulleted or numbered list formatting to paragraphs when using DocumentBuilder.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Aspose.Words allows:"); builder.writeln(); // Start a numbered list with default formatting builder.getListFormat().applyNumberDefault(); builder.writeln("Opening documents from different formats:"); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // Go to second list level, add more text builder.getListFormat().listIndent(); Assert.assertEquals(1, builder.getListFormat().getListLevelNumber()); builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); // Outdent to the first list level builder.getListFormat().listOutdent(); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); builder.writeln("Processing documents"); builder.writeln("Saving documents in different formats:"); // Indent the list level again builder.getListFormat().listIndent(); builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); builder.writeln("MHTML"); builder.writeln("Plain text"); // Outdent the list level again builder.getListFormat().listOutdent(); builder.writeln("Doing many other things!"); // End the numbered list builder.getListFormat().removeNumbers(); builder.writeln(); builder.writeln("Aspose.Words main advantages are:"); builder.writeln(); // Start a bulleted list with default formatting builder.getListFormat().applyBulletDefault(); builder.writeln("Great performance"); builder.writeln("High reliability"); builder.writeln("Quality code and working"); builder.writeln("Wide variety of features"); builder.writeln("Easy to understand API"); // End the bulleted list builder.getListFormat().removeNumbers(); doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
public void listOutdent() throws java.lang.Exception
This method changes the list level and applies formatting properties of the new level.
In Word documents, lists may consist of up to nine levels. List formatting for each level specifies what bullet or number is used, left indent, space between the bullet and text etc.
Example:
Shows how to apply default bulleted or numbered list formatting to paragraphs when using DocumentBuilder.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Aspose.Words allows:"); builder.writeln(); // Start a numbered list with default formatting builder.getListFormat().applyNumberDefault(); builder.writeln("Opening documents from different formats:"); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // Go to second list level, add more text builder.getListFormat().listIndent(); Assert.assertEquals(1, builder.getListFormat().getListLevelNumber()); builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); // Outdent to the first list level builder.getListFormat().listOutdent(); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); builder.writeln("Processing documents"); builder.writeln("Saving documents in different formats:"); // Indent the list level again builder.getListFormat().listIndent(); builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); builder.writeln("MHTML"); builder.writeln("Plain text"); // Outdent the list level again builder.getListFormat().listOutdent(); builder.writeln("Doing many other things!"); // End the numbered list builder.getListFormat().removeNumbers(); builder.writeln(); builder.writeln("Aspose.Words main advantages are:"); builder.writeln(); // Start a bulleted list with default formatting builder.getListFormat().applyBulletDefault(); builder.writeln("Great performance"); builder.writeln("High reliability"); builder.writeln("Quality code and working"); builder.writeln("Wide variety of features"); builder.writeln("Easy to understand API"); // End the bulleted list builder.getListFormat().removeNumbers(); doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
public void removeNumbers()
Calling this method is equivalent to setting the
Example:
Shows how to apply default bulleted or numbered list formatting to paragraphs when using DocumentBuilder.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Aspose.Words allows:"); builder.writeln(); // Start a numbered list with default formatting builder.getListFormat().applyNumberDefault(); builder.writeln("Opening documents from different formats:"); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // Go to second list level, add more text builder.getListFormat().listIndent(); Assert.assertEquals(1, builder.getListFormat().getListLevelNumber()); builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); // Outdent to the first list level builder.getListFormat().listOutdent(); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); builder.writeln("Processing documents"); builder.writeln("Saving documents in different formats:"); // Indent the list level again builder.getListFormat().listIndent(); builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); builder.writeln("MHTML"); builder.writeln("Plain text"); // Outdent the list level again builder.getListFormat().listOutdent(); builder.writeln("Doing many other things!"); // End the numbered list builder.getListFormat().removeNumbers(); builder.writeln(); builder.writeln("Aspose.Words main advantages are:"); builder.writeln(); // Start a bulleted list with default formatting builder.getListFormat().applyBulletDefault(); builder.writeln("Great performance"); builder.writeln("High reliability"); builder.writeln("Quality code and working"); builder.writeln("Wide variety of features"); builder.writeln("Easy to understand API"); // End the bulleted list builder.getListFormat().removeNumbers(); doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
Example:
Shows how to remove bullets and numbering from all paragraphs in the main text of a section.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.getListFormat().applyNumberDefault(); builder.writeln("Numbered list item 1"); builder.writeln("Numbered list item 2"); builder.writeln("Numbered list item 3"); builder.getListFormat().removeNumbers(); NodeCollection paras = doc.getChildNodes(NodeType.PARAGRAPH, true); Assert.assertEquals(3, DocumentHelper.getListItemCount(paras)); for (Paragraph paragraph : doc.getFirstSection().getBody().getParagraphs()) paragraph.getListFormat().removeNumbers(); paras = doc.getChildNodes(NodeType.PARAGRAPH, true); Assert.assertEquals(0, DocumentHelper.getListItemCount(paras));