com.aspose.words
Class RowFormat

java.lang.Object
    extended by com.aspose.words.RowFormat

public class RowFormat 
extends java.lang.Object

Represents all formatting for a table row.

Example:

Shows how to modify formatting of a table row.
Document doc = new Document(getMyDir() + "Table.Document.doc");
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);

// Retrieve the first row in the table.
Row firstRow = table.getFirstRow();

// Modify some row level properties.
firstRow.getRowFormat().getBorders().setLineStyle(LineStyle.NONE);
firstRow.getRowFormat().setHeightRule(HeightRule.AUTO);
firstRow.getRowFormat().setAllowBreakAcrossPages(true);

Example:

Shows how to insert a table using the constructors of nodes.
Document doc = new Document();

// We start by creating the table object. Note how we must pass the document object
// to the constructor of each node. This is because every node we create must belong
// to some document.
Table table = new Table(doc);
// Add the table to the document.
doc.getFirstSection().getBody().appendChild(table);

// Here we could call EnsureMinimum to create the rows and cells for us. This method is used
// to ensure that the specified node is valid, in this case a valid table should have at least one
// row and one cell, therefore this method creates them for us.

// Instead we will handle creating the row and table ourselves. This would be the best way to do this
// if we were creating a table inside an algorthim for example.
Row row = new Row(doc);
row.getRowFormat().setAllowBreakAcrossPages(true);
table.appendChild(row);

// We can now apply any auto fit settings.
table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);

// Create a cell and add it to the row
Cell cell = new Cell(doc);
cell.getCellFormat().getShading().setBackgroundPatternColor(Color.BLUE);
cell.getCellFormat().setWidth(80);

// Add a paragraph to the cell as well as a new run with some text.
cell.appendChild(new Paragraph(doc));
cell.getFirstParagraph().appendChild(new Run(doc, "Row 1, Cell 1 Text"));

// Add the cell to the row.
row.appendChild(cell);

// We would then repeat the process for the other cells and rows in the table.
// We can also speed things up by cloning existing cells and rows.
row.appendChild(cell.deepClone(false));
row.getLastCell().appendChild(new Paragraph(doc));
row.getLastCell().getFirstParagraph().appendChild(new Run(doc, "Row 1, Cell 2 Text"));

doc.save(getMyDir() + "Table.InsertTableUsingNodes Out.doc");

Property Getters/Setters Summary
intgetAlignment()
voidsetAlignment(int value)
           Gets or sets a value that represents the alignment for the row. The value of the property is RowAlignment integer constant.
booleangetAllowAutoFit()
voidsetAllowAutoFit(boolean value)
           Allows Microsoft Word to automatically resize cells in a table to fit their contents.
booleangetAllowBreakAcrossPages()
voidsetAllowBreakAcrossPages(boolean value)
           True if the text in a table row is allowed to split across a page break.
booleangetBidi()
voidsetBidi(boolean value)
           Gets or sets whether this is a right-to-left table.
BorderCollectiongetBorders()
           Gets the collection of default cell borders for the row.
doublegetBottomPadding()
voidsetBottomPadding(double value)
           Gets or sets the amount of space (in points) to add below the contents of cells.
doublegetCellSpacing()
voidsetCellSpacing(double value)
           Gets or sets the amount of space (in points) between the cells.
booleangetHeadingFormat()
voidsetHeadingFormat(boolean value)
           True if the row is repeated as a table heading on every page when the table spans more than one page.
doublegetHeight()
voidsetHeight(double value)
           Gets or sets the height of the table row in points.
intgetHeightRule()
voidsetHeightRule(int value)
           Gets or sets the rule for determining the height of the table row. The value of the property is HeightRule integer constant.
doublegetLeftIndent()
voidsetLeftIndent(double value)
           Gets or sets the value that represents the left indent of the table row.
doublegetLeftPadding()
voidsetLeftPadding(double value)
           Gets or sets the amount of space (in points) to add to the left of the contents of cells.
PreferredWidthgetPreferredWidth()
voidsetPreferredWidth(PreferredWidth value)
           Gets or sets the preferred table width.
doublegetRightPadding()
voidsetRightPadding(double value)
           Gets or sets the amount of space (in points) to add to the right of the contents of cells.
doublegetTopPadding()
voidsetTopPadding(double value)
           Gets or sets the amount of space (in points) to add above the contents of cells.
 
Method Summary
voidclearCellPadding()
           Sets default cell margins (padding) to zero.
voidclearFormatting()
           Resets to default row formatting.
 

Property Getters/Setters Detail

getAlignment/setAlignment

public int getAlignment() / public void setAlignment(int value)
Gets or sets a value that represents the alignment for the row. The value of the property is RowAlignment integer constant.

getAllowAutoFit/setAllowAutoFit

