java.lang.ObjectStyle
com.aspose.words.TableStyle
public class TableStyle
Example:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
table.setStyle(tableStyle);
// Some Table attributes are linked to style variables
Assert.assertEquals(table.getBidi(), true);
Assert.assertEquals(table.getCellSpacing(), 5.0);
Assert.assertEquals(table.getStyleName(), "MyTableStyle1");
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");
| Property Getters/Setters Summary | ||
|---|---|---|
java.lang.String[] | getAliases() | → inherited from Style |
| Gets all aliases of this style. If style has no aliases then empty array of string is returned. | ||
int | getAlignment() | |
void | setAlignment(int value) | |
| Specifies the alignment for the table style. The value of the property is TableAlignment integer constant. | ||
boolean | getAllowBreakAcrossPages() | |
void | setAllowBreakAcrossPages(boolean value) | |
| Gets or sets a flag indicating whether text in a table row is allowed to split across a page break. | ||
java.lang.String | getBaseStyleName() | → inherited from Style |
void | setBaseStyleName(java.lang.String value) | |
| Gets/sets the name of the style this style is based on. | ||
boolean | getBidi() | |
void | setBidi(boolean value) | |
| Gets or sets whether this is a style for a right-to-left table. | ||
BorderCollection | getBorders() | |
| Gets the collection of default cell borders for the style. | ||
double | getBottomPadding() | |
void | setBottomPadding(double value) | |
| Gets or sets the amount of space (in points) to add below the contents of table cells. | ||
boolean | getBuiltIn() | → inherited from Style |
| True if this style is one of the built-in styles in MS Word. | ||
double | getCellSpacing() | |
void | setCellSpacing(double value) | |
| Gets or sets the amount of space (in points) between the cells. | ||
int | getColumnStripe() | |
void | setColumnStripe(int value) | |
| Gets or sets a number of columns to include in the banding when the style specifies odd/even columns banding. | ||
ConditionalStyleCollection | getConditionalStyles() | |
| Collection of conditional styles that may be defined for this table style. | ||
DocumentBase | getDocument() | → inherited from Style |
| Gets the owner document. | ||
Font | getFont() | → inherited from Style |
| Gets the character formatting of the style. | ||
boolean | isHeading() | → inherited from Style |
| True when the style is one of the built-in Heading styles. | ||
boolean | isQuickStyle() | → inherited from Style |
void | isQuickStyle(boolean value) | |
| Specifies whether this style is shown in the Quick Style gallery inside MS Word UI. | ||
double | getLeftIndent() | |
void | setLeftIndent(double value) | |
| Gets or sets the value that represents the left indent of a table. | ||
double | getLeftPadding() | |
void | setLeftPadding(double value) | |
| Gets or sets the amount of space (in points) to add to the left of the contents of table cells. | ||
java.lang.String | getLinkedStyleName() | → inherited from Style |
| Gets the name of the Style linked to this one. Returns Empty string if no styles are linked. | ||
List | getList() | → inherited from Style |
| Gets the list that defines formatting of this list style. | ||
ListFormat | getListFormat() | → inherited from Style |
| Provides access to the list formatting properties of a paragraph style. | ||
java.lang.String | getName() | → inherited from Style |
void | setName(java.lang.String value) | |
| Gets or sets the name of the style. | ||
java.lang.String | getNextParagraphStyleName() | → inherited from Style |
void | setNextParagraphStyleName(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. | ||
ParagraphFormat | getParagraphFormat() | → inherited from Style |
| Gets the paragraph formatting of the style. | ||
double | getRightPadding() | |
void | setRightPadding(double value) | |
| Gets or sets the amount of space (in points) to add to the right of the contents of table cells. | ||
int | getRowStripe() | |
void | setRowStripe(int value) | |
| Gets or sets a number of rows to include in the banding when the style specifies odd/even row banding. | ||
Shading | getShading() | |
|
Gets a |
||
int | getStyleIdentifier() | → inherited from Style |
| Gets the locale independent style identifier for a built-in style. The value of the property is StyleIdentifier integer constant. | ||
StyleCollection | getStyles() | → inherited from Style |
| Gets the collection of styles this style belongs to. | ||
double | getTopPadding() | |
void | setTopPadding(double value) | |
| Gets or sets the amount of space (in points) to add above the contents of table cells. | ||
int | getType() | → inherited from Style |
| Gets the style type (paragraph or character). The value of the property is StyleType integer constant. | ||
| Method Summary | ||
|---|---|---|
boolean | equals(Style style) | → inherited from Style |
| Compares with the specified style. Styles Istds are compared for built-in styles only. Styles defaults are not included in comparison. Base style, linked style and next paragraph style are recursively compared. | ||
void | remove() | → inherited from Style |
| Removes the specified style from the document. | ||
| Property Getters/Setters Detail |
|---|
getAliases | → inherited from Style |
public java.lang.String[] getAliases() | |
Example:
Shows how to use style aliases.
// Open a document that had a style inserted with commas in its name which separate the style name and aliases
Document doc = new Document(getMyDir() + "StyleWithAlias.docx");
// The aliases, separate from the name can be found here
Style style = doc.getStyles().get("MyStyle");
Assert.assertEquals(new String[]{"MyStyle Alias 1", "MyStyle Alias 2"}, style.getAliases());
Assert.assertEquals("Title", style.getBaseStyleName());
Assert.assertEquals("MyStyle Char", style.getLinkedStyleName());
// A style can be referenced by alias as well as name
Assert.assertTrue(style.equals(doc.getStyles().get("MyStyle Alias 1")));getAlignment/setAlignment | |
public int getAlignment() / public void setAlignment(int value) | |
Example:
Shows how to set table position.Document doc = new Document(); TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1"); // By default AW uses Alignment instead of LeftIndent // To set table position use tableStyle.setAlignment(TableAlignment.CENTER); // or tableStyle.setLeftIndent(55.0);
getAllowBreakAcrossPages/setAllowBreakAcrossPages | |
public boolean getAllowBreakAcrossPages() / public void setAllowBreakAcrossPages(boolean value) | |
Example:
Shows how to create your own style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
table.setStyle(tableStyle);
// Some Table attributes are linked to style variables
Assert.assertEquals(table.getBidi(), true);
Assert.assertEquals(table.getCellSpacing(), 5.0);
Assert.assertEquals(table.getStyleName(), "MyTableStyle1");
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");getBaseStyleName/setBaseStyleName | → inherited from Style |
public java.lang.String getBaseStyleName() / public void setBaseStyleName(java.lang.String value) | |
Example:
Shows how to use style aliases.
// Open a document that had a style inserted with commas in its name which separate the style name and aliases
Document doc = new Document(getMyDir() + "StyleWithAlias.docx");
// The aliases, separate from the name can be found here
Style style = doc.getStyles().get("MyStyle");
Assert.assertEquals(new String[]{"MyStyle Alias 1", "MyStyle Alias 2"}, style.getAliases());
Assert.assertEquals("Title", style.getBaseStyleName());
Assert.assertEquals("MyStyle Char", style.getLinkedStyleName());
// A style can be referenced by alias as well as name
Assert.assertTrue(style.equals(doc.getStyles().get("MyStyle Alias 1")));getBidi/setBidi | |
public boolean getBidi() / public void setBidi(boolean value) | |
When true, the cells in rows are laid out right to left.
The default value is false.
Example:
Shows how to create your own style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
table.setStyle(tableStyle);
// Some Table attributes are linked to style variables
Assert.assertEquals(table.getBidi(), true);
Assert.assertEquals(table.getCellSpacing(), 5.0);
Assert.assertEquals(table.getStyleName(), "MyTableStyle1");
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");getBorders | |
public BorderCollection getBorders() | |
Example:
Shows how to create your own style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
table.setStyle(tableStyle);
// Some Table attributes are linked to style variables
Assert.assertEquals(table.getBidi(), true);
Assert.assertEquals(table.getCellSpacing(), 5.0);
Assert.assertEquals(table.getStyleName(), "MyTableStyle1");
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");getBottomPadding/setBottomPadding | |
public double getBottomPadding() / public void setBottomPadding(double value) | |
Example:
Shows how to create your own style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
table.setStyle(tableStyle);
// Some Table attributes are linked to style variables
Assert.assertEquals(table.getBidi(), true);
Assert.assertEquals(table.getCellSpacing(), 5.0);
Assert.assertEquals(table.getStyleName(), "MyTableStyle1");
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");getBuiltIn | → inherited from Style |
public boolean getBuiltIn() | |
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 runs = doc.getChildNodes(NodeType.RUN, true);
// Loop through every run node.
for (Run run : (Iterable<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(getArtifactsDir() + "Font.Style.doc");getCellSpacing/setCellSpacing | |
public double getCellSpacing() / public void setCellSpacing(double value) | |
Example:
Shows how to create your own style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
table.setStyle(tableStyle);
// Some Table attributes are linked to style variables
Assert.assertEquals(table.getBidi(), true);
Assert.assertEquals(table.getCellSpacing(), 5.0);
Assert.assertEquals(table.getStyleName(), "MyTableStyle1");
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");getColumnStripe/setColumnStripe | |
public int getColumnStripe() / public void setColumnStripe(int value) | |
Example:
Shows how to work with odd/even row/column styles.Document doc = new Document(getMyDir() + "Table.ConditionalStyles.docx"); TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1"); tableStyle.getBorders().setColor(Color.BLACK); tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH); // Define our stripe through one column and row tableStyle.setColumnStripe(1); tableStyle.setRowStripe(1); // Let's start from the first row and second column tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.ODD_ROW_BANDING).getShading().setBackgroundPatternColor(Color.BLUE); tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.EVEN_COLUMN_BANDING).getShading().setBackgroundPatternColor(Color.BLUE); Table table = (Table) doc.getChild(NodeType.TABLE, 0, true); table.setStyle(tableStyle); doc.save(getArtifactsDir() + "Table.WorkWithOddEvenRowColumnStyles.docx");
getConditionalStyles | |
public ConditionalStyleCollection getConditionalStyles() | |
Example:
Shows how to work with certain area styles of a table.Document doc = new Document(getMyDir() + "Table.ConditionalStyles.docx"); TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1"); // There is a different ways how to get conditional styles: // by conditional style type tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.FIRST_ROW).getShading().setBackgroundPatternColor(Color.BLUE); // by index tableStyle.getConditionalStyles().get(0).getBorders().setColor(Color.BLACK); tableStyle.getConditionalStyles().get(0).getBorders().setLineStyle(LineStyle.DOT_DASH); Assert.assertEquals(tableStyle.getConditionalStyles().get(0).getType(), ConditionalStyleType.FIRST_ROW); // directly from ConditionalStyleCollection tableStyle.getConditionalStyles().getFirstRow().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER); // To see this in Word document select Total Row checkbox in Design Tab tableStyle.getConditionalStyles().getLastRow().setBottomPadding(10.0); tableStyle.getConditionalStyles().getLastRow().setLeftPadding(10.0); tableStyle.getConditionalStyles().getLastRow().setRightPadding(10.0); tableStyle.getConditionalStyles().getLastRow().setTopPadding(10.0); // To see this in Word document select Last Column checkbox in Design Tab tableStyle.getConditionalStyles().getLastColumn().getFont().setBold(true); System.out.println(tableStyle.getConditionalStyles().getCount()); System.out.println(tableStyle.getConditionalStyles().get(0).getType()); Table table = (Table) doc.getChild(NodeType.TABLE, 0, true); table.setStyle(tableStyle); doc.save(getArtifactsDir() + "Table.WorkWithTableConditionalStyles.docx");
getDocument | → inherited from Style |
public DocumentBase getDocument() | |
Example:
Shows how to get access to the collection of styles defined in the document.
Document doc = new Document();
StyleCollection styles = doc.getStyles();
Iterator<Style> stylesEnum = doc.getStyles().iterator();
while (stylesEnum.hasNext()) {
Style curStyle = stylesEnum.next();
System.out.println(MessageFormat.format("Style name:\t\"{0}\", of type \"{1}\"", curStyle.getName(), curStyle.getType()));
System.out.println(MessageFormat.format("\tSubsequent style:\t{0}", curStyle.getNextParagraphStyleName()));
System.out.println(MessageFormat.format("\tIs heading:\t\t\t{0}", curStyle.isHeading()));
System.out.println(MessageFormat.format("\tIs QuickStyle:\t\t{0}", curStyle.isQuickStyle()));
Assert.assertEquals(curStyle.getDocument(), doc);
}getFont | → inherited from Style |
public Font getFont() | |
For list styles this property returns null.
Example:
Shows how to change the font formatting of all styles in a document.
Document doc = new Document();
for (Style style : doc.getStyles()) {
if (style.getFont() != null) {
style.getFont().clearFormatting();
style.getFont().setSize(20);
style.getFont().setName("Arial");
}
}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(getArtifactsDir() + "Lists.ParagraphStyleBulleted.doc");isHeading | → inherited from Style |
public boolean isHeading() | |
Example:
Shows how to get access to the collection of styles defined in the document.
Document doc = new Document();
StyleCollection styles = doc.getStyles();
Iterator<Style> stylesEnum = doc.getStyles().iterator();
while (stylesEnum.hasNext()) {
Style curStyle = stylesEnum.next();
System.out.println(MessageFormat.format("Style name:\t\"{0}\", of type \"{1}\"", curStyle.getName(), curStyle.getType()));
System.out.println(MessageFormat.format("\tSubsequent style:\t{0}", curStyle.getNextParagraphStyleName()));
System.out.println(MessageFormat.format("\tIs heading:\t\t\t{0}", curStyle.isHeading()));
System.out.println(MessageFormat.format("\tIs QuickStyle:\t\t{0}", curStyle.isQuickStyle()));
Assert.assertEquals(curStyle.getDocument(), doc);
}isQuickStyle/isQuickStyle | → inherited from Style |
public boolean isQuickStyle() / public void isQuickStyle(boolean value) | |
Example:
Shows how to get access to the collection of styles defined in the document.
Document doc = new Document();
StyleCollection styles = doc.getStyles();
Iterator<Style> stylesEnum = doc.getStyles().iterator();
while (stylesEnum.hasNext()) {
Style curStyle = stylesEnum.next();
System.out.println(MessageFormat.format("Style name:\t\"{0}\", of type \"{1}\"", curStyle.getName(), curStyle.getType()));
System.out.println(MessageFormat.format("\tSubsequent style:\t{0}", curStyle.getNextParagraphStyleName()));
System.out.println(MessageFormat.format("\tIs heading:\t\t\t{0}", curStyle.isHeading()));
System.out.println(MessageFormat.format("\tIs QuickStyle:\t\t{0}", curStyle.isQuickStyle()));
Assert.assertEquals(curStyle.getDocument(), doc);
}getLeftIndent/setLeftIndent | |
public double getLeftIndent() / public void setLeftIndent(double value) | |
Example:
Shows how to set table position.Document doc = new Document(); TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1"); // By default AW uses Alignment instead of LeftIndent // To set table position use tableStyle.setAlignment(TableAlignment.CENTER); // or tableStyle.setLeftIndent(55.0);
getLeftPadding/setLeftPadding | |
public double getLeftPadding() / public void setLeftPadding(double value) | |
Example:
Shows how to create your own style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
table.setStyle(tableStyle);
// Some Table attributes are linked to style variables
Assert.assertEquals(table.getBidi(), true);
Assert.assertEquals(table.getCellSpacing(), 5.0);
Assert.assertEquals(table.getStyleName(), "MyTableStyle1");
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");getLinkedStyleName | → inherited from Style |
public java.lang.String getLinkedStyleName() | |
Example:
Shows how to use style aliases.
// Open a document that had a style inserted with commas in its name which separate the style name and aliases
Document doc = new Document(getMyDir() + "StyleWithAlias.docx");
// The aliases, separate from the name can be found here
Style style = doc.getStyles().get("MyStyle");
Assert.assertEquals(new String[]{"MyStyle Alias 1", "MyStyle Alias 2"}, style.getAliases());
Assert.assertEquals("Title", style.getBaseStyleName());
Assert.assertEquals("MyStyle Char", style.getLinkedStyleName());
// A style can be referenced by alias as well as name
Assert.assertTrue(style.equals(doc.getStyles().get("MyStyle Alias 1")));getList | → inherited from Style |
public List getList() | |
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.
System.out.println("IsListStyleDefinition: " + list1.isListStyleDefinition()); // Will be true
System.out.println("IsListStyleReference: " + list1.isListStyleReference()); // Will be false
System.out.println("IsMultiLevel: " + list1.isMultiLevel()); // Will be true
System.out.println("List style has been set: " + (listStyle == list1.getStyle())); // Are equal
// 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.
System.out.println("IsListStyleDefinition: " + list2.isListStyleDefinition()); // Will be false
System.out.println("IsListStyleReference: " + list2.isListStyleReference()); // Will be true
System.out.println("List Style has been set: " + (listStyle == list2.getStyle())); // Are equal
// 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(getArtifactsDir() + "Lists.CreateAndUseListStyle.doc");getListFormat | → inherited from Style |
public ListFormat getListFormat() | |
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(getArtifactsDir() + "Lists.ParagraphStyleBulleted.doc");getName/setName | → inherited from Style |
public java.lang.String getName() / public void setName(java.lang.String value) | |
Can not be empty string.
If there already is a style with such name in the collection, then this style will override it. All affected nodes will reference new style.
Example:
Demonstrates how to copy a style within the same document.
// The AddCopy method creates a copy of the specified style and automatically generates a new name for the style, such as "Heading 1_0".
Style newStyle = doc.getStyles().addCopy(doc.getStyles().get("Heading 1"));
// You can change the new style name if required as the Style.Name property is read-write.
newStyle.setName("My Heading 1");Example:
Shows how to get access to the collection of styles defined in the document.
Document doc = new Document();
StyleCollection styles = doc.getStyles();
Iterator<Style> stylesEnum = doc.getStyles().iterator();
while (stylesEnum.hasNext()) {
Style curStyle = stylesEnum.next();
System.out.println(MessageFormat.format("Style name:\t\"{0}\", of type \"{1}\"", curStyle.getName(), curStyle.getType()));
System.out.println(MessageFormat.format("\tSubsequent style:\t{0}", curStyle.getNextParagraphStyleName()));
System.out.println(MessageFormat.format("\tIs heading:\t\t\t{0}", curStyle.isHeading()));
System.out.println(MessageFormat.format("\tIs QuickStyle:\t\t{0}", curStyle.isQuickStyle()));
Assert.assertEquals(curStyle.getDocument(), doc);
}getNextParagraphStyleName/setNextParagraphStyleName | → inherited from Style |
public java.lang.String getNextParagraphStyleName() / public void setNextParagraphStyleName(java.lang.String value) | |
Example:
Shows how to get access to the collection of styles defined in the document.
Document doc = new Document();
StyleCollection styles = doc.getStyles();
Iterator<Style> stylesEnum = doc.getStyles().iterator();
while (stylesEnum.hasNext()) {
Style curStyle = stylesEnum.next();
System.out.println(MessageFormat.format("Style name:\t\"{0}\", of type \"{1}\"", curStyle.getName(), curStyle.getType()));
System.out.println(MessageFormat.format("\tSubsequent style:\t{0}", curStyle.getNextParagraphStyleName()));
System.out.println(MessageFormat.format("\tIs heading:\t\t\t{0}", curStyle.isHeading()));
System.out.println(MessageFormat.format("\tIs QuickStyle:\t\t{0}", curStyle.isQuickStyle()));
Assert.assertEquals(curStyle.getDocument(), doc);
}getParagraphFormat | → inherited from Style |
public ParagraphFormat getParagraphFormat() | |
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(getArtifactsDir() + "Lists.ParagraphStyleBulleted.doc");getRightPadding/setRightPadding | |
public double getRightPadding() / public void setRightPadding(double value) | |
Example:
Shows how to create your own style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
table.setStyle(tableStyle);
// Some Table attributes are linked to style variables
Assert.assertEquals(table.getBidi(), true);
Assert.assertEquals(table.getCellSpacing(), 5.0);
Assert.assertEquals(table.getStyleName(), "MyTableStyle1");
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");getRowStripe/setRowStripe | |
public int getRowStripe() / public void setRowStripe(int value) | |
Example:
Shows how to work with odd/even row/column styles.Document doc = new Document(getMyDir() + "Table.ConditionalStyles.docx"); TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1"); tableStyle.getBorders().setColor(Color.BLACK); tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH); // Define our stripe through one column and row tableStyle.setColumnStripe(1); tableStyle.setRowStripe(1); // Let's start from the first row and second column tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.ODD_ROW_BANDING).getShading().setBackgroundPatternColor(Color.BLUE); tableStyle.getConditionalStyles().getByConditionalStyleType(ConditionalStyleType.EVEN_COLUMN_BANDING).getShading().setBackgroundPatternColor(Color.BLUE); Table table = (Table) doc.getChild(NodeType.TABLE, 0, true); table.setStyle(tableStyle); doc.save(getArtifactsDir() + "Table.WorkWithOddEvenRowColumnStyles.docx");
getShading | |
public Shading getShading() | |
Example:
Shows how to create your own style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
table.setStyle(tableStyle);
// Some Table attributes are linked to style variables
Assert.assertEquals(table.getBidi(), true);
Assert.assertEquals(table.getCellSpacing(), 5.0);
Assert.assertEquals(table.getStyleName(), "MyTableStyle1");
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");getStyleIdentifier | → inherited from Style |
public int getStyleIdentifier() | |
For user defined (custom) styles, this property returns
Example:
Shows how to modify the position of the right tab stop in TOC related paragraphs.
Document doc = new Document(getMyDir() + "Document.TableOfContents.doc");
// Iterate through all paragraphs in the document
for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
// Check if this paragraph is formatted using the TOC result based styles. This is any style between TOC and TOC9.
if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1
&& para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) {
// Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
TabStop tab = para.getParagraphFormat().getTabStops().get(0);
// Remove the old tab from the collection.
para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition());
// Insert a new tab using the same properties but at a modified position.
// We could also change the separators used (dots) by passing a different Leader type
para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50, tab.getAlignment(), tab.getLeader());
}
}
doc.save(getArtifactsDir() + "Document.TableOfContentsTabStops.doc");getStyles | → inherited from Style |
public StyleCollection getStyles() | |
Example:
Shows how to get access to the collection of styles defined in the document.
Document doc = new Document();
StyleCollection styles = doc.getStyles();
Iterator<Style> stylesEnum = doc.getStyles().iterator();
while (stylesEnum.hasNext()) {
Style curStyle = stylesEnum.next();
System.out.println(MessageFormat.format("Style name:\t\"{0}\", of type \"{1}\"", curStyle.getName(), curStyle.getType()));
System.out.println(MessageFormat.format("\tSubsequent style:\t{0}", curStyle.getNextParagraphStyleName()));
System.out.println(MessageFormat.format("\tIs heading:\t\t\t{0}", curStyle.isHeading()));
System.out.println(MessageFormat.format("\tIs QuickStyle:\t\t{0}", curStyle.isQuickStyle()));
Assert.assertEquals(curStyle.getDocument(), doc);
}getTopPadding/setTopPadding | |
public double getTopPadding() / public void setTopPadding(double value) | |
Example:
Shows how to create your own style settings for the table.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("Name");
builder.insertCell();
builder.write("مرحبًا");
builder.endRow();
builder.insertCell();
builder.insertCell();
builder.endTable();
TableStyle tableStyle = (TableStyle) doc.getStyles().add(StyleType.TABLE, "MyTableStyle1");
tableStyle.setAllowBreakAcrossPages(true);
tableStyle.setBidi(true);
tableStyle.setCellSpacing(5.0);
tableStyle.setBottomPadding(20.0);
tableStyle.setLeftPadding(5.0);
tableStyle.setRightPadding(10.0);
tableStyle.setTopPadding(20.0);
tableStyle.getShading().setBackgroundPatternColor(Color.WHITE);
tableStyle.getBorders().setColor(Color.BLACK);
tableStyle.getBorders().setLineStyle(LineStyle.DOT_DASH);
table.setStyle(tableStyle);
// Some Table attributes are linked to style variables
Assert.assertEquals(table.getBidi(), true);
Assert.assertEquals(table.getCellSpacing(), 5.0);
Assert.assertEquals(table.getStyleName(), "MyTableStyle1");
doc.save(getArtifactsDir() + "Table.TableStyleCreation.docx");getType | → inherited from Style |
public int getType() | |
Example:
Shows how to get access to the collection of styles defined in the document.
Document doc = new Document();
StyleCollection styles = doc.getStyles();
Iterator<Style> stylesEnum = doc.getStyles().iterator();
while (stylesEnum.hasNext()) {
Style curStyle = stylesEnum.next();
System.out.println(MessageFormat.format("Style name:\t\"{0}\", of type \"{1}\"", curStyle.getName(), curStyle.getType()));
System.out.println(MessageFormat.format("\tSubsequent style:\t{0}", curStyle.getNextParagraphStyleName()));
System.out.println(MessageFormat.format("\tIs heading:\t\t\t{0}", curStyle.isHeading()));
System.out.println(MessageFormat.format("\tIs QuickStyle:\t\t{0}", curStyle.isQuickStyle()));
Assert.assertEquals(curStyle.getDocument(), doc);
}| Method Detail |
|---|
equals | → inherited from Style |
public boolean equals(Style style) | |
Example:
Shows how to use style aliases.
// Open a document that had a style inserted with commas in its name which separate the style name and aliases
Document doc = new Document(getMyDir() + "StyleWithAlias.docx");
// The aliases, separate from the name can be found here
Style style = doc.getStyles().get("MyStyle");
Assert.assertEquals(new String[]{"MyStyle Alias 1", "MyStyle Alias 2"}, style.getAliases());
Assert.assertEquals("Title", style.getBaseStyleName());
Assert.assertEquals("MyStyle Char", style.getLinkedStyleName());
// A style can be referenced by alias as well as name
Assert.assertTrue(style.equals(doc.getStyles().get("MyStyle Alias 1")));remove | → inherited from Style |
public void remove() | |
Example:
Shows how to pick a style that is defined in the document and remove it.
Document doc = new Document();
doc.getStyles().get("Normal").remove();