Aspose::Words::Tables::Table Class Reference

Detailed Description

Represents a table in a Word document.

Table is a block-level node and can be a child of classes derived from Story or InlineStory.

Table can contain one or more Row nodes.

A minimal valid table needs to have at least one Row.

Examples

Shows how to build a formatted table that contains 2 rows and 2 columns.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
// Insert a cell
builder->InsertCell();
builder->get_CellFormat()->set_VerticalAlignment(Aspose::Words::Tables::CellVerticalAlignment::Center);
builder->Write(u"This is row 1 cell 1");
// Use fixed column widths
// Insert a cell
builder->InsertCell();
builder->Write(u"This is row 1 cell 2");
builder->EndRow();
// Insert a cell
builder->InsertCell();
// Apply new row formatting
builder->get_RowFormat()->set_Height(100);
builder->get_RowFormat()->set_HeightRule(Aspose::Words::HeightRule::Exactly);
builder->get_CellFormat()->set_Orientation(Aspose::Words::TextOrientation::Upward);
builder->Write(u"This is row 2 cell 1");
// Insert a cell
builder->InsertCell();
builder->get_CellFormat()->set_Orientation(Aspose::Words::TextOrientation::Downward);
builder->Write(u"This is row 2 cell 2");
builder->EndRow();
builder->EndTable();

Shows how to create a simple table.

auto doc = MakeObject<Document>();
// Tables are placed in the body of a document
auto table = MakeObject<Table>(doc);
doc->get_FirstSection()->get_Body()->AppendChild(table);
// Tables contain rows, which contain cells,
// which contain contents such as paragraphs, runs and even other tables
// Calling table.EnsureMinimum will also make sure that a table has at least one row, cell and paragraph
auto firstRow = MakeObject<Row>(doc);
table->AppendChild(firstRow);
auto firstCell = MakeObject<Cell>(doc);
firstRow->AppendChild(firstCell);
auto paragraph = MakeObject<Paragraph>(doc);
firstCell->AppendChild(paragraph);
auto run = MakeObject<Run>(doc, u"Hello world!");
paragraph->AppendChild(run);
doc->Save(ArtifactsDir + u"Table.CreateTable.docx");

Shows how to iterate through all tables in the document and display the content from each cell.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
// Here we get all tables from the Document node. You can do this for any other composite node
// which can contain block level nodes. For example you can retrieve tables from header or from a cell
// containing another table (nested tables)
SharedPtr<TableCollection> tables = doc->get_FirstSection()->get_Body()->get_Tables();
// We can make a new array to clone all of the tables in the collection
ASSERT_EQ(2, tables->ToArray()->get_Length());
// Iterate through all tables in the document
for (int i = 0; i < tables->get_Count(); i++)
{
// Get the index of the table node as contained in the parent node of the table
System::Console::WriteLine(String::Format(u"Start of Table {0}",i));
SharedPtr<RowCollection> rows = tables->idx_get(i)->get_Rows();
// RowCollections can be cloned into arrays
ASPOSE_ASSERT_EQ(rows, rows->ToArray());
ASPOSE_ASSERT_NS(rows, rows->ToArray());
// Iterate through all rows in the table
for (int j = 0; j < rows->get_Count(); j++)
{
System::Console::WriteLine(String::Format(u"\tStart of Row {0}",j));
SharedPtr<CellCollection> cells = rows->idx_get(j)->get_Cells();
// RowCollections can also be cloned into arrays
ASPOSE_ASSERT_EQ(cells, cells->ToArray());
ASPOSE_ASSERT_NS(cells, cells->ToArray());
// Iterate through all cells in the row
for (int k = 0; k < cells->get_Count(); k++)
{
// Get the plain text content of this cell
String cellText = cells->idx_get(k)->ToString(Aspose::Words::SaveFormat::Text).Trim();
// Print the content of the cell
System::Console::WriteLine(String::Format(u"\t\tContents of Cell:{0} = \"{1}\"",k,cellText));
}
System::Console::WriteLine(String::Format(u"\tEnd of Row {0}",j));
}
System::Console::WriteLine(String::Format(u"End of Table {0}\n",i));
}

#include <Aspose.Words.Cpp/Model/Tables/Table.h>

+ Inheritance diagram for Aspose::Words::Tables::Table:

Public Member Functions

 Table (SharedPtr< DocumentBase > doc)
 Initializes a new instance of the Table class. More...
 
bool Accept (SharedPtr< DocumentVisitor > visitor) override
 Accepts a visitor. More...
 
void AutoFit (AutoFitBehavior behavior)
 Resizes the table and cells according to the specified auto fit behavior. More...
 
void ClearBorders ()
 Removes all table and cell borders on this table. More...
 
void ClearShading ()
 Removes all shading on the table. More...
 
void ConvertToHorizontallyMergedCells ()
 Converts cells horizontally merged by width to cells merged by HorizontalMerge. More...
 
void EnsureMinimum ()
 If the table has no rows, creates and appends one Row. More...
 
double get_AbsoluteHorizontalDistance ()
 Gets or sets absolute horizontal floating table position specified by the table properties, in points. Default value is 0. More...
 
double get_AbsoluteVerticalDistance ()
 Gets or sets absolute vertical floating table position specified by the table properties, in points. Default value is 0. More...
 
TableAlignment get_Alignment ()
 Specifies how an inline table is aligned in the document. More...
 
bool get_AllowAutoFit ()
 Allows Microsoft Word and Aspose.Words to automatically resize cells in a table to fit their contents. More...
 
bool get_AllowCellSpacing ()
 Gets or sets the "Allow spacing between cells" option. More...
 
bool get_AllowOverlap ()
 Gets whether a floating table shall allow other floating objects in the document to overlap its extents when displayed. Default value is true. More...
 
bool get_Bidi ()
 Gets or sets whether this is a right-to-left table. More...
 
double get_BottomPadding ()
 Gets or sets the amount of space (in points) to add below the contents of cells. More...
 
double get_CellSpacing ()
 Gets or sets the amount of space (in points) between the cells. More...
 
String get_Description ()
 Gets or sets description of this table. It provides an alternative text representation of the information contained in the table. More...
 
double get_DistanceBottom ()
 Gets distance between table bottom and the surrounding text, in points. More...
 
double get_DistanceLeft ()
 Gets distance between table left and the surrounding text, in points. More...
 
double get_DistanceRight ()
 Gets distance between table right and the surrounding text, in points. More...
 
double get_DistanceTop ()
 Gets distance between table top and the surrounding text, in points. More...
 
SharedPtr< Rowget_FirstRow ()
 Returns the first Row node in the table. More...
 
RelativeHorizontalPosition get_HorizontalAnchor ()
 Gets the base object from which the horizontal positioning of floating table should be calculated. Default value is Column. More...
 
SharedPtr< Rowget_LastRow ()
 Returns the last Row node in the table. More...
 
double get_LeftIndent ()
 Gets or sets the value that represents the left indent of the table. More...
 
double get_LeftPadding ()
 Gets or sets the amount of space (in points) to add to the left of the contents of cells. More...
 
NodeType get_NodeType () const override
 Returns NodeType.Table. More...
 
SharedPtr< PreferredWidthget_PreferredWidth ()
 Gets or sets the table preferred width. More...
 
HorizontalAlignment get_RelativeHorizontalAlignment ()
 Gets or sets floating table relative horizontal alignment. More...
 
VerticalAlignment get_RelativeVerticalAlignment ()
 Gets or sets floating table relative vertical alignment. More...
 
double get_RightPadding ()
 Gets or sets the amount of space (in points) to add to the right of the contents of cells. More...
 
SharedPtr< RowCollectionget_Rows ()
 Provides typed access to the rows of the table. More...
 
SharedPtr< Styleget_Style ()
 Gets or sets the table style applied to this table. More...
 
StyleIdentifier get_StyleIdentifier ()
 Gets or sets the locale independent style identifier of the table style applied to this table. More...
 
String get_StyleName ()
 Gets or sets the name of the table style applied to this table. More...
 
TableStyleOptions get_StyleOptions ()
 Gets or sets bit flags that specify how a table style is applied to this table. More...
 
TextWrapping get_TextWrapping ()
 Gets or sets TextWrapping for table. More...
 
String get_Title ()
 Gets or sets title of this table. It provides an alternative text representation of the information contained in the table. More...
 
double get_TopPadding ()
 Gets or sets the amount of space (in points) to add above the contents of cells. More...
 
RelativeVerticalPosition get_VerticalAnchor ()
 Gets the base object from which the vertical positioning of floating table should be calculated. Default value is Margin. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_AbsoluteHorizontalDistance (double value)
 Setter for get_AbsoluteHorizontalDistance. More...
 
void set_AbsoluteVerticalDistance (double value)
 Setter for get_AbsoluteVerticalDistance. More...
 
void set_Alignment (TableAlignment value)
 Setter for get_Alignment. More...
 
void set_AllowAutoFit (bool value)
 Setter for get_AllowAutoFit. More...
 
void set_AllowCellSpacing (bool value)
 Setter for get_AllowCellSpacing. More...
 
void set_Bidi (bool value)
 Setter for get_Bidi. More...
 
void set_BottomPadding (double value)
 Setter for get_BottomPadding. More...
 
void set_CellSpacing (double value)
 Setter for get_CellSpacing. More...
 
void set_Description (String value)
 Setter for get_Description. More...
 
void set_HorizontalAnchor (RelativeHorizontalPosition value)
 Setter for get_HorizontalAnchor. More...
 
void set_LeftIndent (double value)
 Setter for get_LeftIndent. More...
 
void set_LeftPadding (double value)
 Setter for get_LeftPadding. More...
 
void set_PreferredWidth (SharedPtr< PreferredWidth > value)
 Setter for get_PreferredWidth. More...
 
void set_RelativeHorizontalAlignment (HorizontalAlignment value)
 Setter for get_RelativeHorizontalAlignment. More...
 
void set_RelativeVerticalAlignment (VerticalAlignment value)
 Setter for get_RelativeVerticalAlignment. More...
 
void set_RightPadding (double value)
 Setter for get_RightPadding. More...
 
void set_Style (SharedPtr< Style > value)
 Setter for get_Style. More...
 
void set_StyleIdentifier (StyleIdentifier value)
 Setter for get_StyleIdentifier. More...
 
void set_StyleName (String value)
 Setter for get_StyleName. More...
 
void set_StyleOptions (TableStyleOptions value)
 Setter for get_StyleOptions. More...
 
void set_TextWrapping (TextWrapping value)
 Setter for get_TextWrapping. More...
 
void set_Title (String value)
 Setter for get_Title. More...
 
void set_TopPadding (double value)
 Setter for get_TopPadding. More...
 
void set_VerticalAnchor (RelativeVerticalPosition value)
 Setter for get_VerticalAnchor. More...
 
void SetBorder (BorderType borderType, LineStyle lineStyle, double lineWidth, Color color, bool isOverrideCellBorders)
 Sets the specified table border to the specified line style, width and color. More...
 
void SetBorders (LineStyle lineStyle, double lineWidth, Color color)
 Sets all table borders to the specified line style, width and color. More...
 
void SetShading (TextureIndex texture, Color foregroundColor, Color backgroundColor)
 Sets shading to the specified values on all cells in the table. More...
 
- Public Member Functions inherited from CompositeNode
SharedPtr< NodeAppendChild (SharedPtr< Node > newChild)
 Adds the specified node to the end of the list of child nodes for this node. More...
 
SharedPtr< NodeCollectionget_ChildNodes ()
 Gets all immediate child nodes of this node. More...
 
SharedPtr< CompositeNodeget_Container () override
 
int32_t get_Count ()
 Gets the number of immediate children of this node. More...
 
SharedPtr< Nodeget_FirstChild () const
 Gets the first child of the node. More...
 
bool get_HasChildNodes ()
 Returns true if this node has any child nodes. More...
 
bool get_IsComposite () override
 Returns true as this node can have child nodes. More...
 
SharedPtr< Nodeget_LastChild () const
 Gets the last child of the node. More...
 
SharedPtr< NodeGetChild (NodeType nodeType, int32_t index, bool isDeep)
 Returns an Nth child node that matches the specified type. More...
 
SharedPtr< NodeCollectionGetChildNodes (NodeType nodeType, bool isDeep)
 Returns a live collection of child nodes that match the specified type. More...
 
SharedPtr< NodeGetCurrentNode () override
 
SharedPtr< IEnumerator< SharedPtr< Node > > > GetEnumerator () override
 Provides support for the for each style iteration over the child nodes of this node. More...
 
SharedPtr< NodeGetNextMatchingNode (SharedPtr< Node > curNode) override
 
String GetText () override
 Gets the text of this node and of all its children. More...
 
int32_t IndexOf (SharedPtr< Node > child)
 Returns the index of the specified child node in the child node array. More...
 
SharedPtr< NodeInsertAfter (SharedPtr< Node > newChild, SharedPtr< Node > refChild)
 Inserts the specified node immediately after the specified reference node. More...
 
SharedPtr< NodeInsertBefore (SharedPtr< Node > newChild, SharedPtr< Node > refChild)
 Inserts the specified node immediately before the specified reference node. More...
 
SharedPtr< NodePrependChild (SharedPtr< Node > newChild)
 Adds the specified node to the beginning of the list of child nodes for this node. More...
 
void RemoveAllChildren ()
 Removes all the child nodes of the current node. More...
 
SharedPtr< NodeRemoveChild (SharedPtr< Node > oldChild)
 Removes the specified child node. More...
 
void RemoveSmartTags ()
 Removes all SmartTag descendant nodes of the current node. More...
 
SharedPtr< NodeListSelectNodes (String xpath)
 Selects a list of nodes matching the XPath expression. More...
 
SharedPtr< NodeSelectSingleNode (String xpath)
 Selects the first Node that matches the XPath expression. More...
 
- Public Member Functions inherited from Node
SharedPtr< NodeClone (bool isCloneChildren)
 Creates a duplicate of the node. More...
 
virtual SharedPtr< DocumentBaseget_Document () const
 Gets the document to which this node belongs. More...
 
SharedPtr< Nodeget_NextSibling ()
 Gets the node immediately following this node. More...
 
SharedPtr< CompositeNodeget_ParentNode ()
 Gets the immediate parent of this node. More...
 
SharedPtr< Nodeget_PreviousSibling ()
 Gets the node immediately preceding this node. More...
 
SharedPtr< Rangeget_Range ()
 Returns a Range object that represents the portion of a document that is contained in this node. More...
 
SharedPtr< CompositeNodeGetAncestor (NodeType ancestorType)
 Gets the first ancestor of the specified NodeType. More...
 
template<typename T >
GetAncestorOf ()
 
SharedPtr< NodeNextPreOrder (SharedPtr< Node > rootNode)
 Gets next node according to the pre-order tree traversal algorithm. More...
 
SharedPtr< NodePreviousPreOrder (SharedPtr< Node > rootNode)
 Gets the previous node according to the pre-order tree traversal algorithm. More...
 
void Remove ()
 Removes itself from the parent. More...
 
String ToString (SaveFormat saveFormat)
 Exports the content of the node into a string in the specified format. More...
 
String ToString (SharedPtr< SaveOptions > saveOptions)
 Exports the content of the node into a string using the specified save options. More...
 
- Public Member Functions inherited from Object
ASPOSECPP_SHARED_API Object ()
 
ASPOSECPP_SHARED_API Object (Object const &x)
 
virtual ASPOSECPP_SHARED_API ~Object ()
 
virtual ASPOSECPP_SHARED_API bool Equals (ptr obj)
 
Detail::SmartPtrCounter * GetCounter ()
 
virtual ASPOSECPP_SHARED_API int GetHashCode () const
 
ASPOSECPP_SHARED_API void Lock ()
 
virtual ASPOSECPP_SHARED_API ptr MemberwiseClone () const
 
Objectoperator= (Object const &x)
 
bool ReferenceEquals (String const &str, std::nullptr_t)
 
bool ReferenceEquals (String const &str1, String const &str2)
 
int RemovedSharedRefs (int count)
 
virtual ASPOSECPP_SHARED_API void SetTemplateWeakPtr (unsigned int argument)
 
int SharedCount () const
 
ObjectSharedRefAdded ()
 
int SharedRefRemovedSafe ()
 
virtual ASPOSECPP_SHARED_API String ToString () const
 
ASPOSECPP_SHARED_API void Unlock ()
 
Detail::SmartPtrCounter * WeakRefAdded ()
 
void WeakRefRemoved ()
 
- Public Member Functions inherited from System::Collections::Generic::IEnumerable< System::SharedPtr< Aspose::Words::Node > >
EnumeratorBasedIterator< T, IEnumerator< T > > begin () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > cbegin () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > cend () noexcept
 
EnumeratorBasedIterator< T, IEnumerator< T > > end () noexcept
 
bool LINQ_All (std::function< bool(T)> predicate)
 
bool LINQ_Any ()
 
bool LINQ_Any (std::function< bool(T)> predicate)
 
SharedPtr< IEnumerable< ResultType > > LINQ_Cast ()
 
SharedPtr< IEnumerable< Result > > LINQ_Cast ()
 
bool LINQ_Contains (T value)
 
int LINQ_Count ()
 
int LINQ_Count (const Func< T, bool > &predicate)
 
LINQ_ElementAt (int index)
 
LINQ_First ()
 
LINQ_First (const Func< T, bool > &predicate)
 
LINQ_FirstOrDefault ()
 
LINQ_FirstOrDefault (std::function< bool(T)> predicate)
 
LINQ_Last ()
 
LINQ_LastOrDefault ()
 
SharedPtr< IEnumerable< ResultType > > LINQ_OfType ()
 
SharedPtr< IEnumerable< Result > > LINQ_OfType ()
 
SharedPtr< IEnumerable< Source > > LINQ_OrderBy (const Func< Source, Key > &keySelector)
 
SharedPtr< IEnumerable< T > > LINQ_OrderBy (const Func< T, Key > &keySelector)
 
SharedPtr< IEnumerable< Result > > LINQ_Select (const Func< Source, Result > &selector)
 
SharedPtr< IEnumerable< ResultType > > LINQ_Select (const Func< T, ResultType > &selector)
 
ArrayPtr< T > LINQ_ToArray ()
 
SharedPtr< List< T > > LINQ_ToList ()
 
SharedPtr< IEnumerable< T > > LINQ_Where (std::function< bool(T)> predicate)
 

Static Public Member Functions

static const TypeInfoType ()
 
- Static Public Member Functions inherited from CompositeNode
static const TypeInfoType ()
 
- Static Public Member Functions inherited from Node
static String NodeTypeToString (NodeType nodeType)
 A utility method that converts a node type enum value into a user friendly string. More...
 
static const TypeInfoType ()
 
- Static Public Member Functions inherited from Object
bool Equals (double const &objA, double const &objB)
 
bool Equals (float const &objA, float const &objB)
 
static std::enable_if<!IsSmartPtr< T1 >::value &&!IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 
static std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 
static bool ReferenceEquals (ptr const &objA, ptr const &objB)
 
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, std::nullptr_t)
 
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, T const &objB)
 
static const TypeInfoType ()
 

Additional Inherited Members

- Public Types inherited from Object
typedef SmartPtr< Objectptr
 
typedef System::Details::SharedMembersType shared_members_type
 
- Public Types inherited from System::Collections::Generic::IEnumerable< System::SharedPtr< Aspose::Words::Node > >
typedef IEnumerator< T > IEnumeratorType
 
typedef T ValueType
 

Constructor & Destructor Documentation

◆ Table()

Aspose::Words::Tables::Table::Table ( System::SharedPtr< Aspose::Words::DocumentBase doc)

Initializes a new instance of the Table class.

When Table is created, it belongs to the specified document, but is not yet part of the document and ParentNode is null.

To append Table to the document use InsertAfter or InsertBefore on the story where you want the table inserted.

Parameters
docThe owner document.
Examples

Shows how to create a simple table.

auto doc = MakeObject<Document>();
// Tables are placed in the body of a document
auto table = MakeObject<Table>(doc);
doc->get_FirstSection()->get_Body()->AppendChild(table);
// Tables contain rows, which contain cells,
// which contain contents such as paragraphs, runs and even other tables
// Calling table.EnsureMinimum will also make sure that a table has at least one row, cell and paragraph
auto firstRow = MakeObject<Row>(doc);
table->AppendChild(firstRow);
auto firstCell = MakeObject<Cell>(doc);
firstRow->AppendChild(firstCell);
auto paragraph = MakeObject<Paragraph>(doc);
firstCell->AppendChild(paragraph);
auto run = MakeObject<Run>(doc, u"Hello world!");
paragraph->AppendChild(run);
doc->Save(ArtifactsDir + u"Table.CreateTable.docx");

Member Function Documentation

◆ Accept()

bool Aspose::Words::Tables::Table::Accept ( System::SharedPtr< Aspose::Words::DocumentVisitor visitor)
overridevirtual

Accepts a visitor.

Enumerates over this node and all of its children. Each node calls a corresponding method on DocumentVisitor.

For more info see the Visitor design pattern.

Parameters
visitorThe visitor that will visit the nodes.
Returns
True if all nodes were visited; false if DocumentVisitor stopped the operation before visiting all nodes.

Implements Aspose::Words::Node.

◆ AutoFit()

void Aspose::Words::Tables::Table::AutoFit ( Aspose::Words::Tables::AutoFitBehavior  behavior)

Resizes the table and cells according to the specified auto fit behavior.

This method mimics the commands available in the Auto Fit menu for a table in Microsoft Word. The commands available are "Auto Fit to Contents", "Auto Fit to Window" and "Fixed Column Width". In Microsoft Word these commands set relevant table properties and then update the table layout and Aspose.Words does the same for you.

Parameters
behaviorSpecifies how to auto fit the table.
Examples

Shows how to build a new table with a table style applied.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<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
// Apply which features should be formatted by the style
// Continue with building the table as normal
builder->Writeln(u"Item");
builder->get_CellFormat()->set_RightPadding(40);
builder->InsertCell();
builder->Writeln(u"Quantity (kg)");
builder->EndRow();
builder->InsertCell();
builder->Writeln(u"Apples");
builder->InsertCell();
builder->Writeln(u"20");
builder->EndRow();
builder->InsertCell();
builder->Writeln(u"Bananas");
builder->InsertCell();
builder->Writeln(u"40");
builder->EndRow();
builder->InsertCell();
builder->Writeln(u"Carrots");
builder->InsertCell();
builder->Writeln(u"50");
builder->EndRow();
doc->Save(ArtifactsDir + u"DocumentBuilder.InsertTableWithStyle.docx");

Shows how to build a formatted table that contains 2 rows and 2 columns.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
// Insert a cell
builder->InsertCell();
builder->get_CellFormat()->set_VerticalAlignment(Aspose::Words::Tables::CellVerticalAlignment::Center);
builder->Write(u"This is row 1 cell 1");
// Use fixed column widths
// Insert a cell
builder->InsertCell();
builder->Write(u"This is row 1 cell 2");
builder->EndRow();
// Insert a cell
builder->InsertCell();
// Apply new row formatting
builder->get_RowFormat()->set_Height(100);
builder->get_RowFormat()->set_HeightRule(Aspose::Words::HeightRule::Exactly);
builder->get_CellFormat()->set_Orientation(Aspose::Words::TextOrientation::Upward);
builder->Write(u"This is row 2 cell 1");
// Insert a cell
builder->InsertCell();
builder->get_CellFormat()->set_Orientation(Aspose::Words::TextOrientation::Downward);
builder->Write(u"This is row 2 cell 2");
builder->EndRow();
builder->EndTable();

◆ ClearBorders()

void Aspose::Words::Tables::Table::ClearBorders ( )

Removes all table and cell borders on this table.

Examples

Shows how to apply a outline border to a table.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
// Align the table to the center of the page
// Clear any existing borders and shading from the table
table->ClearBorders();
table->ClearShading();
// Set a green border around the table but not inside
// Fill the cells with a light green solid color
doc->Save(ArtifactsDir + u"Table.SetOutlineBorders.docx");

Shows how to remove all borders from a table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Create a table
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Hello world!");
builder->EndTable();
// Set a color/thickness for the top border of the first row and verify the values
SharedPtr<Border> topBorder = table->get_FirstRow()->get_RowFormat()->get_Borders()->idx_get(Aspose::Words::BorderType::Top);
ASPOSE_ASSERT_EQ(1.5, topBorder->get_LineWidth());
ASSERT_EQ(System::Drawing::Color::get_Red().ToArgb(), topBorder->get_Color().ToArgb());
ASSERT_EQ(Aspose::Words::LineStyle::Double, topBorder->get_LineStyle());
// Clear the borders all cells in the table
table->ClearBorders();
doc->Save(ArtifactsDir + u"Table.ClearBorders.docx");
// Upon re-opening the saved document, the new border attributes can be verified
doc = MakeObject<Document>(ArtifactsDir + u"Table.ClearBorders.docx");
table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
topBorder = table->get_FirstRow()->get_RowFormat()->get_Borders()->idx_get(Aspose::Words::BorderType::Top);
ASPOSE_ASSERT_EQ(0.0, topBorder->get_LineWidth());
ASSERT_EQ(System::Drawing::Color::Empty.ToArgb(), topBorder->get_Color().ToArgb());
ASSERT_EQ(Aspose::Words::LineStyle::None, topBorder->get_LineStyle());

◆ ClearShading()

void Aspose::Words::Tables::Table::ClearShading ( )

Removes all shading on the table.

Examples

Shows how to apply a outline border to a table.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
// Align the table to the center of the page
// Clear any existing borders and shading from the table
table->ClearBorders();
table->ClearShading();
// Set a green border around the table but not inside
// Fill the cells with a light green solid color
doc->Save(ArtifactsDir + u"Table.SetOutlineBorders.docx");

◆ ConvertToHorizontallyMergedCells()

void Aspose::Words::Tables::Table::ConvertToHorizontallyMergedCells ( )

Converts cells horizontally merged by width to cells merged by HorizontalMerge.

Examples

Shows how to convert cells horizontally merged by width to cells merged by CellFormat.HorizontalMerge.

auto doc = MakeObject<Document>(MyDir + u"Table with merged cells.docx");
// MS Word does not write merge flags anymore, they define merged cells by its width
// So AW by default define only 5 cells in a row and all of it didn't have horizontal merge flag
SharedPtr<Table> table = doc->get_FirstSection()->get_Body()->get_Tables()->idx_get(0);
SharedPtr<Row> row = table->get_Rows()->idx_get(0);
ASSERT_EQ(5, row->get_Cells()->get_Count());
// To resolve this inconvenience, we have added new public method to convert cells which are horizontally merged
// by its width to the cell horizontally merged by flags. Thus now we have 7 cells and some of them have
// horizontal merge value
table->ConvertToHorizontallyMergedCells();
row = table->get_Rows()->idx_get(0);
ASSERT_EQ(7, row->get_Cells()->get_Count());
ASSERT_EQ(Aspose::Words::Tables::CellMerge::None, row->get_Cells()->idx_get(0)->get_CellFormat()->get_HorizontalMerge());
ASSERT_EQ(Aspose::Words::Tables::CellMerge::First, row->get_Cells()->idx_get(1)->get_CellFormat()->get_HorizontalMerge());
ASSERT_EQ(Aspose::Words::Tables::CellMerge::Previous, row->get_Cells()->idx_get(2)->get_CellFormat()->get_HorizontalMerge());
ASSERT_EQ(Aspose::Words::Tables::CellMerge::None, row->get_Cells()->idx_get(3)->get_CellFormat()->get_HorizontalMerge());
ASSERT_EQ(Aspose::Words::Tables::CellMerge::First, row->get_Cells()->idx_get(4)->get_CellFormat()->get_HorizontalMerge());
ASSERT_EQ(Aspose::Words::Tables::CellMerge::Previous, row->get_Cells()->idx_get(5)->get_CellFormat()->get_HorizontalMerge());
ASSERT_EQ(Aspose::Words::Tables::CellMerge::None, row->get_Cells()->idx_get(6)->get_CellFormat()->get_HorizontalMerge());

◆ EnsureMinimum()

void Aspose::Words::Tables::Table::EnsureMinimum ( )

If the table has no rows, creates and appends one Row.

Examples

Shows how to ensure a table node is valid.

auto doc = MakeObject<Document>();
// Create a new table and add it to the document
auto table = MakeObject<Table>(doc);
doc->get_FirstSection()->get_Body()->AppendChild(table);
// Currently, the table does not contain any rows, cells or nodes that can have content added to them
ASSERT_EQ(0, table->GetChildNodes(Aspose::Words::NodeType::Any, true)->get_Count());
// This method ensures that the table has one row, one cell and one paragraph; the minimal nodes required to begin editing
table->EnsureMinimum();
table->get_FirstRow()->get_FirstCell()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u"Hello world!"));

◆ get_AbsoluteHorizontalDistance()

double Aspose::Words::Tables::Table::get_AbsoluteHorizontalDistance ( )

Gets or sets absolute horizontal floating table position specified by the table properties, in points. Default value is 0.

Examples

Shows how set the location of floating tables.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a table
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Table 1, cell 1");
builder->EndTable();
table->set_PreferredWidth(PreferredWidth::FromPoints(300));
// We can set the table's location to a place on the page, such as the bottom right corner
table->set_RelativeVerticalAlignment(Aspose::Words::Drawing::VerticalAlignment::Bottom);
table->set_RelativeHorizontalAlignment(Aspose::Words::Drawing::HorizontalAlignment::Right);
table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Table 2, cell 1");
builder->EndTable();
table->set_PreferredWidth(PreferredWidth::FromPoints(300));
// We can also set a horizontal and vertical offset from the location in the paragraph where the table was inserted
table->set_AbsoluteVerticalDistance(50);
table->set_AbsoluteHorizontalDistance(100);
doc->Save(ArtifactsDir + u"Table.ChangeFloatingTableProperties.docx");

◆ get_AbsoluteVerticalDistance()

double Aspose::Words::Tables::Table::get_AbsoluteVerticalDistance ( )

Gets or sets absolute vertical floating table position specified by the table properties, in points. Default value is 0.

Examples

Shows how set the location of floating tables.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a table
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Table 1, cell 1");
builder->EndTable();
table->set_PreferredWidth(PreferredWidth::FromPoints(300));
// We can set the table's location to a place on the page, such as the bottom right corner
table->set_RelativeVerticalAlignment(Aspose::Words::Drawing::VerticalAlignment::Bottom);
table->set_RelativeHorizontalAlignment(Aspose::Words::Drawing::HorizontalAlignment::Right);
table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Table 2, cell 1");
builder->EndTable();
table->set_PreferredWidth(PreferredWidth::FromPoints(300));
// We can also set a horizontal and vertical offset from the location in the paragraph where the table was inserted
table->set_AbsoluteVerticalDistance(50);
table->set_AbsoluteHorizontalDistance(100);
doc->Save(ArtifactsDir + u"Table.ChangeFloatingTableProperties.docx");

◆ get_Alignment()

Aspose::Words::Tables::TableAlignment Aspose::Words::Tables::Table::get_Alignment ( )

Specifies how an inline table is aligned in the document.

The default value is Left.

Examples

Shows how to apply a outline border to a table.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
// Align the table to the center of the page
// Clear any existing borders and shading from the table
table->ClearBorders();
table->ClearShading();
// Set a green border around the table but not inside
// Fill the cells with a light green solid color
doc->Save(ArtifactsDir + u"Table.SetOutlineBorders.docx");

◆ get_AllowAutoFit()

bool Aspose::Words::Tables::Table::get_AllowAutoFit ( )

Allows Microsoft Word and Aspose.Words to automatically resize cells in a table to fit their contents.

The default value is true.

See also
Aspose::Words::Tables::Table::AutoFit(Aspose::Words::Tables::AutoFitBehavior)
Examples

Shows how to set a table to shrink or grow each cell to accommodate its contents.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->get_CellFormat()->set_PreferredWidth(PreferredWidth::FromPoints(100));
builder->Write(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder->InsertCell();
builder->get_CellFormat()->set_PreferredWidth(PreferredWidth::Auto());
builder->Write(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder->EndRow();
builder->EndTable();
table->set_AllowAutoFit(allowAutoFit);
doc->Save(ArtifactsDir + u"Table.AllowAutoFitOnTable.html");

◆ get_AllowCellSpacing()

bool Aspose::Words::Tables::Table::get_AllowCellSpacing ( )

Gets or sets the "Allow spacing between cells" option.

Examples

Shows how to enable spacing between individual cells in a table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Animal");
builder->InsertCell();
builder->Write(u"Class");
builder->EndRow();
builder->InsertCell();
builder->Write(u"Dog");
builder->InsertCell();
builder->Write(u"Mammal");
builder->EndTable();
// Set the size of padding space between cells, and the switch that enables/negates this setting
table->set_CellSpacing(3);
table->set_AllowCellSpacing(allowCellSpacing);
doc->Save(ArtifactsDir + u"Table.AllowCellSpacing.html");

◆ get_AllowOverlap()

bool Aspose::Words::Tables::Table::get_AllowOverlap ( )

Gets whether a floating table shall allow other floating objects in the document to overlap its extents when displayed. Default value is true.

Examples

Shows how get properties for floating tables

auto doc = MakeObject<Document>(MyDir + u"Table wrapped by text.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
ASSERT_EQ(Aspose::Words::Tables::TextWrapping::Around, table->get_TextWrapping());
ASSERT_EQ(Aspose::Words::Drawing::RelativeHorizontalPosition::Margin, table->get_HorizontalAnchor());
ASSERT_EQ(Aspose::Words::Drawing::RelativeVerticalPosition::Paragraph, table->get_VerticalAnchor());
ASPOSE_ASSERT_EQ(false, table->get_AllowOverlap());

◆ get_Bidi()

bool Aspose::Words::Tables::Table::get_Bidi ( )

Gets or sets whether this is a right-to-left table.

When true, the cells in this row are laid out right to left.

The default value is false.

Examples

Shows how to create custom style settings for the table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Name");
builder->InsertCell();
builder->Write(u"مرحبًا");
builder->EndRow();
builder->InsertCell();
builder->InsertCell();
builder->EndTable();
auto tableStyle = System::DynamicCast<Aspose::Words::TableStyle>(doc->get_Styles()->Add(Aspose::Words::StyleType::Table, u"MyTableStyle1"));
tableStyle->set_AllowBreakAcrossPages(true);
tableStyle->set_Bidi(true);
tableStyle->set_CellSpacing(5);
tableStyle->set_BottomPadding(20);
tableStyle->set_LeftPadding(5);
tableStyle->set_RightPadding(10);
tableStyle->set_TopPadding(20);
tableStyle->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_AntiqueWhite());
tableStyle->get_Borders()->set_Color(System::Drawing::Color::get_Blue());
tableStyle->get_Borders()->set_LineStyle(Aspose::Words::LineStyle::DotDash);
table->set_Style(tableStyle);
// Some Table attributes are linked to style variables
ASSERT_TRUE(table->get_Bidi());
ASPOSE_ASSERT_EQ(5.0, table->get_CellSpacing());
ASSERT_EQ(u"MyTableStyle1", table->get_StyleName());
doc->Save(ArtifactsDir + u"Table.TableStyleCreation.docx");

◆ get_BottomPadding()

double Aspose::Words::Tables::Table::get_BottomPadding ( )

Gets or sets the amount of space (in points) to add below the contents of cells.

Examples

Shows how to create a table that contains a single cell and apply row formatting.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
// Set the row formatting
SharedPtr<RowFormat> rowFormat = builder->get_RowFormat();
rowFormat->set_Height(100);
rowFormat->set_HeightRule(Aspose::Words::HeightRule::Exactly);
// These formatting properties are set on the table and are applied to all rows in the table
table->set_LeftPadding(30);
table->set_RightPadding(30);
table->set_TopPadding(30);
table->set_BottomPadding(30);
builder->Writeln(u"Contents of formatted row.");
builder->EndRow();
builder->EndTable();
doc->Save(ArtifactsDir + u"DocumentBuilder.DocumentBuilderSetRowFormatting.docx");

◆ get_CellSpacing()

double Aspose::Words::Tables::Table::get_CellSpacing ( )

Gets or sets the amount of space (in points) between the cells.

Examples

Shows how to enable spacing between individual cells in a table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Animal");
builder->InsertCell();
builder->Write(u"Class");
builder->EndRow();
builder->InsertCell();
builder->Write(u"Dog");
builder->InsertCell();
builder->Write(u"Mammal");
builder->EndTable();
// Set the size of padding space between cells, and the switch that enables/negates this setting
table->set_CellSpacing(3);
table->set_AllowCellSpacing(allowCellSpacing);
doc->Save(ArtifactsDir + u"Table.AllowCellSpacing.html");

Shows how to create custom style settings for the table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Name");
builder->InsertCell();
builder->Write(u"مرحبًا");
builder->EndRow();
builder->InsertCell();
builder->InsertCell();
builder->EndTable();
auto tableStyle = System::DynamicCast<Aspose::Words::TableStyle>(doc->get_Styles()->Add(Aspose::Words::StyleType::Table, u"MyTableStyle1"));
tableStyle->set_AllowBreakAcrossPages(true);
tableStyle->set_Bidi(true);
tableStyle->set_CellSpacing(5);
tableStyle->set_BottomPadding(20);
tableStyle->set_LeftPadding(5);
tableStyle->set_RightPadding(10);
tableStyle->set_TopPadding(20);
tableStyle->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_AntiqueWhite());
tableStyle->get_Borders()->set_Color(System::Drawing::Color::get_Blue());
tableStyle->get_Borders()->set_LineStyle(Aspose::Words::LineStyle::DotDash);
table->set_Style(tableStyle);
// Some Table attributes are linked to style variables
ASSERT_TRUE(table->get_Bidi());
ASPOSE_ASSERT_EQ(5.0, table->get_CellSpacing());
ASSERT_EQ(u"MyTableStyle1", table->get_StyleName());
doc->Save(ArtifactsDir + u"Table.TableStyleCreation.docx");

◆ get_Description()

System::String Aspose::Words::Tables::Table::get_Description ( )

Gets or sets description of this table. It provides an alternative text representation of the information contained in the table.

The default value is an empty string.

This property is meaningful for ISO/IEC 29500 compliant DOCX documents (OoxmlCompliance). When saved to pre-ISO/IEC 29500 formats, the property is ignored.

◆ get_DistanceBottom()

double Aspose::Words::Tables::Table::get_DistanceBottom ( )

Gets distance between table bottom and the surrounding text, in points.

Examples

Shows the minimum distance operations between table boundaries and text.

auto doc = MakeObject<Document>(MyDir + u"Table wrapped by text.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
ASPOSE_ASSERT_EQ(25.9, table->get_DistanceTop());
ASPOSE_ASSERT_EQ(25.9, table->get_DistanceBottom());
ASPOSE_ASSERT_EQ(17.3, table->get_DistanceLeft());
ASPOSE_ASSERT_EQ(17.3, table->get_DistanceRight());

◆ get_DistanceLeft()

double Aspose::Words::Tables::Table::get_DistanceLeft ( )

Gets distance between table left and the surrounding text, in points.

Examples

Shows the minimum distance operations between table boundaries and text.

auto doc = MakeObject<Document>(MyDir + u"Table wrapped by text.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
ASPOSE_ASSERT_EQ(25.9, table->get_DistanceTop());
ASPOSE_ASSERT_EQ(25.9, table->get_DistanceBottom());
ASPOSE_ASSERT_EQ(17.3, table->get_DistanceLeft());
ASPOSE_ASSERT_EQ(17.3, table->get_DistanceRight());

◆ get_DistanceRight()

double Aspose::Words::Tables::Table::get_DistanceRight ( )

Gets distance between table right and the surrounding text, in points.

Examples

Shows the minimum distance operations between table boundaries and text.

auto doc = MakeObject<Document>(MyDir + u"Table wrapped by text.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
ASPOSE_ASSERT_EQ(25.9, table->get_DistanceTop());
ASPOSE_ASSERT_EQ(25.9, table->get_DistanceBottom());
ASPOSE_ASSERT_EQ(17.3, table->get_DistanceLeft());
ASPOSE_ASSERT_EQ(17.3, table->get_DistanceRight());

◆ get_DistanceTop()

double Aspose::Words::Tables::Table::get_DistanceTop ( )

Gets distance between table top and the surrounding text, in points.

Examples

Shows the minimum distance operations between table boundaries and text.

auto doc = MakeObject<Document>(MyDir + u"Table wrapped by text.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
ASPOSE_ASSERT_EQ(25.9, table->get_DistanceTop());
ASPOSE_ASSERT_EQ(25.9, table->get_DistanceBottom());
ASPOSE_ASSERT_EQ(17.3, table->get_DistanceLeft());
ASPOSE_ASSERT_EQ(17.3, table->get_DistanceRight());

◆ get_FirstRow()

System::SharedPtr<Aspose::Words::Tables::Row> Aspose::Words::Tables::Table::get_FirstRow ( )

Returns the first Row node in the table.

Examples

Shows how to use typed properties to access nodes of the document tree.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
// Quick typed access to all Table child nodes contained in the Body
SharedPtr<TableCollection> tables = doc->get_FirstSection()->get_Body()->get_Tables();
ASSERT_EQ(5, tables->idx_get(0)->get_Rows()->get_Count());
ASSERT_EQ(4, tables->idx_get(1)->get_Rows()->get_Count());
for (auto table : System::IterateOver(tables->LINQ_OfType<SharedPtr<Table> >()))
{
// Quick typed access to the first row of the table
if (table->get_FirstRow() != nullptr)
{
table->get_FirstRow()->Remove();
}
// Quick typed access to the last row of the table
if (table->get_LastRow() != nullptr)
{
table->get_LastRow()->Remove();
}
}
// Each table has shrunk by two rows
ASSERT_EQ(3, tables->idx_get(0)->get_Rows()->get_Count());
ASSERT_EQ(2, tables->idx_get(1)->get_Rows()->get_Count());

Shows how to combine the rows from two tables into one.

// Load the document
auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
// Get the first and second table in the document
// The rows from the second table will be appended to the end of the first table
auto firstTable = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
auto secondTable = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 1, true));
// Append all rows from the current table to the next
// Due to the design of tables even tables with different cell count and widths can be joined into one table
while (secondTable->get_HasChildNodes())
{
firstTable->get_Rows()->Add(secondTable->get_FirstRow());
}
// Remove the empty table container
secondTable->Remove();
doc->Save(ArtifactsDir + u"Table.CombineTables.docx");

◆ get_HorizontalAnchor()

Aspose::Words::Drawing::RelativeHorizontalPosition Aspose::Words::Tables::Table::get_HorizontalAnchor ( )

Gets the base object from which the horizontal positioning of floating table should be calculated. Default value is Column.

Examples

Shows how get properties for floating tables

auto doc = MakeObject<Document>(MyDir + u"Table wrapped by text.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
ASSERT_EQ(Aspose::Words::Tables::TextWrapping::Around, table->get_TextWrapping());
ASSERT_EQ(Aspose::Words::Drawing::RelativeHorizontalPosition::Margin, table->get_HorizontalAnchor());
ASSERT_EQ(Aspose::Words::Drawing::RelativeVerticalPosition::Paragraph, table->get_VerticalAnchor());
ASPOSE_ASSERT_EQ(false, table->get_AllowOverlap());

◆ get_LastRow()

System::SharedPtr<Aspose::Words::Tables::Row> Aspose::Words::Tables::Table::get_LastRow ( )

Returns the last Row node in the table.

Examples

Shows how to use typed properties to access nodes of the document tree.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
// Quick typed access to all Table child nodes contained in the Body
SharedPtr<TableCollection> tables = doc->get_FirstSection()->get_Body()->get_Tables();
ASSERT_EQ(5, tables->idx_get(0)->get_Rows()->get_Count());
ASSERT_EQ(4, tables->idx_get(1)->get_Rows()->get_Count());
for (auto table : System::IterateOver(tables->LINQ_OfType<SharedPtr<Table> >()))
{
// Quick typed access to the first row of the table
if (table->get_FirstRow() != nullptr)
{
table->get_FirstRow()->Remove();
}
// Quick typed access to the last row of the table
if (table->get_LastRow() != nullptr)
{
table->get_LastRow()->Remove();
}
}
// Each table has shrunk by two rows
ASSERT_EQ(3, tables->idx_get(0)->get_Rows()->get_Count());
ASSERT_EQ(2, tables->idx_get(1)->get_Rows()->get_Count());

◆ get_LeftIndent()

double Aspose::Words::Tables::Table::get_LeftIndent ( )

Gets or sets the value that represents the left indent of the table.

Examples

Shows how to create a formatted table using DocumentBuilder.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<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->set_LeftIndent(20.0);
// Set height and define the height rule for the header row
builder->get_RowFormat()->set_Height(40.0);
builder->get_RowFormat()->set_HeightRule(Aspose::Words::HeightRule::AtLeast);
// Some special features for the header row
builder->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::FromArgb(198, 217, 241));
builder->get_ParagraphFormat()->set_Alignment(Aspose::Words::ParagraphAlignment::Center);
builder->get_Font()->set_Size(16);
builder->get_Font()->set_Name(u"Arial");
builder->get_Font()->set_Bold(true);
builder->get_CellFormat()->set_Width(100.0);
builder->Write(u"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(u"Header Row,\n Cell 2");
builder->InsertCell();
builder->get_CellFormat()->set_Width(200.0);
builder->Write(u"Header Row,\n Cell 3");
builder->EndRow();
// Set features for the other rows and cells
builder->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_White());
builder->get_CellFormat()->set_Width(100.0);
builder->get_CellFormat()->set_VerticalAlignment(Aspose::Words::Tables::CellVerticalAlignment::Center);
// Reset height and define a different height rule for table body
builder->get_RowFormat()->set_Height(30.0);
builder->get_RowFormat()->set_HeightRule(Aspose::Words::HeightRule::Auto);
builder->InsertCell();
// Reset font formatting
builder->get_Font()->set_Size(12);
builder->get_Font()->set_Bold(false);
// Build the other cells
builder->Write(u"Row 1, Cell 1 Content");
builder->InsertCell();
builder->Write(u"Row 1, Cell 2 Content");
builder->InsertCell();
builder->get_CellFormat()->set_Width(200.0);
builder->Write(u"Row 1, Cell 3 Content");
builder->EndRow();
builder->InsertCell();
builder->get_CellFormat()->set_Width(100.0);
builder->Write(u"Row 2, Cell 1 Content");
builder->InsertCell();
builder->Write(u"Row 2, Cell 2 Content");
builder->InsertCell();
builder->get_CellFormat()->set_Width(200.0);
builder->Write(u"Row 2, Cell 3 Content.");
builder->EndRow();
builder->EndTable();
doc->Save(ArtifactsDir + u"DocumentBuilder.CreateFormattedTable.docx");

◆ get_LeftPadding()

double Aspose::Words::Tables::Table::get_LeftPadding ( )

Gets or sets the amount of space (in points) to add to the left of the contents of cells.

Examples

Shows how to create a table that contains a single cell and apply row formatting.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
// Set the row formatting
SharedPtr<RowFormat> rowFormat = builder->get_RowFormat();
rowFormat->set_Height(100);
rowFormat->set_HeightRule(Aspose::Words::HeightRule::Exactly);
// These formatting properties are set on the table and are applied to all rows in the table
table->set_LeftPadding(30);
table->set_RightPadding(30);
table->set_TopPadding(30);
table->set_BottomPadding(30);
builder->Writeln(u"Contents of formatted row.");
builder->EndRow();
builder->EndTable();
doc->Save(ArtifactsDir + u"DocumentBuilder.DocumentBuilderSetRowFormatting.docx");

◆ get_NodeType()

Aspose::Words::NodeType Aspose::Words::Tables::Table::get_NodeType ( ) const
overridevirtual

Returns NodeType.Table.

Implements Aspose::Words::Node.

◆ get_PreferredWidth()

System::SharedPtr<Aspose::Words::Tables::PreferredWidth> Aspose::Words::Tables::Table::get_PreferredWidth ( )

Gets or sets the table preferred width.

The default value is Auto.

Examples

Shows how to set a table to auto fit to 50% of the page width.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a table with a width that takes up half the page width
SharedPtr<Table> table = builder->StartTable();
// Insert a few cells
builder->InsertCell();
table->set_PreferredWidth(PreferredWidth::FromPercent(50));
builder->Writeln(u"Cell #1");
builder->InsertCell();
builder->Writeln(u"Cell #2");
builder->InsertCell();
builder->Writeln(u"Cell #3");
doc->Save(ArtifactsDir + u"DocumentBuilder.InsertTableWithPreferredWidth.docx");

◆ get_RelativeHorizontalAlignment()

Aspose::Words::Drawing::HorizontalAlignment Aspose::Words::Tables::Table::get_RelativeHorizontalAlignment ( )

Gets or sets floating table relative horizontal alignment.

Examples

Shows how set the location of floating tables.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a table
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Table 1, cell 1");
builder->EndTable();
table->set_PreferredWidth(PreferredWidth::FromPoints(300));
// We can set the table's location to a place on the page, such as the bottom right corner
table->set_RelativeVerticalAlignment(Aspose::Words::Drawing::VerticalAlignment::Bottom);
table->set_RelativeHorizontalAlignment(Aspose::Words::Drawing::HorizontalAlignment::Right);
table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Table 2, cell 1");
builder->EndTable();
table->set_PreferredWidth(PreferredWidth::FromPoints(300));
// We can also set a horizontal and vertical offset from the location in the paragraph where the table was inserted
table->set_AbsoluteVerticalDistance(50);
table->set_AbsoluteHorizontalDistance(100);
doc->Save(ArtifactsDir + u"Table.ChangeFloatingTableProperties.docx");

◆ get_RelativeVerticalAlignment()

Aspose::Words::Drawing::VerticalAlignment Aspose::Words::Tables::Table::get_RelativeVerticalAlignment ( )

Gets or sets floating table relative vertical alignment.

Examples

Shows how set the location of floating tables.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a table
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Table 1, cell 1");
builder->EndTable();
table->set_PreferredWidth(PreferredWidth::FromPoints(300));
// We can set the table's location to a place on the page, such as the bottom right corner
table->set_RelativeVerticalAlignment(Aspose::Words::Drawing::VerticalAlignment::Bottom);
table->set_RelativeHorizontalAlignment(Aspose::Words::Drawing::HorizontalAlignment::Right);
table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Table 2, cell 1");
builder->EndTable();
table->set_PreferredWidth(PreferredWidth::FromPoints(300));
// We can also set a horizontal and vertical offset from the location in the paragraph where the table was inserted
table->set_AbsoluteVerticalDistance(50);
table->set_AbsoluteHorizontalDistance(100);
doc->Save(ArtifactsDir + u"Table.ChangeFloatingTableProperties.docx");

◆ get_RightPadding()

double Aspose::Words::Tables::Table::get_RightPadding ( )

Gets or sets the amount of space (in points) to add to the right of the contents of cells.

Examples

Shows how to create a table that contains a single cell and apply row formatting.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
// Set the row formatting
SharedPtr<RowFormat> rowFormat = builder->get_RowFormat();
rowFormat->set_Height(100);
rowFormat->set_HeightRule(Aspose::Words::HeightRule::Exactly);
// These formatting properties are set on the table and are applied to all rows in the table
table->set_LeftPadding(30);
table->set_RightPadding(30);
table->set_TopPadding(30);
table->set_BottomPadding(30);
builder->Writeln(u"Contents of formatted row.");
builder->EndRow();
builder->EndTable();
doc->Save(ArtifactsDir + u"DocumentBuilder.DocumentBuilderSetRowFormatting.docx");

◆ get_Rows()

System::SharedPtr<Aspose::Words::Tables::RowCollection> Aspose::Words::Tables::Table::get_Rows ( )

Provides typed access to the rows of the table.

Examples

Shows how to iterate through all tables in the document and display the content from each cell.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
// Here we get all tables from the Document node. You can do this for any other composite node
// which can contain block level nodes. For example you can retrieve tables from header or from a cell
// containing another table (nested tables)
SharedPtr<TableCollection> tables = doc->get_FirstSection()->get_Body()->get_Tables();
// We can make a new array to clone all of the tables in the collection
ASSERT_EQ(2, tables->ToArray()->get_Length());
// Iterate through all tables in the document
for (int i = 0; i < tables->get_Count(); i++)
{
// Get the index of the table node as contained in the parent node of the table
System::Console::WriteLine(String::Format(u"Start of Table {0}",i));
SharedPtr<RowCollection> rows = tables->idx_get(i)->get_Rows();
// RowCollections can be cloned into arrays
ASPOSE_ASSERT_EQ(rows, rows->ToArray());
ASPOSE_ASSERT_NS(rows, rows->ToArray());
// Iterate through all rows in the table
for (int j = 0; j < rows->get_Count(); j++)
{
System::Console::WriteLine(String::Format(u"\tStart of Row {0}",j));
SharedPtr<CellCollection> cells = rows->idx_get(j)->get_Cells();
// RowCollections can also be cloned into arrays
ASPOSE_ASSERT_EQ(cells, cells->ToArray());
ASPOSE_ASSERT_NS(cells, cells->ToArray());
// Iterate through all cells in the row
for (int k = 0; k < cells->get_Count(); k++)
{
// Get the plain text content of this cell
String cellText = cells->idx_get(k)->ToString(Aspose::Words::SaveFormat::Text).Trim();
// Print the content of the cell
System::Console::WriteLine(String::Format(u"\t\tContents of Cell:{0} = \"{1}\"",k,cellText));
}
System::Console::WriteLine(String::Format(u"\tEnd of Row {0}",j));
}
System::Console::WriteLine(String::Format(u"End of Table {0}\n",i));
}

Shows how to combine the rows from two tables into one.

// Load the document
auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
// Get the first and second table in the document
// The rows from the second table will be appended to the end of the first table
auto firstTable = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
auto secondTable = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 1, true));
// Append all rows from the current table to the next
// Due to the design of tables even tables with different cell count and widths can be joined into one table
while (secondTable->get_HasChildNodes())
{
firstTable->get_Rows()->Add(secondTable->get_FirstRow());
}
// Remove the empty table container
secondTable->Remove();
doc->Save(ArtifactsDir + u"Table.CombineTables.docx");

◆ get_Style()

System::SharedPtr<Aspose::Words::Style> Aspose::Words::Tables::Table::get_Style ( )

Gets or sets the table style applied to this table.

Examples

Shows how to create custom style settings for the table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Name");
builder->InsertCell();
builder->Write(u"مرحبًا");
builder->EndRow();
builder->InsertCell();
builder->InsertCell();
builder->EndTable();
auto tableStyle = System::DynamicCast<Aspose::Words::TableStyle>(doc->get_Styles()->Add(Aspose::Words::StyleType::Table, u"MyTableStyle1"));
tableStyle->set_AllowBreakAcrossPages(true);
tableStyle->set_Bidi(true);
tableStyle->set_CellSpacing(5);
tableStyle->set_BottomPadding(20);
tableStyle->set_LeftPadding(5);
tableStyle->set_RightPadding(10);
tableStyle->set_TopPadding(20);
tableStyle->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_AntiqueWhite());
tableStyle->get_Borders()->set_Color(System::Drawing::Color::get_Blue());
tableStyle->get_Borders()->set_LineStyle(Aspose::Words::LineStyle::DotDash);
table->set_Style(tableStyle);
// Some Table attributes are linked to style variables
ASSERT_TRUE(table->get_Bidi());
ASPOSE_ASSERT_EQ(5.0, table->get_CellSpacing());
ASSERT_EQ(u"MyTableStyle1", table->get_StyleName());
doc->Save(ArtifactsDir + u"Table.TableStyleCreation.docx");

