Changing the text in a Word table cell

Hi,

I’m looking for a way to modify the text in a table cell. I can retrieve the text like this:

doc.GetChildNodes(NodeType.Table, true)[0]).Rows[0].Cells[0].ToTxt();

but I can’t find any method which allows me to change the text.

I thought about removing the ChildNode and adding a new one, but when I tried that I got an error message that I can’t create a new instance of the abstract class Node(), so I can’t figure out how to use something like this:

doc.GetChildNodes(NodeType.Table, true)[0]).Rows[0].Cells[0].ChildNodes.Add(…);

Thanks,

Mark

Hi Mark,

Thanks for your inquiry. Please check following code snippet, used to change text of a cell. Hopefully it will serve the purpose.

Document doc = new Document(MyDir + "TableTest.docx");
Table tbl = doc.Sections[0].Body.Tables[0];
tbl.Rows[0].Cells[0].FirstParagraph.Runs.Clear();
tbl.Rows[0].Cells[0].FirstParagraph.AppendChild(new Run(doc,"hello"));

Please feel free to contact us for any further assistance.

Best Regards,

Perfect. Thanks.

Hi Mark,

Thanks for your feedback. It is good to know that you managed to achieve your desired results.

Please feel free to contact us for any further assistance.

Best Regards