com.aspose.words

Class AutoFitBehavior

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

Utility class containing constants. Determines how Aspose.Words resizes the table when you invoke the Table.autoFit(int) method.

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

Field Summary
static final intAUTO_FIT_TO_CONTENTS = 0

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 intAUTO_FIT_TO_WINDOW = 1

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 intFIXED_COLUMN_WIDTHS = 2

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 CellFormat.Width properties.

 

    • 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 CellFormat.Width properties.