com.aspose.words

Class TextColumnCollection

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

A collection of TextColumn objects that represent all the columns of text in a section of a document.

Use setCount(int) to set the number of text columns.

To make all columns equal width and spaced evenly, set EvenlySpaced to true and specify the amount of space between the columns in Spacing. MS Word will automatically calculate column widths.

If you have EvenlySpaced set to false, you need to specify width and spacing for each column individually. Use the indexer to access individual TextColumn objects.

When using custom column widths, make sure the sum of all column widths and spacings between them equals page width minus left and right page margins.

Example:

Shows how to create multiple evenly spaced columns in a section using DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

TextColumnCollection columns = builder.getPageSetup().getTextColumns();
// Make spacing between columns wider
columns.setSpacing(100.0);
// This creates two columns of equal width
columns.setCount(2);

builder.writeln("Text in column 1.");
builder.insertBreak(BreakType.COLUMN_BREAK);
builder.writeln("Text in column 2.");

doc.save(getArtifactsDir() + "PageSetup.ColumnsSameWidth.docx");
See Also:
PageSetup, Section

Property Getters/Setters Summary
intgetCount()
Gets the number of columns in the section of a document.
booleangetEvenlySpaced()
void
setEvenlySpaced(booleanvalue)
          True if text columns are of equal width and evenly spaced.
booleangetLineBetween()
void
setLineBetween(booleanvalue)
           When true, adds a vertical line between columns.
doublegetSpacing()
void
setSpacing(doublevalue)
           When columns are evenly spaced, gets or sets the amount of space between each column in points.
doublegetWidth()
When columns are evenly spaced, gets the width of the columns.
TextColumnget(int index)
Returns a text column at the specified index.
 
Method Summary
voidsetCount(int newCount)
Arranges text into the specified number of text columns.
 

    • Property Getters/Setters Detail

      • getCount

        public int getCount()
        
        Gets the number of columns in the section of a document.
      • getEvenlySpaced/setEvenlySpaced

        public boolean getEvenlySpaced() / public void setEvenlySpaced(boolean value)
        
        True if text columns are of equal width and evenly spaced.

        Example:

        Shows how to set widths of columns.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        TextColumnCollection columns = builder.getPageSetup().getTextColumns();
        // Show vertical line between columns
        columns.setLineBetween(true);
        // Indicate we want to create column with different widths
        columns.setEvenlySpaced(false);
        // Create two columns, note they will be created with zero widths, need to set them
        columns.setCount(2);
        
        // Set the first column to be narrow
        TextColumn column = columns.get(0);
        column.setWidth(100.0);
        column.setSpaceAfter(20.0);
        
        // Set the second column to take the rest of the space available on the page
        column = columns.get(1);
        PageSetup pageSetup = builder.getPageSetup();
        double contentWidth = pageSetup.getPageWidth() - pageSetup.getLeftMargin() - pageSetup.getRightMargin();
        column.setWidth(contentWidth - column.getWidth() - column.getSpaceAfter());
        
        builder.writeln("Narrow column 1.");
        builder.insertBreak(BreakType.COLUMN_BREAK);
        builder.writeln("Wide column 2.");
        
        doc.save(getArtifactsDir() + "PageSetup.CustomColumnWidth.docx");
      • getLineBetween/setLineBetween

        public boolean getLineBetween() / public void setLineBetween(boolean value)
        
        When true, adds a vertical line between columns.

        Example:

        Shows how to set widths of columns.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        TextColumnCollection columns = builder.getPageSetup().getTextColumns();
        // Show vertical line between columns
        columns.setLineBetween(true);
        // Indicate we want to create column with different widths
        columns.setEvenlySpaced(false);
        // Create two columns, note they will be created with zero widths, need to set them
        columns.setCount(2);
        
        // Set the first column to be narrow
        TextColumn column = columns.get(0);
        column.setWidth(100.0);
        column.setSpaceAfter(20.0);
        
        // Set the second column to take the rest of the space available on the page
        column = columns.get(1);
        PageSetup pageSetup = builder.getPageSetup();
        double contentWidth = pageSetup.getPageWidth() - pageSetup.getLeftMargin() - pageSetup.getRightMargin();
        column.setWidth(contentWidth - column.getWidth() - column.getSpaceAfter());
        
        builder.writeln("Narrow column 1.");
        builder.insertBreak(BreakType.COLUMN_BREAK);
        builder.writeln("Wide column 2.");
        
        doc.save(getArtifactsDir() + "PageSetup.CustomColumnWidth.docx");
      • getSpacing/setSpacing

        public double getSpacing() / public void setSpacing(double value)
        
        When columns are evenly spaced, gets or sets the amount of space between each column in points. Has effect only when EvenlySpaced is set to true.

        Example:

        Shows how to create multiple evenly spaced columns in a section using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        TextColumnCollection columns = builder.getPageSetup().getTextColumns();
        // Make spacing between columns wider
        columns.setSpacing(100.0);
        // This creates two columns of equal width
        columns.setCount(2);
        
        builder.writeln("Text in column 1.");
        builder.insertBreak(BreakType.COLUMN_BREAK);
        builder.writeln("Text in column 2.");
        
        doc.save(getArtifactsDir() + "PageSetup.ColumnsSameWidth.docx");
      • getWidth

        public double getWidth()
        
        When columns are evenly spaced, gets the width of the columns.

        Has effect only when EvenlySpaced is set to true.

      • get

        public TextColumn get(int index)
        
        Returns a text column at the specified index.

        Example:

        Shows how to set widths of columns.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        TextColumnCollection columns = builder.getPageSetup().getTextColumns();
        // Show vertical line between columns
        columns.setLineBetween(true);
        // Indicate we want to create column with different widths
        columns.setEvenlySpaced(false);
        // Create two columns, note they will be created with zero widths, need to set them
        columns.setCount(2);
        
        // Set the first column to be narrow
        TextColumn column = columns.get(0);
        column.setWidth(100.0);
        column.setSpaceAfter(20.0);
        
        // Set the second column to take the rest of the space available on the page
        column = columns.get(1);
        PageSetup pageSetup = builder.getPageSetup();
        double contentWidth = pageSetup.getPageWidth() - pageSetup.getLeftMargin() - pageSetup.getRightMargin();
        column.setWidth(contentWidth - column.getWidth() - column.getSpaceAfter());
        
        builder.writeln("Narrow column 1.");
        builder.insertBreak(BreakType.COLUMN_BREAK);
        builder.writeln("Wide column 2.");
        
        doc.save(getArtifactsDir() + "PageSetup.CustomColumnWidth.docx");
    • Method Detail

      • setCount

        public void setCount(int newCount)
        Arranges text into the specified number of text columns.

        When EvenlySpaced is false and you increase the number of columns, new TextColumn objects are created with zero width and spacing. You need to set width and spacing for the new columns.

        Parameters:
        newCount - The number of columns the text is to be arranged into.

        Example:

        Shows how to create multiple evenly spaced columns in a section using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        TextColumnCollection columns = builder.getPageSetup().getTextColumns();
        // Make spacing between columns wider
        columns.setSpacing(100.0);
        // This creates two columns of equal width
        columns.setCount(2);
        
        builder.writeln("Text in column 1.");
        builder.insertBreak(BreakType.COLUMN_BREAK);
        builder.writeln("Text in column 2.");
        
        doc.save(getArtifactsDir() + "PageSetup.ColumnsSameWidth.docx");