java.lang.Objectcom.aspose.words.RowFormat
public class RowFormat
Example: Example: Example:
Document doc = new Document(getMyDir() + "Tables.docx");
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);
doc.save(getArtifactsDir() + "Table.RowFormat.docx");
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.insertCell();
builder.write("City");
builder.insertCell();
builder.write("Country");
builder.endRow();
builder.insertCell();
builder.write("London");
builder.insertCell();
builder.write("U.K.");
builder.endTable();
// The appearance of rows and individual cells can be edited using the respective formatting objects
RowFormat rowFormat = table.getFirstRow().getRowFormat();
rowFormat.setHeight(25.0);
rowFormat.getBorders().getByBorderType(BorderType.BOTTOM).setColor(Color.RED);
CellFormat cellFormat = table.getLastRow().getFirstCell().getCellFormat();
cellFormat.setWidth(100.0);
cellFormat.getShading().setBackgroundPatternColor(Color.ORANGE);
doc.save(getArtifactsDir() + "Table.RowCellFormat.docx");
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Start building a table
builder.startTable();
// Set the appropriate paragraph, cell, and row formatting. The formatting properties are preserved
// until they are explicitly modified so there's no need to set them for each row or cell
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.getCellFormat().clearFormatting();
builder.getCellFormat().setWidth(150.0);
builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN);
builder.getCellFormat().setWrapText(false);
builder.getCellFormat().setFitText(true);
builder.getRowFormat().clearFormatting();
builder.getRowFormat().setHeightRule(HeightRule.EXACTLY);
builder.getRowFormat().setHeight(50.0);
builder.getRowFormat().getBorders().setLineStyle(LineStyle.ENGRAVE_3_D);
builder.getRowFormat().getBorders().setColor(Color.ORANGE);
builder.insertCell();
builder.write("Row 1, Col 1");
builder.insertCell();
builder.write("Row 1, Col 2");
builder.endRow();
// Remove the shading (clear background)
builder.getCellFormat().getShading().clearFormatting();
builder.insertCell();
builder.write("Row 2, Col 1");
builder.insertCell();
builder.write("Row 2, Col 2");
builder.endRow();
builder.insertCell();
// Make the row height bigger so that a vertically oriented text could fit into cells
builder.getRowFormat().setHeight(150.0);
builder.getCellFormat().setOrientation(TextOrientation.UPWARD);
builder.write("Row 3, Col 1");
builder.insertCell();
builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD);
builder.write("Row 3, Col 2");
builder.endRow();
builder.endTable();
doc.save(getArtifactsDir() + "DocumentBuilder.InsertTable.docx");
Property Getters/Setters Summary | ||
---|---|---|
boolean | getAllowBreakAcrossPages() | |
void | setAllowBreakAcrossPages(boolean value) | |
True if the text in a table row is allowed to split across a page break. | ||
BorderCollection | getBorders() | |
Gets the collection of default cell borders for the row. | ||
boolean | getHeadingFormat() | |
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. | ||
double | getHeight() | |
void | setHeight(double value) | |
Gets or sets the height of the table row in points. | ||
int | getHeightRule() | |
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. |
Method Summary | ||
---|---|---|
void | clearFormatting() | |
Resets to default row formatting. |
Property Getters/Setters Detail |
---|
getAllowBreakAcrossPages/setAllowBreakAcrossPages | |
public boolean getAllowBreakAcrossPages() / public void setAllowBreakAcrossPages(boolean value) |
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 Document doc = new Document(getMyDir() + "Table spanning two pages.docx"); // Retrieve the first table in the document Table table = (Table) doc.getChild(NodeType.TABLE, 0, true); for (Row row : table) { row.getRowFormat().setAllowBreakAcrossPages(false); } doc.save(getArtifactsDir() + "Table.DisableBreakAcrossPages.docx");
getBorders | |
public BorderCollection getBorders() |
Example:
Shows how to build a nice bordered table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Start building a table builder.startTable(); // Set the appropriate paragraph, cell, and row formatting. The formatting properties are preserved // until they are explicitly modified so there's no need to set them for each row or cell builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER); builder.getCellFormat().clearFormatting(); builder.getCellFormat().setWidth(150.0); builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER); builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN); builder.getCellFormat().setWrapText(false); builder.getCellFormat().setFitText(true); builder.getRowFormat().clearFormatting(); builder.getRowFormat().setHeightRule(HeightRule.EXACTLY); builder.getRowFormat().setHeight(50.0); builder.getRowFormat().getBorders().setLineStyle(LineStyle.ENGRAVE_3_D); builder.getRowFormat().getBorders().setColor(Color.ORANGE); builder.insertCell(); builder.write("Row 1, Col 1"); builder.insertCell(); builder.write("Row 1, Col 2"); builder.endRow(); // Remove the shading (clear background) builder.getCellFormat().getShading().clearFormatting(); builder.insertCell(); builder.write("Row 2, Col 1"); builder.insertCell(); builder.write("Row 2, Col 2"); builder.endRow(); builder.insertCell(); // Make the row height bigger so that a vertically oriented text could fit into cells builder.getRowFormat().setHeight(150.0); builder.getCellFormat().setOrientation(TextOrientation.UPWARD); builder.write("Row 3, Col 1"); builder.insertCell(); builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD); builder.write("Row 3, Col 2"); builder.endRow(); builder.endTable(); doc.save(getArtifactsDir() + "DocumentBuilder.InsertTable.docx");
getHeadingFormat/setHeadingFormat | |
public boolean getHeadingFormat() / public void setHeadingFormat(boolean value) |
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); builder.startTable(); builder.getRowFormat().setHeadingFormat(true); builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER); builder.getCellFormat().setWidth(100.0); builder.insertCell(); builder.writeln("Heading row 1"); builder.endRow(); builder.insertCell(); builder.writeln("Heading row 2"); builder.endRow(); builder.getCellFormat().setWidth(50.0); 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(getArtifactsDir() + "DocumentBuilder.InsertTableSetHeadingRow.docx");
getHeight/setHeight | |
public double getHeight() / public void setHeight(double value) |
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.0); rowFormat.setHeightRule(HeightRule.EXACTLY); // These formatting properties are set on the table and are applied to all rows in the table table.setLeftPadding(30.0); table.setRightPadding(30.0); table.setTopPadding(30.0); table.setBottomPadding(30.0); builder.writeln("Contents of formatted row."); builder.endRow(); builder.endTable(); doc.save(getArtifactsDir() + "DocumentBuilder.DocumentBuilderSetRowFormatting.docx");
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(getArtifactsDir() + "DocumentBuilder.CreateFormattedTable.docx");
getHeightRule/setHeightRule | |
public int getHeightRule() / public void setHeightRule(int value) |
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.0); rowFormat.setHeightRule(HeightRule.EXACTLY); // These formatting properties are set on the table and are applied to all rows in the table table.setLeftPadding(30.0); table.setRightPadding(30.0); table.setTopPadding(30.0); table.setBottomPadding(30.0); builder.writeln("Contents of formatted row."); builder.endRow(); builder.endTable(); doc.save(getArtifactsDir() + "DocumentBuilder.DocumentBuilderSetRowFormatting.docx");
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(getArtifactsDir() + "DocumentBuilder.CreateFormattedTable.docx");
Method Detail |
---|
clearFormatting | |
public void clearFormatting() throws java.lang.Exception |
Example:
Shows how to build a nice bordered table.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Start building a table builder.startTable(); // Set the appropriate paragraph, cell, and row formatting. The formatting properties are preserved // until they are explicitly modified so there's no need to set them for each row or cell builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER); builder.getCellFormat().clearFormatting(); builder.getCellFormat().setWidth(150.0); builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER); builder.getCellFormat().getShading().setBackgroundPatternColor(Color.GREEN); builder.getCellFormat().setWrapText(false); builder.getCellFormat().setFitText(true); builder.getRowFormat().clearFormatting(); builder.getRowFormat().setHeightRule(HeightRule.EXACTLY); builder.getRowFormat().setHeight(50.0); builder.getRowFormat().getBorders().setLineStyle(LineStyle.ENGRAVE_3_D); builder.getRowFormat().getBorders().setColor(Color.ORANGE); builder.insertCell(); builder.write("Row 1, Col 1"); builder.insertCell(); builder.write("Row 1, Col 2"); builder.endRow(); // Remove the shading (clear background) builder.getCellFormat().getShading().clearFormatting(); builder.insertCell(); builder.write("Row 2, Col 1"); builder.insertCell(); builder.write("Row 2, Col 2"); builder.endRow(); builder.insertCell(); // Make the row height bigger so that a vertically oriented text could fit into cells builder.getRowFormat().setHeight(150.0); builder.getCellFormat().setOrientation(TextOrientation.UPWARD); builder.write("Row 3, Col 1"); builder.insertCell(); builder.getCellFormat().setOrientation(TextOrientation.DOWNWARD); builder.write("Row 3, Col 2"); builder.endRow(); builder.endTable(); doc.save(getArtifactsDir() + "DocumentBuilder.InsertTable.docx");