public boolean getAllowAutoFit() / public void setAllowAutoFit(boolean value)
Allows Microsoft Word to automatically resize cells in a table to fit their contents.

getAllowBreakAcrossPages/setAllowBreakAcrossPages

public boolean getAllowBreakAcrossPages() / public void setAllowBreakAcrossPages(boolean value)
True if the text in a table row is allowed to split across a page break.

Example:

Shows how to disable rows breaking across pages for every row in a table.
// Disable breaking across pages for all rows in the table.
for(Row row : table)
    row.getRowFormat().setAllowBreakAcrossPages(false);

getBidi/setBidi

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

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


getBorders

public BorderCollection getBorders()
Gets the collection of default cell borders for the row.

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 cells.

getCellSpacing/setCellSpacing

public double getCellSpacing() / public void setCellSpacing(double value)
Gets or sets the amount of space (in points) between the cells.

getHeadingFormat/setHeadingFormat

public boolean getHeadingFormat() / public void setHeadingFormat(boolean value)
True if the row is repeated as a table heading on every page when the table spans more than one page.

Example:

Shows how to build a table which include heading rows that repeat on subsequent pages.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.startTable();
builder.getRowFormat().setHeadingFormat(true);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.getCellFormat().setWidth(100);
builder.insertCell();
builder.writeln("Heading row 1");
builder.endRow();
builder.insertCell();
builder.writeln("Heading row 2");
builder.endRow();

builder.getCellFormat().setWidth(50);
builder.getParagraphFormat().clearFormatting();

// Insert some content so the table is long enough to continue onto the next page.
for (int i = 0; i < 50; i++)
{
    builder.insertCell();
    builder.getRowFormat().setHeadingFormat(false);
    builder.write("Column 1 Text");
    builder.insertCell();
    builder.write("Column 2 Text");
    builder.endRow();
}

doc.save(getMyDir() + "Table.HeadingRow Out.doc");

getHeight/setHeight

public double getHeight() / public void setHeight(double value)
Gets or sets the height of the table row in points.

Example:

Shows how to create a table that contains a single cell and apply row formatting.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.startTable();
builder.insertCell();

// Set the row formatting
RowFormat rowFormat = builder.getRowFormat();
rowFormat.setHeight(100);
rowFormat.setHeightRule(HeightRule.EXACTLY);
// These formatting properties are set on the table and are applied to all rows in the table.
table.setLeftPadding(30);
table.setRightPadding(30);
table.setTopPadding(30);
table.setBottomPadding(30);

builder.writeln("I'm a wonderful formatted row.");

builder.endRow();
builder.endTable();

Example:

Shows how to build a formatted table that contains 2 rows and 2 columns.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.startTable();

// Insert a cell
builder.insertCell();
// Use fixed column widths.
table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);

builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
builder.write("This is row 1 cell 1");

// Insert a cell
builder.insertCell();
builder.write("This is row 1 cell 2");

builder.endRow();

// Insert a cell
builder.insertCell();

// Apply new row formatting
builder.getRowFormat().setHeight(100);
builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);

builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
builder.writeln("This is row 2 cell 1");

// Insert a cell
builder.insertCell();
builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
builder.writeln("This is row 2 cell 2");

builder.endRow();

builder.endTable();

Example:

Shows how to create a formatted table using DocumentBuilder
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.startTable();

// Make the header row.
builder.insertCell();

// Set the left indent for the table. Table wide formatting must be applied after
// at least one row is present in the table.
table.setLeftIndent(20.0);

// Set height and define the height rule for the header row.
builder.getRowFormat().setHeight(40.0);
builder.getRowFormat().setHeightRule(HeightRule.AT_LEAST);

// Some special features for the header row.
builder.getCellFormat().getShading().setBackgroundPatternColor(new Color(198, 217, 241));
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.getFont().setSize(16);
builder.getFont().setName("Arial");
builder.getFont().setBold (true);

builder.getCellFormat().setWidth(100.0);
builder.write("Header Row,\n Cell 1");

// We don't need to specify the width of this cell because it's inherited from the previous cell.
builder.insertCell();
builder.write("Header Row,\n Cell 2");

builder.insertCell();
builder.getCellFormat().setWidth(200.0);
builder.write("Header Row,\n Cell 3");
builder.endRow();

// Set features for the other rows and cells.
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
builder.getCellFormat().setWidth(100.0);
builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);

// Reset height and define a different height rule for table body
builder.getRowFormat().setHeight(30.0);
builder.getRowFormat().setHeightRule(HeightRule.AUTO);
builder.insertCell();
// Reset font formatting.
builder.getFont().setSize(12);
builder.getFont().setBold(false);

