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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Clone Table from Template

Thread ID:

Created:

Updated:

Platform:

Replies:

120706 Oct 6,2015 05:25 PM UTC Dec 7,2015 12:15 PM UTC ASP.NET Web Forms 11
loading
Tags: DocIO
Pedro Coelho
Asked On October 6, 2015 05:25 PM UTC

Hi,

I have a word document with one (or more) table, I wanted to replicate this table with different data.

the word I have this table with bookmarks:
~
And I want to convert to:

I am using this code:


// replace account name
bk.MoveToBookmark(BookmarkAccountName);
bk.ReplaceBookmarkContent(ReplacedByBookmarkAccountName, true);


//Gets the table
WTable table = GetTable(); 
//Gets the second row
WTableRow templateRow = table.Rows[1] as WTableRow;
//Find the index of template row
int index = table.Rows.IndexOf(templateRow);

List<WTableRow> listrow = new List<WTableRow>();

for (int i = 1; i <= 5; i++) //is only a example
{
bk.MoveToBookmark(i);
bk.ReplaceBookmarkContent(ReplacedBy, true);
}

//Clone the first row add it to list
listrow.Add(templateRow.Clone());

foreach (WTableRow row in listrow)
{
//Add each row in the list to table
table.Rows.Add(row);
}
//Remove the template Row
table.Rows.RemoveAt(index);



This example works for the first table, but I am not able to duplicate the same table but with other data, someone can help?

Thanks,
Pedro Coelho

Sathish K [Syncfusion]
Replied On October 7, 2015 08:56 AM UTC

Hi Pedro,

Thank you for contacting Syncfusion support.

On analysing further on your working scenario, we suspect you are removing the original row after cloning and adding that to the document. So the bookmark associated with the original row also deleted and hence you can’t find the same row with the bookmark name again.

Could you please let us know whether you are trying to add new data for newly added rows? If we misunderstood your query, then kindly provide us clear and detailed information about your requirement. Thereby we will analyse further on your requirement and update you with appropriate solution at the earliest.

Regards,
Sathish


Pedro Coelho
Replied On October 7, 2015 09:23 AM UTC

Hi Sathish,

In word document I have the template table (first image) that represents the details of an account, but in my application I can have more than one account.
What I want to do is use the table on word document as template in order to create multiple tables (second image), but as you said, in the first interaction on the table I am removing the original row after cloning and adding that to the document, so the bookmark associated with the original row also deleted.

My idea was to clone the table, populate data and at the end delete the template table, it is possible to do this? and how can I do?

Thanks,
Pedro Coelho

Sathish K [Syncfusion]
Replied On October 8, 2015 09:23 AM UTC

Hi Pedro,

We have prepared a sample to meet your requirement to remove the template table after cloning and adding it’s content. Please find the sample from the following link and let us know if this helps you.

Sample link:
http://www.syncfusion.com/downloads/support/forum/120706/ze/Sample1614048630

Regards,
Sathish


Pedro Coelho
Replied On October 8, 2015 04:46 PM UTC

Hi Sathish,

I already can duplicate the table, thank you for the example.

Now I need to change the text in the table with bookmarks, I have tried many ways but without success, where I can add this code:

BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
bookmarkNavigator.MoveToBookmark("AccountDate"); //first cell
bookmarkNavigator.ReplaceBookmarkContent("Replaced By", true);

On "for" for add row I tried add the logic for replace the bookmark before adding the row, but it did not work.

More one time, you can help me?

Thanks,
Pedro Coelho

Sathish K [Syncfusion]
Replied On October 9, 2015 08:43 AM UTC

Hi Pedro,

We have prepared sample to replace bookmark content before cloning and adding the corresponding table row. Please find the sample from the following link.

Sample link:
http://www.syncfusion.com/downloads/support/forum/120706/ze/Sample_ReplaceBookmarkContent-735168816

If you are still facing any problems with bookmark content replacement, then kindly modify the above sample to reproduce the issue and update us the same. Thereby we will investigate further on this case and update you proper solution at the earliest.

Regards,
Sathish


Pedro Coelho
Replied On October 9, 2015 12:00 PM UTC

Hi Sathish,

I attached my example.
What is missing is to make the bookmark replace before add each row and keep the tables in the same position of the document ( not add at the end).

Thank you for your help.
Pedro Coelho

Attachment: syncfusion_96b6f87d.rar

Sathish K [Syncfusion]
Replied On October 12, 2015 06:41 AM UTC

Hi Pedro,

We have modified the given sample to meet your requirement to populate the table row in the same location after replacing bookmark contents. Please find the modified sample from the following link and let us know if this helps you.

Modified sample link:
http://www.syncfusion.com/downloads/support/forum/120706/ze/Modified_Sample1841504101

Regards,
Sathish


Pedro Coelho
Replied On October 23, 2015 10:01 AM UTC

Hi,

Still missing the bookmark replace before add each row... I have a issue here:

for (int i = 0; i < 5; i++)
{
      bookmarkNavigator.MoveToBookmark("AccountDate");
      bookmarkNavigator.ReplaceBookmarkContent("09/10/2015" + i, true);
      tempTable1.Rows.Add(row.Clone());
}

http://screencast.com/t/lJXNQIYP

Project: https://www.dropbox.com/s/3usaxqh6o7pk932/syncfusion.rar?dl=0

Can you help me?

Thanks,
Pedro Coelho

Sarathkumar V [Syncfusion]
Replied On October 26, 2015 12:39 PM UTC

Hi Pedro,

Thank you for your update.

We have modified the sample to meet with your requirement using mail merge fields instead of bookmarks. In the given template document “Donor Annual Statement.docx”, we have replaced the bookmark with merge fields, which act as a place holder during mail merge operation. Please find the modified sample from the following link and let us know if this helps you.

Modified sample link:
http://www.syncfusion.com/downloads/support/forum/120706/ze/ModifiedSample-1718543447.zip

Please let us know if you have any concern.
Regards,

Sarath


Pedro Coelho
Replied On December 2, 2015 10:11 AM UTC

Hi Sathish,

Thanks for your help.

The Merge Fields seems a good solution, but I am having other problem, I added another field section with "TableStart" but merging is only done in the first section.

You can take a look at the code attached? I only added a new section on word document with "TableStart/TableEnd" and added a new DataTable on DataSet on code.

Is possible work only with TableStart instead BeginGroup?

Thanks,
Pedro

Attachment: ModifiedSample1718543447v2_d449a04b.rar

Sarathkumar V [Syncfusion]
Replied On December 7, 2015 12:15 PM UTC

Hi Pedro,

Thank you for your update.

We have modified the sample to execute the mail merge group and mail merge nested group using MailMerge.ExecuteGroup() and MailMerge.ExecuteNestedGroup() respectively to archive your requirement. MailMerge.ExecuteGroup() will be used to perform the mail merge and append multiple records from data source within a specified region to a template document and MailMerge.ExecuteNestedGroup() will be used to perform the nested mail merge with relational or hierarchical data source and independent data tables in a template document. Please find the modified sample from the following link.

Sample Link:
http://www.syncfusion.com/downloads/support/forum/120706/ze/Sample_with_ExecuteGroup_and_ExecuteNestedGroup760723106.zip

For more details about DocIO’s mail merge functionality, please refer the following online UG documentation:
http://help.syncfusion.com/file-formats/docio/working-with-mailmerge

Please let us know if you have any queries.

Regards,
Sarath


CONFIRMATION

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.

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

;