java.lang.Objectcom.aspose.words.AutoFitBehavior
public class AutoFitBehavior
Example: Example: Example: Example: Example:
// Open the document
Document doc = new Document(dataDir + "TestFile.doc");
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
// Disable autofitting on this table.
table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
// Save the document to disk.
doc.save(dataDir + "TestFile.FixedWidth Out.doc");
// Open the document
Document doc = new Document(dataDir + "TestFile.doc");
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
// Autofit the first table to the page width.
table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW);
// Save the document to disk.
doc.save(dataDir + "TestFile.AutoFitToWindow Out.doc");
// Open the document
Document doc = new Document(dataDir + "TestFile.doc");
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
// Auto fit the table to the cell contents
table.autoFit(AutoFitBehavior.AUTO_FIT_TO_CONTENTS);
// Save the document to disk.
doc.save(dataDir + "TestFile.AutoFitToContents Out.doc");
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();
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() + "DocumentBuilder.SetTableStyle Out.docx");
Field Summary | ||
---|---|---|
static final int | AUTO_FIT_TO_CONTENTS | |
Aspose.Words enables the AutoFit option, removes the preferred width from the table and all cells and then updates the table layout. In the resulting table, cell widths are updated to fit the table contents. Most likely, the table will shrink. |
||
static final int | AUTO_FIT_TO_WINDOW | |
When you use this value, Aspose.Words enables the AutoFit option, sets the preferred width for the table to 100%, removes preferred widths from all cells and then updates the table layout. As a result, the table occupies all available width and the cell widths are updated to fit table contents. |
||
static final int | FIXED_COLUMN_WIDTHS | |
Aspose.Words disables the AutoFit option and removes the preferred with from the table. The widths of the cells remain as they are specified by their |
Field Detail |
---|
AUTO_FIT_TO_CONTENTS = 0 | |
public static final int AUTO_FIT_TO_CONTENTS |
Aspose.Words enables the AutoFit option, removes the preferred width from the table and all cells and then updates the table layout.
In the resulting table, cell widths are updated to fit the table contents. Most likely, the table will shrink.
AUTO_FIT_TO_WINDOW = 1 | |
public static final int AUTO_FIT_TO_WINDOW |
When you use this value, Aspose.Words enables the AutoFit option, sets the preferred width for the table to 100%, removes preferred widths from all cells and then updates the table layout.
As a result, the table occupies all available width and the cell widths are updated to fit table contents.
FIXED_COLUMN_WIDTHS = 2 | |
public static final int FIXED_COLUMN_WIDTHS |
Aspose.Words disables the AutoFit option and removes the preferred with from the table.
The widths of the cells remain as they are specified by their