com.aspose.words

Class TableStyleOptions

  • java.lang.Object
    • com.aspose.words.TableStyleOptions
public class TableStyleOptions 
extends java.lang.Object

Utility class containing constants. Specifies how table style is applied to a table.

Example:

Shows how to import the data from a DataTable and insert it into a new table in the document.
// Create a new document.
Document doc = new Document();

// We can position where we want the table to be inserted and also specify any extra formatting to be
// applied onto the table as well.
DocumentBuilder builder = new DocumentBuilder(doc);

// We want to rotate the page landscape as we expect a wide table.
doc.getFirstSection().getPageSetup().setOrientation(Orientation.LANDSCAPE);

// Retrieve the data from our data source which is stored as a DataTable.
DataTable dataTable = getEmployees(databaseDir);

// Build a table in the document from the data contained in the DataTable.
Table table = importTableFromDataTable(builder, dataTable, true);

// We can apply a table style as a very quick way to apply formatting to the entire table.
table.setStyleIdentifier(StyleIdentifier.MEDIUM_LIST_2_ACCENT_1);
table.setStyleOptions(TableStyleOptions.FIRST_ROW | TableStyleOptions.ROW_BANDS | TableStyleOptions.LAST_COLUMN);

// For our table we want to remove the heading for the image column.
table.getFirstRow().getLastCell().removeAllChildren();

doc.save(dataDir + "Table.FromDataTable Out.docx");

Example:

Shows how to build a new table with a table style applied.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.startTable();
// We must insert at least one row first before setting any table formatting.
builder.insertCell();
// Set the table style used based of the unique style identifier.
// Note that not all table styles are available when saving as .doc format.
table.setStyleIdentifier(StyleIdentifier.MEDIUM_SHADING_1_ACCENT_1);
// Apply which features should be formatted by the style.
table.setStyleOptions(TableStyleOptions.FIRST_COLUMN | TableStyleOptions.ROW_BANDS | TableStyleOptions.FIRST_ROW);
table.autoFit(AutoFitBehavior.AUTO_FIT_TO_CONTENTS);

// Continue with building the table as normal.
builder.writeln("Item");
builder.getCellFormat().setRightPadding(40);
builder.insertCell();
builder.writeln("Quantity (kg)");
builder.endRow();

builder.insertCell();
builder.writeln("Apples");
builder.insertCell();
builder.writeln("20");
builder.endRow();

builder.insertCell();
builder.writeln("Bananas");
builder.insertCell();
builder.writeln("40");
builder.endRow();

builder.insertCell();
builder.writeln("Carrots");
builder.insertCell();
builder.writeln("50");
builder.endRow();

doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.SetTableStyle.docx");
See Also:
Table.StyleOptions

Field Summary
static final intNONE = 0
No table style formatting is applied.
static final intFIRST_ROW = 32
Apply first row conditional formatting.
static final intLAST_ROW = 64
Apply last row conditional formatting.
static final intFIRST_COLUMN = 128
Apply 1 first column conditional formatting.
static final intLAST_COLUMN = 256
Apply last column conditional formatting.
static final intROW_BANDS = 512
Apply row banding conditional formatting.
static final intCOLUMN_BANDS = 1024
Apply column banding conditional formatting.
static final intDEFAULT_2003 = 1536
Row and column banding is applied. This is Microsoft Word default for old formats such as DOC, WML and RTF.
static final intDEFAULT = 672
This is Microsoft Word defaults.
 

    • Field Detail

      • NONE = 0

        public static final int NONE
        No table style formatting is applied.
      • FIRST_ROW = 32

        public static final int FIRST_ROW
        Apply first row conditional formatting.
      • LAST_ROW = 64

        public static final int LAST_ROW
        Apply last row conditional formatting.
      • FIRST_COLUMN = 128

        public static final int FIRST_COLUMN
        Apply 1 first column conditional formatting.
      • LAST_COLUMN = 256

        public static final int LAST_COLUMN
        Apply last column conditional formatting.
      • ROW_BANDS = 512

        public static final int ROW_BANDS
        Apply row banding conditional formatting.
      • COLUMN_BANDS = 1024

        public static final int COLUMN_BANDS
        Apply column banding conditional formatting.
      • DEFAULT_2003 = 1536

        public static final int DEFAULT_2003
        Row and column banding is applied. This is Microsoft Word default for old formats such as DOC, WML and RTF.
      • DEFAULT = 672

        public static final int DEFAULT
        This is Microsoft Word defaults.