We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Replace a text by a table

Thread ID:





140736 Nov 5,2018 07:29 AM UTC Jan 7,2019 05:07 PM UTC ASP.NET MVC - EJ 2 1
Tags: DocIO
Asked On November 5, 2018 07:29 AM UTC


I want to find a text and replace it by table but i don't know how to do it. i am new to the platform so any help will be appreciated.

For example:

In the doc there a word "table" want to change that by real table. 
I try  document.Replace("table", section, true, true, true);
In the section I add the table.

Dilli Babu Nandha Gopal [Syncfusion]
Replied On January 7, 2019 05:07 PM UTC

Hi Saly, 
Thank you for your patience. 
Yes, it is possible to replace a text with a table in a Word document which is illustrated in the following code example. 

//Open a word Document instance 
WordDocument document = new WordDocument("Template.docx"); 
//Create a new table. 
WTable table = new WTable(document); 
//sets lineWidth and color 
table.TableFormat.Borders.LineWidth = 2f; 
table.TableFormat.Borders.Color = Color.Black; 
//Sets number of rows and columns. 
table.ResetCells(2, 2); 
//Selects the first row and appends text in each cell. 
WTableRow row0 = table.Rows[0]; 
row0.Cells[0].CellFormat.Borders.LineWidth = 2f; 
row0.Cells[0].CellFormat.Borders.Color = Color.Black;        
//Selects the second row and appends text in each cell. 
WTableRow row1 = table.Rows[1];        
row1.Cells[1].CellFormat.Borders.LineWidth = 2f; 
row1.Cells[1].CellFormat.Borders.Color = Color.Black; 
//Creates TextBodyPart and insert the table. 
TextBodyPart part = new TextBodyPart(document); 
part.BodyItems.Insert(0, table); 
// replaces the specified text with a part. 
document.Replace("ReplaceText", part, false, false); 
//Save document and dispose the Word document instance 

To know more about different replacing functionalities, kindly refer the following link. 

Please let us know if you have any questions. 

Dilli babu. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon