We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Access Words Table/Cell Text

Hello,

Is there any way I can access the specific table to update a single cell later in time? For example If I create a table with code below. I append few documents after I create this table. Now I have lost what I was doing on table and need to access the table's cell which is already on this document.

How can I change a cell's text on existing table in a document? Is there any ID that I need to generate while creating table? How should I access or refere to specific table and change TEXT on specific cell?

Dim ltable As Aspose.Words.Tables.Table

ltable = lobjDocBuilder.StartTable()

''''' Cell 1.1

lobjDocBuilder.InsertCell()

lobjDocBuilder.Write(psPlaintiff)

lobjDocBuilder.CellFormat.Width = 300

lobjDocBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left

lobjDocBuilder.Bold = False

lobjDocBuilder.Font.Underline = Underline.None

''''' Cell 1.2

lobjDocBuilder.Font.Underline = Underline.Single

lobjDocBuilder.Bold = True

lobjDocBuilder.InsertCell()

lobjDocBuilder.Write(psCase)

lobjDocBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Right

'lobjDocBuilder.Bold = True

'lobjDocBuilder.Font.Underline = Underline.Single

lobjDocBuilder.EndRow() '--End Of Row 1

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. You can access the table by index, also you can insert bookmark into the table and access table by moving DocumentBuilder cursor to the bookmark. For example see the following code:

//Create Document and DocuemntBuilder

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

//Build simple table in the document

//Build heder of table

builder.PushFont();

builder.Font.Bold = true;

builder.Font.Italic = true;

builder.InsertCell();

//Insert bookamark here

builder.StartBookmark("myTable");

builder.EndBookmark("myTable");

//Insert some text

builder.Write("First column");

builder.InsertCell();

builder.Write("Second column");

builder.InsertCell();

builder.Write("Third column");

builder.EndRow();

builder.PopFont();

//Build body of the table

for (int rowIdx = 0; rowIdx < 5; rowIdx++)

{

for (int cellIdx = 0; cellIdx < 3; cellIdx++)

{

builder.InsertCell();

builder.Write("Some text here.");

}

builder.EndRow();

}

builder.EndTable();

//=============================================

//Do something else with document

//=============================================

//Move DocumentBuilder cursor to the bookmark

builder.MoveToBookmark("myTable");

//Get table where this bookmark is placed

Table myTable = builder.CurrentNode.GetAncestor(NodeType.Table) as Table;

if (myTable != null)

{

//Now we can update values in the table

//Get cell that should be updated

Cell cell = myTable.Rows[1].Cells[0];

//First we should remove old text

cell.RemoveAllChildren();

cell.EnsureMinimum();

//move DocumentBuilder cursor to the cell

builder.MoveTo(cell.FirstParagraph);

//Insert new text

builder.Font.Color = Color.Red;

builder.Write("This is updated text");

}

//Save output document

doc.Save(@"Test135\out.doc");

Hope this helps.

Best regards.