java.lang.Objectcom.aspose.words.ListFormat
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);
Assert.assertFalse(builder.getListFormat().isListItem());
// A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents.
// We can create nested lists by increasing the indent level.
// We can begin and end a list by using a document builder's "ListFormat" property.
// Each paragraph that we add between a list's start and the end will become an item in the list.
// Below are two types of lists that we can create using a document builder.
// 1 - A numbered list:
// Numbered lists create a logical order for their paragraphs by numbering each item.
builder.getListFormat().setList(doc.getLists().add(ListTemplate.NUMBER_DEFAULT));
Assert.assertTrue(builder.getListFormat().isListItem());
// By setting the "ListLevelNumber" property, we can increase the list level
// to begin a self-contained sub-list at the current list item.
// The Microsoft Word list template called "NumberDefault" uses numbers to create list levels for the first list level.
// Deeper list levels use letters and lowercase Roman numerals.
for (int i = 0; i < 9; i++) {
builder.getListFormat().setListLevelNumber(i);
builder.writeln("Level " + i);
}
// 2 - A bulleted list:
// This list will apply an indent and a bullet symbol ("�") before each paragraph.
// Deeper levels of this list will use different symbols, such as "�" and "?".
builder.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DEFAULT));
for (int i = 0; i < 9; i++) {
builder.getListFormat().setListLevelNumber(i);
builder.writeln("Level " + i);
}
// We can disable list formatting to not format any subsequent paragraphs as lists by un-setting the "List" flag.
builder.getListFormat().setList(null);
Assert.assertFalse(builder.getListFormat().isListItem());
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 | setList(List value) | |
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(int value) | |
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. |
Property Getters/Setters Detail |
---|
isListItem | |
public boolean isListItem() |
Example:
Shows how to output all paragraphs in a document that are list items.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()); } }
Example:
Shows how to work with list levels.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Assert.assertFalse(builder.getListFormat().isListItem()); // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents. // We can create nested lists by increasing the indent level. // We can begin and end a list by using a document builder's "ListFormat" property. // Each paragraph that we add between a list's start and the end will become an item in the list. // Below are two types of lists that we can create using a document builder. // 1 - A numbered list: // Numbered lists create a logical order for their paragraphs by numbering each item. builder.getListFormat().setList(doc.getLists().add(ListTemplate.NUMBER_DEFAULT)); Assert.assertTrue(builder.getListFormat().isListItem()); // By setting the "ListLevelNumber" property, we can increase the list level // to begin a self-contained sub-list at the current list item. // The Microsoft Word list template called "NumberDefault" uses numbers to create list levels for the first list level. // Deeper list levels use letters and lowercase Roman numerals. for (int i = 0; i < 9; i++) { builder.getListFormat().setListLevelNumber(i); builder.writeln("Level " + i); } // 2 - A bulleted list: // This list will apply an indent and a bullet symbol ("�") before each paragraph. // Deeper levels of this list will use different symbols, such as "�" and "?". builder.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DEFAULT)); for (int i = 0; i < 9; i++) { builder.getListFormat().setListLevelNumber(i); builder.writeln("Level " + i); } // We can disable list formatting to not format any subsequent paragraphs as lists by un-setting the "List" flag. builder.getListFormat().setList(null); Assert.assertFalse(builder.getListFormat().isListItem()); doc.save(getArtifactsDir() + "Lists.SpecifyListLevel.docx");
getList/setList | |
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 work with list levels.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Assert.assertFalse(builder.getListFormat().isListItem()); // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents. // We can create nested lists by increasing the indent level. // We can begin and end a list by using a document builder's "ListFormat" property. // Each paragraph that we add between a list's start and the end will become an item in the list. // Below are two types of lists that we can create using a document builder. // 1 - A numbered list: // Numbered lists create a logical order for their paragraphs by numbering each item. builder.getListFormat().setList(doc.getLists().add(ListTemplate.NUMBER_DEFAULT)); Assert.assertTrue(builder.getListFormat().isListItem()); // By setting the "ListLevelNumber" property, we can increase the list level // to begin a self-contained sub-list at the current list item. // The Microsoft Word list template called "NumberDefault" uses numbers to create list levels for the first list level. // Deeper list levels use letters and lowercase Roman numerals. for (int i = 0; i < 9; i++) { builder.getListFormat().setListLevelNumber(i); builder.writeln("Level " + i); } // 2 - A bulleted list: // This list will apply an indent and a bullet symbol ("�") before each paragraph. // Deeper levels of this list will use different symbols, such as "�" and "?". builder.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DEFAULT)); for (int i = 0; i < 9; i++) { builder.getListFormat().setListLevelNumber(i); builder.writeln("Level " + i); } // We can disable list formatting to not format any subsequent paragraphs as lists by un-setting the "List" flag. builder.getListFormat().setList(null); Assert.assertFalse(builder.getListFormat().isListItem()); doc.save(getArtifactsDir() + "Lists.SpecifyListLevel.docx");
Example:
Shows how to nest a list inside another list.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents. // We can create nested lists by increasing the indent level. // We can begin and end a list by using a document builder's "ListFormat" property. // Each paragraph that we add between a list's start and the end will become an item in the list. // 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");
getListLevel | |
public ListLevel getListLevel() |
Example:
Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.Document doc = new Document(); // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents. // We can create nested lists by increasing the indent level. // We can begin and end a list by using a document builder's "ListFormat" property. // Each paragraph that we add between a list's start and the end will become an item in the list. // Create a list from a Microsoft Word template, and customize the first two of its list levels. List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT); 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); 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); // This NumberFormat value will create star-shaped bullet list symbols. listLevel.setNumberFormat("\uf0af"); listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE); listLevel.setNumberPosition(144.0); // Create paragraphs and apply both list levels of our custom list formatting to them. 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");
getListLevelNumber/setListLevelNumber | |
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 work with list levels.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Assert.assertFalse(builder.getListFormat().isListItem()); // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents. // We can create nested lists by increasing the indent level. // We can begin and end a list by using a document builder's "ListFormat" property. // Each paragraph that we add between a list's start and the end will become an item in the list. // Below are two types of lists that we can create using a document builder. // 1 - A numbered list: // Numbered lists create a logical order for their paragraphs by numbering each item. builder.getListFormat().setList(doc.getLists().add(ListTemplate.NUMBER_DEFAULT)); Assert.assertTrue(builder.getListFormat().isListItem()); // By setting the "ListLevelNumber" property, we can increase the list level // to begin a self-contained sub-list at the current list item. // The Microsoft Word list template called "NumberDefault" uses numbers to create list levels for the first list level. // Deeper list levels use letters and lowercase Roman numerals. for (int i = 0; i < 9; i++) { builder.getListFormat().setListLevelNumber(i); builder.writeln("Level " + i); } // 2 - A bulleted list: // This list will apply an indent and a bullet symbol ("�") before each paragraph. // Deeper levels of this list will use different symbols, such as "�" and "?". builder.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DEFAULT)); for (int i = 0; i < 9; i++) { builder.getListFormat().setListLevelNumber(i); builder.writeln("Level " + i); } // We can disable list formatting to not format any subsequent paragraphs as lists by un-setting the "List" flag. builder.getListFormat().setList(null); Assert.assertFalse(builder.getListFormat().isListItem()); doc.save(getArtifactsDir() + "Lists.SpecifyListLevel.docx");
Example:
Shows how to create bulleted and numbered lists.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Aspose.Words main advantages are:"); // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents. // We can create nested lists by increasing the indent level. // We can begin and end a list by using a document builder's "ListFormat" property. // Each paragraph that we add between a list's start and the end will become an item in the list. // Below are two types of lists that we can create with a document builder. // 1 - A bulleted list: // This list will apply an indent and a bullet symbol ("�") before each paragraph. 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(); builder.insertBreak(BreakType.PARAGRAPH_BREAK); builder.writeln("Aspose.Words allows:"); // 2 - A numbered list: // Numbered lists create a logical order for their paragraphs by numbering each item. builder.getListFormat().applyNumberDefault(); // This paragraph is the first item. The first item of a numbered list will have a "1." as its list item symbol. builder.writeln("Opening documents from different formats:"); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // Call the "ListIndent" method to increase the current list level, // which will start a new self-contained list, with a deeper indent, at the current item of the first list level. builder.getListFormat().listIndent(); Assert.assertEquals(1, builder.getListFormat().getListLevelNumber()); // These are the first three list items of the second list level, which will maintain a count // independent of the count of the first list level. According to the current list format, // they will have symbols of "a.", "b.", and "c.". builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); // Call the "ListOutdent" method to return to the previous list level. builder.getListFormat().listOutdent(); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // These two paragraphs will continue the count of the first list level. // These items will have symbols of "2.", and "3." builder.writeln("Processing documents"); builder.writeln("Saving documents in different formats:"); // If we increase the list level to a level that we have added items to previously, // the nested list will be separate from the previous, and its numbering will start from the beginning. // These list items will have symbols of "a.", "b.", "c.", "d.", and "e". 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(); doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
Method Detail |
---|
applyBulletDefault | |
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 create bulleted and numbered lists.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Aspose.Words main advantages are:"); // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents. // We can create nested lists by increasing the indent level. // We can begin and end a list by using a document builder's "ListFormat" property. // Each paragraph that we add between a list's start and the end will become an item in the list. // Below are two types of lists that we can create with a document builder. // 1 - A bulleted list: // This list will apply an indent and a bullet symbol ("�") before each paragraph. 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(); builder.insertBreak(BreakType.PARAGRAPH_BREAK); builder.writeln("Aspose.Words allows:"); // 2 - A numbered list: // Numbered lists create a logical order for their paragraphs by numbering each item. builder.getListFormat().applyNumberDefault(); // This paragraph is the first item. The first item of a numbered list will have a "1." as its list item symbol. builder.writeln("Opening documents from different formats:"); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // Call the "ListIndent" method to increase the current list level, // which will start a new self-contained list, with a deeper indent, at the current item of the first list level. builder.getListFormat().listIndent(); Assert.assertEquals(1, builder.getListFormat().getListLevelNumber()); // These are the first three list items of the second list level, which will maintain a count // independent of the count of the first list level. According to the current list format, // they will have symbols of "a.", "b.", and "c.". builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); // Call the "ListOutdent" method to return to the previous list level. builder.getListFormat().listOutdent(); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // These two paragraphs will continue the count of the first list level. // These items will have symbols of "2.", and "3." builder.writeln("Processing documents"); builder.writeln("Saving documents in different formats:"); // If we increase the list level to a level that we have added items to previously, // the nested list will be separate from the previous, and its numbering will start from the beginning. // These list items will have symbols of "a.", "b.", "c.", "d.", and "e". 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(); doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
applyNumberDefault | |
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 create bulleted and numbered lists.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Aspose.Words main advantages are:"); // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents. // We can create nested lists by increasing the indent level. // We can begin and end a list by using a document builder's "ListFormat" property. // Each paragraph that we add between a list's start and the end will become an item in the list. // Below are two types of lists that we can create with a document builder. // 1 - A bulleted list: // This list will apply an indent and a bullet symbol ("�") before each paragraph. 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(); builder.insertBreak(BreakType.PARAGRAPH_BREAK); builder.writeln("Aspose.Words allows:"); // 2 - A numbered list: // Numbered lists create a logical order for their paragraphs by numbering each item. builder.getListFormat().applyNumberDefault(); // This paragraph is the first item. The first item of a numbered list will have a "1." as its list item symbol. builder.writeln("Opening documents from different formats:"); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // Call the "ListIndent" method to increase the current list level, // which will start a new self-contained list, with a deeper indent, at the current item of the first list level. builder.getListFormat().listIndent(); Assert.assertEquals(1, builder.getListFormat().getListLevelNumber()); // These are the first three list items of the second list level, which will maintain a count // independent of the count of the first list level. According to the current list format, // they will have symbols of "a.", "b.", and "c.". builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); // Call the "ListOutdent" method to return to the previous list level. builder.getListFormat().listOutdent(); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // These two paragraphs will continue the count of the first list level. // These items will have symbols of "2.", and "3." builder.writeln("Processing documents"); builder.writeln("Saving documents in different formats:"); // If we increase the list level to a level that we have added items to previously, // the nested list will be separate from the previous, and its numbering will start from the beginning. // These list items will have symbols of "a.", "b.", "c.", "d.", and "e". 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(); doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
listIndent | |
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 create bulleted and numbered lists.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Aspose.Words main advantages are:"); // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents. // We can create nested lists by increasing the indent level. // We can begin and end a list by using a document builder's "ListFormat" property. // Each paragraph that we add between a list's start and the end will become an item in the list. // Below are two types of lists that we can create with a document builder. // 1 - A bulleted list: // This list will apply an indent and a bullet symbol ("�") before each paragraph. 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(); builder.insertBreak(BreakType.PARAGRAPH_BREAK); builder.writeln("Aspose.Words allows:"); // 2 - A numbered list: // Numbered lists create a logical order for their paragraphs by numbering each item. builder.getListFormat().applyNumberDefault(); // This paragraph is the first item. The first item of a numbered list will have a "1." as its list item symbol. builder.writeln("Opening documents from different formats:"); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // Call the "ListIndent" method to increase the current list level, // which will start a new self-contained list, with a deeper indent, at the current item of the first list level. builder.getListFormat().listIndent(); Assert.assertEquals(1, builder.getListFormat().getListLevelNumber()); // These are the first three list items of the second list level, which will maintain a count // independent of the count of the first list level. According to the current list format, // they will have symbols of "a.", "b.", and "c.". builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); // Call the "ListOutdent" method to return to the previous list level. builder.getListFormat().listOutdent(); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // These two paragraphs will continue the count of the first list level. // These items will have symbols of "2.", and "3." builder.writeln("Processing documents"); builder.writeln("Saving documents in different formats:"); // If we increase the list level to a level that we have added items to previously, // the nested list will be separate from the previous, and its numbering will start from the beginning. // These list items will have symbols of "a.", "b.", "c.", "d.", and "e". 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(); doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
listOutdent | |
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 create bulleted and numbered lists.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Aspose.Words main advantages are:"); // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents. // We can create nested lists by increasing the indent level. // We can begin and end a list by using a document builder's "ListFormat" property. // Each paragraph that we add between a list's start and the end will become an item in the list. // Below are two types of lists that we can create with a document builder. // 1 - A bulleted list: // This list will apply an indent and a bullet symbol ("�") before each paragraph. 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(); builder.insertBreak(BreakType.PARAGRAPH_BREAK); builder.writeln("Aspose.Words allows:"); // 2 - A numbered list: // Numbered lists create a logical order for their paragraphs by numbering each item. builder.getListFormat().applyNumberDefault(); // This paragraph is the first item. The first item of a numbered list will have a "1." as its list item symbol. builder.writeln("Opening documents from different formats:"); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // Call the "ListIndent" method to increase the current list level, // which will start a new self-contained list, with a deeper indent, at the current item of the first list level. builder.getListFormat().listIndent(); Assert.assertEquals(1, builder.getListFormat().getListLevelNumber()); // These are the first three list items of the second list level, which will maintain a count // independent of the count of the first list level. According to the current list format, // they will have symbols of "a.", "b.", and "c.". builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); // Call the "ListOutdent" method to return to the previous list level. builder.getListFormat().listOutdent(); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // These two paragraphs will continue the count of the first list level. // These items will have symbols of "2.", and "3." builder.writeln("Processing documents"); builder.writeln("Saving documents in different formats:"); // If we increase the list level to a level that we have added items to previously, // the nested list will be separate from the previous, and its numbering will start from the beginning. // These list items will have symbols of "a.", "b.", "c.", "d.", and "e". 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(); doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
removeNumbers | |
public void removeNumbers() |
Calling this method is equivalent to setting the
Example:
Shows how to create bulleted and numbered lists.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.writeln("Aspose.Words main advantages are:"); // A list allows us to organize and decorate sets of paragraphs with prefix symbols and indents. // We can create nested lists by increasing the indent level. // We can begin and end a list by using a document builder's "ListFormat" property. // Each paragraph that we add between a list's start and the end will become an item in the list. // Below are two types of lists that we can create with a document builder. // 1 - A bulleted list: // This list will apply an indent and a bullet symbol ("�") before each paragraph. 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(); builder.insertBreak(BreakType.PARAGRAPH_BREAK); builder.writeln("Aspose.Words allows:"); // 2 - A numbered list: // Numbered lists create a logical order for their paragraphs by numbering each item. builder.getListFormat().applyNumberDefault(); // This paragraph is the first item. The first item of a numbered list will have a "1." as its list item symbol. builder.writeln("Opening documents from different formats:"); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // Call the "ListIndent" method to increase the current list level, // which will start a new self-contained list, with a deeper indent, at the current item of the first list level. builder.getListFormat().listIndent(); Assert.assertEquals(1, builder.getListFormat().getListLevelNumber()); // These are the first three list items of the second list level, which will maintain a count // independent of the count of the first list level. According to the current list format, // they will have symbols of "a.", "b.", and "c.". builder.writeln("DOC"); builder.writeln("PDF"); builder.writeln("HTML"); // Call the "ListOutdent" method to return to the previous list level. builder.getListFormat().listOutdent(); Assert.assertEquals(0, builder.getListFormat().getListLevelNumber()); // These two paragraphs will continue the count of the first list level. // These items will have symbols of "2.", and "3." builder.writeln("Processing documents"); builder.writeln("Saving documents in different formats:"); // If we increase the list level to a level that we have added items to previously, // the nested list will be separate from the previous, and its numbering will start from the beginning. // These list items will have symbols of "a.", "b.", "c.", "d.", and "e". 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(); doc.save(getArtifactsDir() + "Lists.ApplyDefaultBulletsAndNumbers.docx");
Example:
Shows how to remove list formatting 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));