Equivalent VBA table convert to text function

Does Aspose.Words have the equivalent of Word’s convert to text for tables?

Example VBA code is :

Selection.Tables(1).Select
Selection.Rows.ConvertToText Separator:=wdSeparateByParagraphs, NestedTables:=True

@cgw.aspose,

Thanks for your inquiry. Please use the following code example to get the table’s text. Hope this helps you.

Moreover, we suggest you please read about Aspose.Words document object model from here:
Aspose.Words Document Object Model

Document doc = new Document(MyDir + "table.docx");
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
Console.WriteLine(table.ToString(SaveFormat.Text));

Thanks Tahir

You’re right - I’ve found in Aspose.Words you often have to approach a problem with a different mindset than VBA. The Aspose.Words table object will contain all the text runs which I can copy/extract out.

My table cell is rich, with lists, formatting etc. It’s only in a row so that, if I need to remove the text, I can remove the whole row rather than paragraph by paragraph.

I’ve tested with my variation of your How to Extract Selected Content Between Nodes in a Document function (customised to exclude the parent table by the fourth boolean parameter).

Basic test example:
Aspose.Words.Tables.Table _table = (Aspose.Words.Tables.Table)AsposeWordDocument.GetChild(NodeType.Table, 0, true);
Node n = _table.PreviousSibling;
System.Collections.ArrayList extractedNodes = Business.AsposeFunc.ExtractContent(_table.Rows[0].Cells[0].FirstChild, _table.Rows[0].Cells[0].LastChild, true, true);
extractedNodes.Reverse();
while (extractedNodes.Count > 0)
{
// Insert the last node from the reversed list
n.ParentNode.InsertAfter((Node)extractedNodes[0], n);
// Remove this node from the list after insertion.
extractedNodes.RemoveAt(0);
}
_table.Remove();

@cgw.aspose,

Thanks for your inquiry.

Yes, you can remove the table node using Table.Remove method and also remove the table’s child nodes e.g. Paragraph, Shape node one by one.

Yes, you can use the code example shared in this article to extract the contents from the document.

If you face any issue while using Aspose.Words, please share your input and expected output Word documents. We will then provide you more information about your query along with code.