Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
What is this page about?
This page explains how to work with text inside a table, including formatting and extraction.
As mentioned in previous articles, a table usually contains plain text, although other content such as images or even other tables can be placed in table cells.
Adding text or other content to the table is carried out using the appropriate methods of the DocumentBuilder class and is described in the “Create a Table” article. In this article, we will talk about how to work with text in an already existing table.
The table, like any other node in Aspose.Words, has access to the Range object. Using the table range object, you can replace text in a table.
The ability to use special characters when replacing is currently supported, so it is possible to replace existing text with multi-paragraph text. To do this, you need to use the special metacharacters described in the corresponding Replace method.
The following code example shows how to replace all instances of a string of text in the cells of an entire table:
Using the Range object, you can also call methods on the entire table range and extract the table as plain text. To do this, use the Text property.
The following code example shows how to print the text range of a table:
The same technique is used to extract content from individual table cells only.
The following code example shows how to print a text range of row and table elements:
Microsoft Word tables have a table title and table description that provide an alternative textual representation of the information contained in the table.
In Aspose.Words, you can also add a table title and description using the Title and Description properties. These properties are meaningful for DOCX documents conforming to the ISO/IEC 29500. When saving in formats earlier than ISO/IEC 29500, these properties are ignored.
The following code example shows how to set the title and description properties of a table:
Q: How can I replace a specific string in all cells of a table?
A: Retrieve the table’s Range object and call Range.Replace("oldText", "newText"). This operation scans every cell, paragraph, and run within the table and substitutes the matching text.
Q: How do I extract plain text from an entire table versus a single cell?
A: For the whole table, use Table.Range.Text. For a particular cell, access Cell.Range.Text. Both properties return the textual content without any formatting or markup.
Q: Can I replace text with line breaks or multiple paragraphs inside a cell?
A: Yes. Include the special metacharacters \r (paragraph break) and \v (line break) in the replacement string when calling Range.Replace. Aspose.Words will insert the appropriate breaks during the replacement.
Q: How can I add a title or description to a table for accessibility purposes?
A: Set the Table.Title and Table.Description properties. These are stored in the DOCX file according to the ISO/IEC 29500 standard and are ignored when saving to older Word formats.
Q: I need to replace text but keep the original formatting; how can I achieve that?
A: Use Range.Replace together with a FindReplaceOptions object where PreserveFormatting is set to true. This ensures that only the text changes while the original font, style, and other formatting remain intact.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.