java.lang.Object
com.aspose.words.Style
- All Implemented Interfaces:
- java.lang.Cloneable
public class Style
- extends java.lang.Object
Represents a single built-in or user-defined style.
Example:
Shows how to create and use a paragraph style with list formatting.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a paragraph style and specify some formatting for it.
Style style = doc.getStyles().add(StyleType.PARAGRAPH, "MyStyle1");
style.getFont().setSize(24);
style.getFont().setName("Verdana");
style.getParagraphFormat().setSpaceAfter(12);
// Create a list and make sure the paragraphs that use this style will use this list.
style.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DEFAULT));
style.getListFormat().setListLevelNumber(0);
// Apply the paragraph style to the current paragraph in the document and add some text.
builder.getParagraphFormat().setStyle(style);
builder.writeln("Hello World: MyStyle1, bulleted.");
// Change to a paragraph style that has no list formatting.
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
builder.writeln("Hello World: Normal.");
builder.getDocument().save(getMyDir() + "Lists.ParagraphStyleBulleted Out.doc");
Property Getters/Setters Detail |
getName | |
public java.lang.String getName()
|
-
Gets the name of the style.
Names of built-in styles in documents created in different languages of MS Word can be different.
- See Also:
- StyleIdentifier
getStyleIdentifier | |
public int getStyleIdentifier()
|
-
Gets the locale independent style identifier for a built-in style.
The value of the property is StyleIdentifier integer constant.
For user defined (custom) styles, this property returns StyleIdentifier.USER.
- See Also:
- Name
isHeading | |
public boolean isHeading()
|
-
True when the style is one of the built-in Heading styles.
getType | |
public int getType()
|
-
Gets the style type (paragraph or character).
The value of the property is StyleType integer constant.
-
Gets the owner document.
getBaseStyle/setBaseStyle | |
public java.lang.String getBaseStyle() / public void setBaseStyle(java.lang.String value)
|
-
Gets/sets the name of the style this style is based on.
This will be an empty string if the style is not based on any other style and it can be set
to an empty string.
getNextParagraphStyle/setNextParagraphStyle | |
public java.lang.String getNextParagraphStyle() / public void setNextParagraphStyle(java.lang.String value)
|
-
Gets/sets the name of the style to be applied automatically to a new paragraph inserted after a
paragraph formatted with the specified style.
This property is not used by Aspose.Words. The next paragraph style will only
be applied automatically when you edit the document in MS Word.
getBuiltIn | |
public boolean getBuiltIn()
|
-
True if this style is one of the built-in styles in MS Word.
Example:
Applies double underline to all runs in a document that are formatted with custom character styles.
Document doc = new Document(getMyDir() + "Font.Style.doc");
// Select all run nodes in the document.
NodeCollection<Run> runs = doc.getChildNodes(NodeType.RUN, true);
// Loop through every run node.
for (Run run : runs)
{
Style charStyle = run.getFont().getStyle();
// If the style of the run is not a built-in character style, apply double underline.
if (!charStyle.getBuiltIn())
run.getFont().setUnderline(Underline.DOUBLE);
}
doc.save(getMyDir() + "Font.Style Out.doc");
getFont | |
public Font getFont()
|
-
Gets the character formatting of the style.
For list styles this property returns null.
Example:
Shows how to create and use a paragraph style with list formatting.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a paragraph style and specify some formatting for it.
Style style = doc.getStyles().add(StyleType.PARAGRAPH, "MyStyle1");
style.getFont().setSize(24);
style.getFont().setName("Verdana");
style.getParagraphFormat().setSpaceAfter(12);
// Create a list and make sure the paragraphs that use this style will use this list.
style.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DEFAULT));
style.getListFormat().setListLevelNumber(0);
// Apply the paragraph style to the current paragraph in the document and add some text.
builder.getParagraphFormat().setStyle(style);
builder.writeln("Hello World: MyStyle1, bulleted.");
// Change to a paragraph style that has no list formatting.
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
builder.writeln("Hello World: Normal.");
builder.getDocument().save(getMyDir() + "Lists.ParagraphStyleBulleted Out.doc");
-
Gets the paragraph formatting of the style.
For character and list styles this property returns null.
Example:
Shows how to create and use a paragraph style with list formatting.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a paragraph style and specify some formatting for it.
Style style = doc.getStyles().add(StyleType.PARAGRAPH, "MyStyle1");
style.getFont().setSize(24);
style.getFont().setName("Verdana");
style.getParagraphFormat().setSpaceAfter(12);
// Create a list and make sure the paragraphs that use this style will use this list.
style.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DEFAULT));
style.getListFormat().setListLevelNumber(0);
// Apply the paragraph style to the current paragraph in the document and add some text.
builder.getParagraphFormat().setStyle(style);
builder.writeln("Hello World: MyStyle1, bulleted.");
// Change to a paragraph style that has no list formatting.
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
builder.writeln("Hello World: Normal.");
builder.getDocument().save(getMyDir() + "Lists.ParagraphStyleBulleted Out.doc");
getList | |
public List getList()
|
-
Gets the list that defines formatting of this list style.
This property is only valid for list styles.
For other style types this property returns null.
Example:
Shows how to create a list style and use it in a document.
Document doc = new Document();
// Create a new list style.
// List formatting associated with this list style is default numbered.
Style listStyle = doc.getStyles().add(StyleType.LIST, "MyListStyle");
// This list defines the formatting of the list style.
// Note this list can not be used directly to apply formatting to paragraphs (see below).
List list1 = listStyle.getList();
// Check some basic rules about the list that defines a list style.
Assert.assertTrue(list1.isListStyleDefinition());
Assert.assertFalse(list1.isListStyleReference());
Assert.assertTrue(list1.isMultiLevel());
Assert.assertEquals(listStyle, list1.getStyle());
// Modify formatting of the list style to our liking.
for (int i = 0; i < list1.getListLevels().getCount(); i++)
{
ListLevel level = list1.getListLevels().get(i);
level.getFont().setName("Verdana");
level.getFont().setColor(Color.BLUE);
level.getFont().setBold(true);
}
// Add some text to our document and use the list style.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Using list style first time:");
// This creates a list based on the list style.
List list2 = doc.getLists().add(listStyle);
// Check some basic rules about the list that references a list style.
Assert.assertFalse(list2.isListStyleDefinition());
Assert.assertTrue(list2.isListStyleReference());
Assert.assertEquals(listStyle,list2.getStyle());
// Apply the list that references the list style.
builder.getListFormat().setList(list2);
builder.writeln("Item 1");
builder.writeln("Item 2");
builder.getListFormat().removeNumbers();
builder.writeln("Using list style second time:");
// Create and apply another list based on the list style.
List list3 = doc.getLists().add(listStyle);
builder.getListFormat().setList(list3);
builder.writeln("Item 1");
builder.writeln("Item 2");
builder.getListFormat().removeNumbers();
builder.getDocument().save(getMyDir() + "Lists.CreateAndUseListStyle Out.doc");
-
Provides access to the list formatting properties of a paragraph style.
This property is only valid for paragraph styles.
For other style types this property returns null.
Example:
Shows how to create and use a paragraph style with list formatting.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a paragraph style and specify some formatting for it.
Style style = doc.getStyles().add(StyleType.PARAGRAPH, "MyStyle1");
style.getFont().setSize(24);
style.getFont().setName("Verdana");
style.getParagraphFormat().setSpaceAfter(12);
// Create a list and make sure the paragraphs that use this style will use this list.
style.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DEFAULT));
style.getListFormat().setListLevelNumber(0);
// Apply the paragraph style to the current paragraph in the document and add some text.
builder.getParagraphFormat().setStyle(style);
builder.writeln("Hello World: MyStyle1, bulleted.");
// Change to a paragraph style that has no list formatting.
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
builder.writeln("Hello World: Normal.");
builder.getDocument().save(getMyDir() + "Lists.ParagraphStyleBulleted Out.doc");
-
Gets the collection of styles this style belongs to.
getDirectParaAttr | |
public java.lang.Object getDirectParaAttr(int key) |
- Reserved for internal use.
getDirectParaAttrsCount | |
public int getDirectParaAttrsCount() |
- Reserved for internal use.
getDirectParaAttrByIndex | |
public void getDirectParaAttrByIndex(int index, System.Int32& key, System.Object& value) |
- Reserved for internal use.
fetchInheritedParaAttr | |
public java.lang.Object fetchInheritedParaAttr(int key)
throws java.lang.Exception |
- Reserved for internal use.
fetchParaAttr | |
public java.lang.Object fetchParaAttr(int key)
throws java.lang.Exception |
- Reserved for internal use.
setParaAttr | |
public void setParaAttr(int key, java.lang.Object value) |
- Reserved for internal use.
removeParaAttr | |
public void removeParaAttr(int key) |
- Reserved for internal use.
clearParaAttrs | |
public void clearParaAttrs() |
- Reserved for internal use.
getDirectRunAttr | |
public java.lang.Object getDirectRunAttr(int key) |
- Reserved for internal use.
getDirectRunAttrsCount | |
public int getDirectRunAttrsCount() |
- Reserved for internal use.
getDirectRunAttrByIndex | |
public void getDirectRunAttrByIndex(int index, int[] key, java.lang.Object[] value) |
- Reserved for internal use.
fetchInheritedRunAttr | |
public java.lang.Object fetchInheritedRunAttr(int key)
throws java.lang.Exception |
- Reserved for internal use.
setRunAttr | |
public void setRunAttr(int key, java.lang.Object value) |
- Reserved for internal use.
clearRunAttrs | |
public void clearRunAttrs() |
- Reserved for internal use.
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.