◆ get_StyleIdentifier()

Aspose::Words::StyleIdentifier Aspose::Words::Tables::Table::get_StyleIdentifier ( )

Gets or sets the locale independent style identifier of the table style applied to this table.

Examples

Shows how to build a new table with a table style applied.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<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
// Apply which features should be formatted by the style
// Continue with building the table as normal
builder->Writeln(u"Item");
builder->get_CellFormat()->set_RightPadding(40);
builder->InsertCell();
builder->Writeln(u"Quantity (kg)");
builder->EndRow();
builder->InsertCell();
builder->Writeln(u"Apples");
builder->InsertCell();
builder->Writeln(u"20");
builder->EndRow();
builder->InsertCell();
builder->Writeln(u"Bananas");
builder->InsertCell();
builder->Writeln(u"40");
builder->EndRow();
builder->InsertCell();
builder->Writeln(u"Carrots");
builder->InsertCell();
builder->Writeln(u"50");
builder->EndRow();
doc->Save(ArtifactsDir + u"DocumentBuilder.InsertTableWithStyle.docx");

◆ get_StyleName()

System::String Aspose::Words::Tables::Table::get_StyleName ( )

Gets or sets the name of the table style applied to this table.

Examples

Shows how to create custom style settings for the table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Name");
builder->InsertCell();
builder->Write(u"مرحبًا");
builder->EndRow();
builder->InsertCell();
builder->InsertCell();
builder->EndTable();
auto tableStyle = System::DynamicCast<Aspose::Words::TableStyle>(doc->get_Styles()->Add(Aspose::Words::StyleType::Table, u"MyTableStyle1"));
tableStyle->set_AllowBreakAcrossPages(true);
tableStyle->set_Bidi(true);
tableStyle->set_CellSpacing(5);
tableStyle->set_BottomPadding(20);
tableStyle->set_LeftPadding(5);
tableStyle->set_RightPadding(10);
tableStyle->set_TopPadding(20);
tableStyle->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_AntiqueWhite());
tableStyle->get_Borders()->set_Color(System::Drawing::Color::get_Blue());
tableStyle->get_Borders()->set_LineStyle(Aspose::Words::LineStyle::DotDash);
table->set_Style(tableStyle);
// Some Table attributes are linked to style variables
ASSERT_TRUE(table->get_Bidi());
ASPOSE_ASSERT_EQ(5.0, table->get_CellSpacing());
ASSERT_EQ(u"MyTableStyle1", table->get_StyleName());
doc->Save(ArtifactsDir + u"Table.TableStyleCreation.docx");

