com.aspose.words

Class TableStyle

  • java.lang.Object
    • Style
      • com.aspose.words.TableStyle
  • All Implemented Interfaces:
    java.lang.Cloneable
    public class TableStyle 
    extends Style

Represents a table style.

Property Getters/Setters Summary
java.lang.String[]getAliases()
Gets all aliases of this style. If style has no aliases then empty array of string is returned.
intgetAlignment()
void
setAlignment(intvalue)
           Specifies the alignment for the table style. The value of the property is TableAlignment integer constant.
booleangetAllowBreakAcrossPages()
void
           Gets or sets a flag indicating whether text in a table row is allowed to split across a page break.
java.lang.StringgetBaseStyleName()
void
setBaseStyleName(java.lang.Stringvalue)
           Gets/sets the name of the style this style is based on.
booleangetBidi()
void
setBidi(booleanvalue)
           Gets or sets whether this is a style for a right-to-left table.
BorderCollectiongetBorders()
Gets the collection of default cell borders for the style.
doublegetBottomPadding()
void
setBottomPadding(doublevalue)
           Gets or sets the amount of space (in points) to add below the contents of table cells.
booleangetBuiltIn()
True if this style is one of the built-in styles in MS Word.
doublegetCellSpacing()
void
setCellSpacing(doublevalue)
           Gets or sets the amount of space (in points) between the cells.
intgetColumnStripe()
void
setColumnStripe(intvalue)
           Gets or sets a number of columns to include in the banding when the style specifies odd/even columns banding.
ConditionalStyleCollectiongetConditionalStyles()
Collection of conditional styles that may be defined for this table style.
DocumentBasegetDocument()
Gets the owner document.
FontgetFont()
Gets the character formatting of the style.
booleanisHeading()
True when the style is one of the built-in Heading styles.
booleanisQuickStyle()
void
isQuickStyle(booleanvalue)
           Specifies whether this style is shown in the Quick Style gallery inside MS Word UI.
doublegetLeftIndent()
void
setLeftIndent(doublevalue)
           Gets or sets the value that represents the left indent of a table.
doublegetLeftPadding()
void
setLeftPadding(doublevalue)
           Gets or sets the amount of space (in points) to add to the left of the contents of table cells.
java.lang.StringgetLinkedStyleName()
Gets the name of the Style linked to this one. Returns Empty string if no styles are linked.
ListgetList()
Gets the list that defines formatting of this list style.
ListFormatgetListFormat()
Provides access to the list formatting properties of a paragraph style.
java.lang.StringgetName()
void
setName(java.lang.Stringvalue)
           Gets or sets the name of the style.
java.lang.StringgetNextParagraphStyleName()
void
setNextParagraphStyleName(java.lang.Stringvalue)
           Gets/sets the name of the style to be applied automatically to a new paragraph inserted after a paragraph formatted with the specified style.
ParagraphFormatgetParagraphFormat()
Gets the paragraph formatting of the style.
doublegetRightPadding()
void
setRightPadding(doublevalue)
           Gets or sets the amount of space (in points) to add to the right of the contents of table cells.
intgetRowStripe()
void
setRowStripe(intvalue)
           Gets or sets a number of rows to include in the banding when the style specifies odd/even row banding.
ShadinggetShading()
Gets a Shading object that refers to the shading formatting for table cells.
intgetStyleIdentifier()
Gets the locale independent style identifier for a built-in style. The value of the property is StyleIdentifier integer constant.
StyleCollectiongetStyles()
Gets the collection of styles this style belongs to.
doublegetTopPadding()
void
setTopPadding(doublevalue)
           Gets or sets the amount of space (in points) to add above the contents of table cells.
intgetType()
Gets the style type (paragraph or character). The value of the property is StyleType integer constant.
 
