search/mag_sel search/close
Aspose::Words::TextColumnCollection Class Reference

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

Use SetCount() 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.

See also
Aspose::Words::PageSetup
Aspose::Words::Section
Examples

Shows how to create multiple evenly spaced columns in a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<TextColumnCollection> columns = builder->get_PageSetup()->get_TextColumns();
columns->set_Spacing(100);
columns->SetCount(2);
builder->Writeln(u"Column 1.");
builder->InsertBreak(BreakType::ColumnBreak);
builder->Writeln(u"Column 2.");
doc->Save(ArtifactsDir + u"PageSetup.ColumnsSameWidth.docx");

#include <Aspose.Words.Cpp/TextColumnCollection.h>

+ Inheritance diagram for Aspose::Words::TextColumnCollection:

Public Member Functions

int32_t get_Count ()
 Gets the number of columns in the section of a document. More...
 
bool get_EvenlySpaced ()
 True if text columns are of equal width and evenly spaced. More...
 
bool get_LineBetween ()
 When true, adds a vertical line between columns. More...
 
double get_Spacing ()
 When columns are evenly spaced, gets or sets the amount of space between each column in points. More...
 
double get_Width ()
 When columns are evenly spaced, gets the width of the columns. More...
 
virtual const TypeInfoGetType () const override
 
SharedPtr< TextColumnidx_get (int32_t index)
 Returns a text column at the specified index. More...
 
virtual bool Is (const TypeInfo &target) const override
 
void set_EvenlySpaced (bool value)
 Setter for get_EvenlySpaced. More...
 
void set_LineBetween (bool value)
 Setter for get_LineBetween. More...
 
void set_Spacing (double value)
 Setter for get_Spacing. More...
 
void SetCount (int32_t newCount)
 Arranges text into the specified number of text columns. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ get_Count()

int32_t Aspose::Words::TextColumnCollection::get_Count ( )

Gets the number of columns in the section of a document.

◆ get_EvenlySpaced()

bool Aspose::Words::TextColumnCollection::get_EvenlySpaced ( )

True if text columns are of equal width and evenly spaced.

Examples

Shows how to create unevenly spaced columns.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<PageSetup> pageSetup = builder->get_PageSetup();
SharedPtr<TextColumnCollection> columns = pageSetup->get_TextColumns();
columns->set_EvenlySpaced(false);
columns->SetCount(2);
// Determine the amount of room that we have available for arranging columns.
double contentWidth = pageSetup->get_PageWidth() - pageSetup->get_LeftMargin() - pageSetup->get_RightMargin();
ASSERT_NEAR(470.30, contentWidth, 0.01);
// Set the first column to be narrow.
SharedPtr<TextColumn> column = columns->idx_get(0);
column->set_Width(100);
column->set_SpaceAfter(20);
// Set the second column to take the rest of the space available within the margins of the page.
column = columns->idx_get(1);
column->set_Width(contentWidth - column->get_Width() - column->get_SpaceAfter());
builder->Writeln(u"Narrow column 1.");
builder->InsertBreak(BreakType::ColumnBreak);
builder->Writeln(u"Wide column 2.");
doc->Save(ArtifactsDir + u"PageSetup.CustomColumnWidth.docx");

◆ get_LineBetween()

bool Aspose::Words::TextColumnCollection::get_LineBetween ( )

When true, adds a vertical line between columns.

Examples

Shows how to separate columns with a vertical line.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Configure the current section's PageSetup object to divide the text into several columns.
// Set the "LineBetween" property to "true" to put a dividing line between columns.
// Set the "LineBetween" property to "false" to leave the space between columns blank.
SharedPtr<TextColumnCollection> columns = builder->get_PageSetup()->get_TextColumns();
columns->set_LineBetween(lineBetween);
columns->SetCount(3);
builder->Writeln(u"Column 1.");
builder->InsertBreak(BreakType::ColumnBreak);
builder->Writeln(u"Column 2.");
builder->InsertBreak(BreakType::ColumnBreak);
builder->Writeln(u"Column 3.");
doc->Save(ArtifactsDir + u"PageSetup.VerticalLineBetweenColumns.docx");

◆ get_Spacing()

double Aspose::Words::TextColumnCollection::get_Spacing ( )

When columns are evenly spaced, gets or sets the amount of space between each column in points.

Examples

Shows how to create multiple evenly spaced columns in a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<TextColumnCollection> columns = builder->get_PageSetup()->get_TextColumns();
columns->set_Spacing(100);
columns->SetCount(2);
builder->Writeln(u"Column 1.");
builder->InsertBreak(BreakType::ColumnBreak);
builder->Writeln(u"Column 2.");
doc->Save(ArtifactsDir + u"PageSetup.ColumnsSameWidth.docx");

◆ get_Width()

double Aspose::Words::TextColumnCollection::get_Width ( )

When columns are evenly spaced, gets the width of the columns.

Has effect only when EvenlySpaced is set to true.

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::TextColumnCollection::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ idx_get()

System::SharedPtr<Aspose::Words::TextColumn> Aspose::Words::TextColumnCollection::idx_get ( int32_t  index)

Returns a text column at the specified index.

Examples

Shows how to create unevenly spaced columns.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<PageSetup> pageSetup = builder->get_PageSetup();
SharedPtr<TextColumnCollection> columns = pageSetup->get_TextColumns();
columns->set_EvenlySpaced(false);
columns->SetCount(2);
// Determine the amount of room that we have available for arranging columns.
double contentWidth = pageSetup->get_PageWidth() - pageSetup->get_LeftMargin() - pageSetup->get_RightMargin();
ASSERT_NEAR(470.30, contentWidth, 0.01);
// Set the first column to be narrow.
SharedPtr<TextColumn> column = columns->idx_get(0);
column->set_Width(100);
column->set_SpaceAfter(20);
// Set the second column to take the rest of the space available within the margins of the page.
column = columns->idx_get(1);
column->set_Width(contentWidth - column->get_Width() - column->get_SpaceAfter());
builder->Writeln(u"Narrow column 1.");
builder->InsertBreak(BreakType::ColumnBreak);
builder->Writeln(u"Wide column 2.");
doc->Save(ArtifactsDir + u"PageSetup.CustomColumnWidth.docx");

◆ Is()

virtual bool Aspose::Words::TextColumnCollection::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ set_EvenlySpaced()

void Aspose::Words::TextColumnCollection::set_EvenlySpaced ( bool  value)

◆ set_LineBetween()

void Aspose::Words::TextColumnCollection::set_LineBetween ( bool  value)

◆ set_Spacing()

void Aspose::Words::TextColumnCollection::set_Spacing ( double  value)

◆ SetCount()

void Aspose::Words::TextColumnCollection::SetCount ( int32_t  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
newCountThe number of columns the text is to be arranged into.
Examples

Shows how to create multiple evenly spaced columns in a section.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<TextColumnCollection> columns = builder->get_PageSetup()->get_TextColumns();
columns->set_Spacing(100);
columns->SetCount(2);
builder->Writeln(u"Column 1.");
builder->InsertBreak(BreakType::ColumnBreak);
builder->Writeln(u"Column 2.");
doc->Save(ArtifactsDir + u"PageSetup.ColumnsSameWidth.docx");

◆ Type()

static const System::TypeInfo& Aspose::Words::TextColumnCollection::Type ( )
static