◆ get_StyleOptions()

Aspose::Words::Tables::TableStyleOptions Aspose::Words::Tables::Table::get_StyleOptions ( )

Gets or sets bit flags that specify how a table style is applied to this table.

Examples

Shows how to build a new table with a table style applied.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<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
// Apply which features should be formatted by the style
// Continue with building the table as normal
builder->Writeln(u"Item");
builder->get_CellFormat()->set_RightPadding(40);
builder->InsertCell();
builder->Writeln(u"Quantity (kg)");
builder->EndRow();
builder->InsertCell();
builder->Writeln(u"Apples");
builder->InsertCell();
builder->Writeln(u"20");
builder->EndRow();
builder->InsertCell();
builder->Writeln(u"Bananas");
builder->InsertCell();
builder->Writeln(u"40");
builder->EndRow();
builder->InsertCell();
builder->Writeln(u"Carrots");
builder->InsertCell();
builder->Writeln(u"50");
builder->EndRow();
doc->Save(ArtifactsDir + u"DocumentBuilder.InsertTableWithStyle.docx");

◆ get_TextWrapping()

Aspose::Words::Tables::TextWrapping Aspose::Words::Tables::Table::get_TextWrapping ( )

Gets or sets TextWrapping for table.

Examples

Shows how to work with table text wrapping.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Insert a table and a paragraph of text after it
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"Cell 1");
builder->InsertCell();
builder->Write(u"Cell 2");
builder->EndTable();
table->set_PreferredWidth(PreferredWidth::FromPoints(300));
builder->get_Font()->set_Size(16);
builder->Writeln(u"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
// Set the table to wrap text around it and push it down into the paragraph below be setting the position
table->set_AbsoluteHorizontalDistance(100);
table->set_AbsoluteVerticalDistance(20);
doc->Save(ArtifactsDir + u"Table.WrapText.docx");

◆ get_Title()

System::String Aspose::Words::Tables::Table::get_Title ( )

Gets or sets title of this table. It provides an alternative text representation of the information contained in the table.

The default value is an empty string.

This property is meaningful for ISO/IEC 29500 compliant DOCX documents (OoxmlCompliance). When saved to pre-ISO/IEC 29500 formats, the property is ignored.

◆ get_TopPadding()

double Aspose::Words::Tables::Table::get_TopPadding ( )

Gets or sets the amount of space (in points) to add above the contents of cells.

Examples

Shows how to create a table that contains a single cell and apply row formatting.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Table> table = builder->StartTable();
builder->InsertCell();
// Set the row formatting
SharedPtr<RowFormat> rowFormat = builder->get_RowFormat();
rowFormat->set_Height(100);
rowFormat->set_HeightRule(Aspose::Words::HeightRule::Exactly);
// These formatting properties are set on the table and are applied to all rows in the table
table->set_LeftPadding(30);
table->set_RightPadding(30);
table->set_TopPadding(30);
table->set_BottomPadding(30);
builder->Writeln(u"Contents of formatted row.");
builder->EndRow();
builder->EndTable();
doc->Save(ArtifactsDir + u"DocumentBuilder.DocumentBuilderSetRowFormatting.docx");

◆ get_VerticalAnchor()

Aspose::Words::Drawing::RelativeVerticalPosition Aspose::Words::Tables::Table::get_VerticalAnchor ( )

Gets the base object from which the vertical positioning of floating table should be calculated. Default value is Margin.

Examples

Shows how get properties for floating tables

auto doc = MakeObject<Document>(MyDir + u"Table wrapped by text.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
ASSERT_EQ(Aspose::Words::Tables::TextWrapping::Around, table->get_TextWrapping());
ASSERT_EQ(Aspose::Words::Drawing::RelativeHorizontalPosition::Margin, table->get_HorizontalAnchor());
ASSERT_EQ(Aspose::Words::Drawing::RelativeVerticalPosition::Paragraph, table->get_VerticalAnchor());
ASPOSE_ASSERT_EQ(false, table->get_AllowOverlap());

◆ GetType()

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

Reimplemented from Aspose::Words::CompositeNode.

◆ Is()

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

Reimplemented from Aspose::Words::CompositeNode.

◆ set_AbsoluteHorizontalDistance()

void Aspose::Words::Tables::Table::set_AbsoluteHorizontalDistance ( double  value)

◆ set_AbsoluteVerticalDistance()

void Aspose::Words::Tables::Table::set_AbsoluteVerticalDistance ( double  value)

◆ set_Alignment()

void Aspose::Words::Tables::Table::set_Alignment ( Aspose::Words::Tables::TableAlignment  value)

◆ set_AllowAutoFit()

void Aspose::Words::Tables::Table::set_AllowAutoFit ( bool  value)

◆ set_AllowCellSpacing()

void Aspose::Words::Tables::Table::set_AllowCellSpacing ( bool  value)

◆ set_Bidi()

void Aspose::Words::Tables::Table::set_Bidi ( bool  value)

◆ set_BottomPadding()

void Aspose::Words::Tables::Table::set_BottomPadding ( double  value)

◆ set_CellSpacing()

void Aspose::Words::Tables::Table::set_CellSpacing ( double  value)

◆ set_Description()

void Aspose::Words::Tables::Table::set_Description ( System::String  value)

◆ set_HorizontalAnchor()

void Aspose::Words::Tables::Table::set_HorizontalAnchor ( Aspose::Words::Drawing::RelativeHorizontalPosition  value)

◆ set_LeftIndent()

void Aspose::Words::Tables::Table::set_LeftIndent ( double  value)

◆ set_LeftPadding()

void Aspose::Words::Tables::Table::set_LeftPadding ( double  value)

◆ set_PreferredWidth()

void Aspose::Words::Tables::Table::set_PreferredWidth ( System::SharedPtr< Aspose::Words::Tables::PreferredWidth value)

◆ set_RelativeHorizontalAlignment()

void Aspose::Words::Tables::Table::set_RelativeHorizontalAlignment ( Aspose::Words::Drawing::HorizontalAlignment  value)

◆ set_RelativeVerticalAlignment()

void Aspose::Words::Tables::Table::set_RelativeVerticalAlignment ( Aspose::Words::Drawing::VerticalAlignment  value)

◆ set_RightPadding()

void Aspose::Words::Tables::Table::set_RightPadding ( double  value)

◆ set_Style()

void Aspose::Words::Tables::Table::set_Style ( System::SharedPtr< Aspose::Words::Style value)

◆ set_StyleIdentifier()

void Aspose::Words::Tables::Table::set_StyleIdentifier ( Aspose::Words::StyleIdentifier  value)

◆ set_StyleName()

void Aspose::Words::Tables::Table::set_StyleName ( System::String  value)

◆ set_StyleOptions()

void Aspose::Words::Tables::Table::set_StyleOptions ( Aspose::Words::Tables::TableStyleOptions  value)

◆ set_TextWrapping()

void Aspose::Words::Tables::Table::set_TextWrapping ( Aspose::Words::Tables::TextWrapping  value)

◆ set_Title()

void Aspose::Words::Tables::Table::set_Title ( System::String  value)

◆ set_TopPadding()

void Aspose::Words::Tables::Table::set_TopPadding ( double  value)

◆ set_VerticalAnchor()

void Aspose::Words::Tables::Table::set_VerticalAnchor ( Aspose::Words::Drawing::RelativeVerticalPosition  value)

◆ SetBorder()

void Aspose::Words::Tables::Table::SetBorder ( Aspose::Words::BorderType  borderType,
Aspose::Words::LineStyle  lineStyle,
double  lineWidth,
System::Drawing::Color  color,
bool  isOverrideCellBorders 
)

Sets the specified table border to the specified line style, width and color.

Parameters
borderTypeThe table border to change.
lineStyleThe line style to apply.
lineWidthThe line width to set (in points).
colorThe color to use for the border.
isOverrideCellBordersWhen true, causes all existing explicit cell borders to be removed.
Examples

Shows how to apply a outline border to a table.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
// Align the table to the center of the page
// Clear any existing borders and shading from the table
table->ClearBorders();
table->ClearShading();
// Set a green border around the table but not inside
// Fill the cells with a light green solid color
doc->Save(ArtifactsDir + u"Table.SetOutlineBorders.docx");

◆ SetBorders()

void Aspose::Words::Tables::Table::SetBorders ( Aspose::Words::LineStyle  lineStyle,
double  lineWidth,
System::Drawing::Color  color 
)

Sets all table borders to the specified line style, width and color.

Parameters
lineStyleThe line style to apply.
lineWidthThe line width to set (in points).
colorThe color to use for the border.
Examples

Shows how to format table and cell with different borders and shadings.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Start a table and set a default color/thickness for its borders
SharedPtr<Table> table = builder->StartTable();
// Set the cell shading for this cell
builder->InsertCell();
builder->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_Red());
builder->Writeln(u"Cell #1");
// Specify a different cell shading for the second cell
builder->InsertCell();
builder->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_Green());
builder->Writeln(u"Cell #2");
// End this row
builder->EndRow();
// Clear the cell formatting from previous operations
builder->get_CellFormat()->ClearFormatting();
// Create the second row
builder->InsertCell();
builder->Writeln(u"Cell #3");
// Clear the cell formatting from the previous cell
builder->get_CellFormat()->ClearFormatting();
builder->get_CellFormat()->get_Borders()->get_Left()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Right()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Top()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Bottom()->set_LineWidth(4.0);
builder->InsertCell();
builder->Writeln(u"Cell #4");
doc->Save(ArtifactsDir + u"DocumentBuilder.TableBordersAndShading.docx");