Method Summary
voidclearCellAttrs()
java.lang.ObjectfetchInheritedParaAttr(int key)
Deprecated. Reserved for internal use.
java.lang.ObjectfetchParaAttr(int key)
Deprecated. Reserved for internal use.
voidremove()
Removes the specified style from the document.
 

    • Property Getters/Setters Detail

      • getAliases

        public java.lang.String[] getAliases()
        
        Gets all aliases of this style. If style has no aliases then empty array of string is returned.
      • getAlignment/setAlignment

        public int getAlignment() / public void setAlignment(int value)
        
        Specifies the alignment for the table style. The value of the property is TableAlignment integer constant. The default value is TableAlignment.LEFT.
      • getAllowBreakAcrossPages/setAllowBreakAcrossPages

        public boolean getAllowBreakAcrossPages() / public void setAllowBreakAcrossPages(boolean value)
        
        Gets or sets a flag indicating whether text in a table row is allowed to split across a page break. The default value is true.
      • getBaseStyleName/setBaseStyleName

        public java.lang.String getBaseStyleName() / public void setBaseStyleName(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.
      • getBidi/setBidi

        public boolean getBidi() / public void setBidi(boolean value)
        
        Gets or sets whether this is a style for a right-to-left table.

        When true, the cells in rows are laid out right to left.

        The default value is false.

      • getBorders

        public BorderCollection getBorders()
        
        Gets the collection of default cell borders for the style.
      • getBottomPadding/setBottomPadding

        public double getBottomPadding() / public void setBottomPadding(double value)
        
        Gets or sets the amount of space (in points) to add below the contents of table cells.
      • 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 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)
        
        Gets or sets the amount of space (in points) between the cells.
      • getColumnStripe/setColumnStripe

        public int getColumnStripe() / public void setColumnStripe(int value)
        
        Gets or sets a number of columns to include in the banding when the style specifies odd/even columns banding.
      • getConditionalStyles

        public ConditionalStyleCollection getConditionalStyles()
        
        Collection of conditional styles that may be defined for this table style.
      • getDocument

        public DocumentBase getDocument()
        
        Gets the owner document.
      • getFont

        public Font getFont()
        
        Gets the character formatting of the style.

        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

        public boolean isHeading()
        
        True when the style is one of the built-in Heading styles.
      • isQuickStyle/isQuickStyle

        public boolean isQuickStyle() / public void isQuickStyle(boolean value)
        
        Specifies whether this style is shown in the Quick Style gallery inside MS Word UI.
      • getLeftIndent/setLeftIndent

        public double getLeftIndent() / public void setLeftIndent(double value)
        
        Gets or sets the value that represents the left indent of a table.
      • getLeftPadding/setLeftPadding

        public double getLeftPadding() / public void setLeftPadding(double value)
        
        Gets or sets the amount of space (in points) to add to the left of the contents of table cells.
      • getLinkedStyleName

        public java.lang.String getLinkedStyleName()
        
        Gets the name of the Style linked to this one. Returns Empty string if no styles are linked.
      • 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.
        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

        public ListFormat getListFormat()
        
        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(getArtifactsDir() + "Lists.ParagraphStyleBulleted.doc");
      • getName/setName

        public java.lang.String getName() / public void setName(java.lang.String value)
        
        Gets or sets the name of the style.

        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:

        Shows how to get access to the collection of styles defined in the document.
        Document doc = new Document();
        StyleCollection styles = doc.getStyles();
        
        for (Style style : styles)
            System.out.println(style.getName());

        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");
      • getNextParagraphStyleName/setNextParagraphStyleName

        public java.lang.String getNextParagraphStyleName() / public 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. 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.
      • getParagraphFormat

        public ParagraphFormat getParagraphFormat()
        
        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(getArtifactsDir() + "Lists.ParagraphStyleBulleted.doc");
      • getRightPadding/setRightPadding

        public double getRightPadding() / public void setRightPadding(double value)
        
        Gets or sets the amount of space (in points) to add to the right of the contents of table cells.
      • getRowStripe/setRowStripe

        public int getRowStripe() / public void setRowStripe(int value)
        
        Gets or sets a number of rows to include in the banding when the style specifies odd/even row banding.
      • getShading

        public Shading getShading()
        
        Gets a Shading object that refers to the shading formatting for table cells.
      • 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.

        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");
        See Also:
        Name
      • getStyles

        public StyleCollection getStyles()
        
        Gets the collection of styles this style belongs to.
      • getTopPadding/setTopPadding

        public double getTopPadding() / public void setTopPadding(double value)
        
        Gets or sets the amount of space (in points) to add above the contents of table cells.
      • getType

        public int getType()
        
        Gets the style type (paragraph or character). The value of the property is StyleType integer constant.
    • Method Detail

      • clearCellAttrs

        public void clearCellAttrs()
      • fetchInheritedParaAttr

        @Deprecated
        public java.lang.Object fetchInheritedParaAttr(int key)
        Deprecated. Reserved for internal use.
      • fetchParaAttr

        @Deprecated
        public java.lang.Object fetchParaAttr(int key)
        Deprecated. Reserved for internal use.
      • remove

        public void remove()
        Removes the specified style from the document. Style removal has following effects on the document model:
        • All references to the style are removed from corresponding paragraphs, runs and tables.
        • If base style is removed its formatting is moved to child styles.
        • If style to be deleted has a linked style, then both of these are deleted.

        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();