// Build the other cells.
builder.write("Row 1, Cell 1 Content");
builder.insertCell();
builder.write("Row 1, Cell 2 Content");

builder.insertCell();
builder.getCellFormat().setWidth(200.0);
builder.write("Row 1, Cell 3 Content");
builder.endRow();

builder.insertCell();
builder.getCellFormat().setWidth(100.0);
builder.write("Row 2, Cell 1 Content");

builder.insertCell();
builder.write("Row 2, Cell 2 Content");

builder.insertCell();
builder.getCellFormat().setWidth(200.0);
builder.write("Row 2, Cell 3 Content.");
builder.endRow();
builder.endTable();

doc.save(getMyDir() + "DocumentBuilder.CreateFormattedTable Out.doc");

getHeightRule/setHeightRule

public int getHeightRule() / public void setHeightRule(int value)
Gets or sets the rule for determining the height of the table row. The value of the property is HeightRule integer constant.

Example:

Shows how to create a table that contains a single cell and apply row formatting.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.startTable();
builder.insertCell();

// Set the row formatting
RowFormat rowFormat = builder.getRowFormat();
rowFormat.setHeight(100);
rowFormat.setHeightRule(HeightRule.EXACTLY);
// These formatting properties are set on the table and are applied to all rows in the table.
table.setLeftPadding(30);
table.setRightPadding(30);
table.setTopPadding(30);
table.setBottomPadding(30);

builder.writeln("I'm a wonderful formatted row.");

builder.endRow();
builder.endTable();

Example:

Shows how to build a formatted table that contains 2 rows and 2 columns.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.startTable();

// Insert a cell
builder.insertCell();
// Use fixed column widths.
table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);

builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
builder.write("This is row 1 cell 1");

// Insert a cell
builder.insertCell();
builder.write("This is row 1 cell 2");

builder.endRow();

// Insert a cell
builder.insertCell();

// Apply new row formatting
builder.getRowFormat().setHeight(100);
builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);

builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
builder.writeln("This is row 2 cell 1");

// Insert a cell
builder.insertCell();
builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
builder.writeln("This is row 2 cell 2");

builder.endRow();

builder.endTable();

Example:

Shows how to create a formatted table using DocumentBuilder
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.startTable();

// Make the header row.
builder.insertCell();

// Set the left indent for the table. Table wide formatting must be applied after
// at least one row is present in the table.
table.setLeftIndent(20.0);

// Set height and define the height rule for the header row.
builder.getRowFormat().setHeight(40.0);
builder.getRowFormat().setHeightRule(HeightRule.AT_LEAST);

// Some special features for the header row.
builder.getCellFormat().getShading().setBackgroundPatternColor(new Color(198, 217, 241));
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.getFont().setSize(16);
builder.getFont().setName("Arial");
builder.getFont().setBold (true);

builder.getCellFormat().setWidth(100.0);
builder.write("Header Row,\n Cell 1");

// We don't need to specify the width of this cell because it's inherited from the previous cell.
builder.insertCell();
builder.write("Header Row,\n Cell 2");

builder.insertCell();
builder.getCellFormat().setWidth(200.0);
builder.write("Header Row,\n Cell 3");
builder.endRow();

// Set features for the other rows and cells.
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.WHITE);
builder.getCellFormat().setWidth(100.0);
builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);

// Reset height and define a different height rule for table body
builder.getRowFormat().setHeight(30.0);
builder.getRowFormat().setHeightRule(HeightRule.AUTO);
builder.insertCell();
// Reset font formatting.
builder.getFont().setSize(12);
builder.getFont().setBold(false);

// Build the other cells.
builder.write("Row 1, Cell 1 Content");
builder.insertCell();
builder.write("Row 1, Cell 2 Content");

builder.insertCell();
builder.getCellFormat().setWidth(200.0);
builder.write("Row 1, Cell 3 Content");
builder.endRow();

builder.insertCell();
builder.getCellFormat().setWidth(100.0);
builder.write("Row 2, Cell 1 Content");

builder.insertCell();
builder.write("Row 2, Cell 2 Content");

builder.insertCell();
builder.getCellFormat().setWidth(200.0);
builder.write("Row 2, Cell 3 Content.");
builder.endRow();
builder.endTable();

doc.save(getMyDir() + "DocumentBuilder.CreateFormattedTable Out.doc");

getLeftIndent/setLeftIndent

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

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 cells.

getPreferredWidth/setPreferredWidth

public PreferredWidth getPreferredWidth() / public void setPreferredWidth(PreferredWidth value)
Gets or sets the preferred table width.

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 cells.

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 cells.

Method Detail

clearCellPadding

public void clearCellPadding()
Sets default cell margins (padding) to zero.

clearFormatting

public void clearFormatting()
                    throws java.lang.Exception
Resets to default row formatting.

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.