Shows how to build a table with all borders enabled (grid).

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
// Clear any existing borders from the table
table->ClearBorders();
// Set a green border around and inside the table
doc->Save(ArtifactsDir + u"Table.SetAllBorders.docx");

◆ SetShading()

void Aspose::Words::Tables::Table::SetShading ( Aspose::Words::TextureIndex  texture,
System::Drawing::Color  foregroundColor,
System::Drawing::Color  backgroundColor 
)

Sets shading to the specified values on all cells in the table.

Parameters
textureThe texture to apply.
foregroundColorThe color of the texture.
backgroundColorThe color of the background fill.
Examples

Shows how to apply a outline border to a table.

auto doc = MakeObject<Document>(MyDir + u"Tables.docx");
auto table = System::DynamicCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 0, true));
// Align the table to the center of the page
// Clear any existing borders and shading from the table
table->ClearBorders();
table->ClearShading();
// Set a green border around the table but not inside
// Fill the cells with a light green solid color
doc->Save(ArtifactsDir + u"Table.SetOutlineBorders.docx");

◆ Type()

static const System::TypeInfo& Aspose::Words::Tables::Table::Type ( )
static
static ASPOSECPP_SHARED_API Color get_White()
@ Around
Text is wrapped around the table occupying available side space.
String
@ RowBands
Apply row banding conditional formatting.
@ Margin
Specifies that the horizontal positioning shall be relative to the page margins.
@ AutoFitToContents
Aspose.Words enables the AutoFit option, removes the preferred width from the table and all cells and...
@ Top
Specifies the top border of a paragraph or a table cell.
@ Bottom
Specifies the bottom border of a paragraph or a table cell.
@ AtLeast
The height will be at least the specified height in points. It will grow, if needed,...
@ Downward
Text is rotated 90 degrees to the right to appear from top to bottom (tb-rl).
@ MediumShading1Accent1
@ Center
Text is aligned in the middle of a cell.
@ DotDash
@ Text
Saves the document in the plain text format.
@ Previous
The cell is merged to the previous cell horizontally or vertically.
@ FirstColumn
Apply 1 first column conditional formatting.
static System::SharedPtr< Aspose::Words::Tables::PreferredWidth > FromPercent(double percent)
A creation method that returns a new instance that represents a preferred width specified as a percen...
static ASPOSECPP_SHARED_API void WriteLine()
std::enable_if_t<!Details::IsIterable< Enumerable >::value, Details::EnumeratorAdapter< Enumerable, T > > IterateOver(System::SmartPtr< Enumerable > enumerable)
static ASPOSECPP_SHARED_API Color get_Black()
@ Left
Specifies the left border of a paragraph or a table cell.
@ None
static System::SharedPtr< Aspose::Words::Tables::PreferredWidth > & Auto()
Returns an instance that represents the "preferred width is not specified" value.
static ASPOSECPP_SHARED_API Color FromArgb(int argb)
@ First
The cell is the first cell in a range of merged cells.
static ASPOSECPP_SHARED_API Color get_LightGreen()
@ None
The cell is not merged.
@ Center
The table is centered.
static ASPOSECPP_SHARED_API Color get_Green()
static System::SharedPtr< Aspose::Words::Tables::PreferredWidth > FromPoints(double points)
A creation method that returns a new instance that represents a preferred width specified using a num...
@ TextureSolid
@ Upward
Text is rotated 90 degrees to the left to appear from bottom to top (bt-lr).
static ASPOSECPP_SHARED_API Color get_AntiqueWhite()
@ FixedColumnWidths
Aspose.Words disables the AutoFit option and removes the preferred with from the table....
@ FirstRow
Apply first row conditional formatting.
@ Right
Specifies the right border of a paragraph or a table cell.
@ Right
Specifies that the object shall be right aligned to the horizontal alignment base.
static ASPOSECPP_SHARED_API Color get_Blue()
@ Exactly
The height is specified exactly in points. Please note that if the text cannot fit inside the object ...
@ Paragraph
The object is positioned relative to the top of the paragraph that contains the anchor.
@ Auto
The height will grow automatically to accommodate all text inside an object.
static ASPOSECPP_SHARED_API Color get_Red()
static ASPOSECPP_SHARED_API const Color Empty
int ToArgb() const
@ Double
@ Table
A Table object that represents a table in a Word document. A Table node can have Row nodes.
@ Single
@ Any
Indicates all node types. Allows to select all children.
@ Table
The style is a table style.
@ Bottom
Specifies that the object shall be at the bottom of the vertical alignment base.
@ Center
Text is centered horizontally.