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

Tables with bookmarks - Adding rows with text

Thread ID:

Created:

Updated:

Platform:

Replies:

105206 Sep 18,2012 07:18 AM UTC Sep 30,2015 10:56 PM UTC Windows Forms 11
loading
Tags: DocIO
Ricerca Sviluppo
Asked On September 18, 2012 07:18 AM UTC

Hello
We're evaluating DocIo in order to use it into our printing process.
We have a .doc model with labels (constant texts) and variables (bookmarks).
The .doc model may have also tables: the first row contains cell titles, the second one contains data cells; each data cells contains one (or maybe more) bookmarks.
The printing process uses the .doc model to create a new (final) document, just substituting bookmarks with variable values.

We tried BookmarksNavigator, and it is great :-)
We just find some difficulties with tables.
We'd need to populate the table, inserting many new lines; each line need to be cloned by the first one, in which we resolve bookmark values.We don't need to clone bookmarks, but we need to use the second table row as a model for all the tables row we add.
Attached to this post you'll find:
- a sample of .doc model (model.doc)
- a sample of the .doc resulting file we'd need to produce (final document.doc)

Do you have any suggestion to perform these operations?
We tried to copy the row with bookmarks into another WordDocument, set the bookmark values, and then add the row to the original table into the final document, but we got an exception (cannot add row from other document). Do you have any code sample we could follow?

Thank you very much!

Best regards

Chiara Marzano

PS: we know... MailMarge would be the better way :-)... but our .doc models may be created with OpenOffice tools, and fields are not managed in the same way :-(

Thank you in advance for any help :-)



sample documents_53e9512a.zip

Ramkumar M [Syncfusion]
Replied On September 19, 2012 11:32 AM UTC

Hi Chiara,

Thank you for your interest in Syncfusion products.

 We have created a sample to meet your specified requirements using DocIO. In this sample we have collected cloned first row into a List object instead of directly adding to the table. Then at the end of for loop we have added the rows in the list to table, so that the problem with ReplaceBookmarkContent can be resolve. Please find the sample from the below link and let us know if this helps you

 

Sample:

http://www.syncfusion.com/downloads/Support/DirectTrac/98975/Sample924521150.zip

 Please let us know if you have any questions.

 Regards

Ramkumar


Ricerca Sviluppo
Replied On November 2, 2012 02:30 PM UTC

Thank you very much, Ramkumar!
Your sample was very helpful! :-)

Now, we're "playing" always with tables, cloning rows and substituting cell's text (variables are simple text, instead of bookmarks).

Thank you very much
Best regards!

 

 

 


Ramkumar M [Syncfusion]
Replied On November 9, 2012 04:35 AM UTC

Hi Ricerca,

You are welcome. Please let us know if you have any question

Regards

Ramkumar 


Pedro Coelho
Replied On September 25, 2015 05:00 PM UTC

Hi,

That's exactly what i was looking for, but I need help for a small change.

It is possible to obtain the position of the table through bookmarks? 
instead of: 
BookmarksNavigator bk = new BookmarksNavigator(document);
//Finds the text within the table.
TextSelection textSelcetion = document.Find("TemplateRow", false, true);
//Gets the TextRange from the selection.
WTextRange textRange = textSelcetion.GetRanges()[0];

we could have something like
BookmarksNavigator bk = new BookmarksNavigator(document);
// Move to the bookmark in word document
bk.MoveToBookmark("TemplateRow");
//Finds the text within the table.
TextSelection textSelcetion = bk.GetBookmarkContent(); (????)
//Gets the TextRange from the selection.
WTextRange textRange = textSelcetion.GetRanges()[0];

Thank you very much
Best regards!

Sathish K [Syncfusion]
Replied On September 28, 2015 05:34 AM UTC

Hi Pedro,

Thank you for contacting Syncfusion support.

Yes, it is possible to access a table through bookmark and access the contents of the table. Kindly refer to the following code example to achieve this.

Code example:
// Move to the bookmark in word document

bk.MoveToBookmark("Bookmark1");

//Gets the content for the current bookmark

TextBodyPart part = bk.GetBookmarkContent();

//Iterates the text body part contents

foreach (Entity entity in part.BodyItems)

{

//Gets the table

if (entity is WTable)

{

//Process further on tables

WTable table = entity as WTable;                   

}
}

Please refer to the following UG documentation link to know more about Bookmarks and Bookmark navigator in DocIO:
http://help.syncfusion.com/windowsforms/docio/working-with-bookmarks

Please refer to the following UG documentation link to know more about tables in DocIO:
http://help.syncfusion.com/windowsforms/docio/working-with-tables

Regards,
Sathish


Pedro Coelho
Replied On September 28, 2015 08:38 PM UTC

Hi Sathish,

Thank you for your help.
I'm still having problems, in my word file I have this table with bookmarks:


But in your example the condition "if (entity is WTable)" is always false:

//Iterates the text body part contents
foreach (Entity entity in part.BodyItems)
{
//Gets the table
if (entity is WTable)
{
//the condition "if (entity is WTable)" is always false
}
}

any suggestion?

Thanks,
Pedro



Sathish K [Syncfusion]
Replied On September 29, 2015 04:43 AM UTC

Hi Pedro,

Kindly use the below code to access the bookmark contents with respect to your test case.

Code example:
//Move to the bookmark in word document 
bk.MoveToBookmark(
"Bookmark1");

//Gets the content for the current bookmark

TextBodyPart part = bk.GetBookmarkContent();

//Iterates the text body part contents

foreach (Entity entity in part.BodyItems)

{

//Gets the table

if (entity is WTable)

{

//Process further on tables

WTable table = entity as WTable;

}

else if (entity is WParagraph)

{

//Process further on the paragraph

WParagraph paragraph = entity as WParagraph;

}
}

Regards,
Sathish


Pedro Coelho
Replied On September 29, 2015 03:32 PM UTC

Hi Sathish,

With your last example I can see that entity is WParagraph, but what I want is the WTable.
I have tried several ways but can not get the WTable.

through the WParagraph I can get a table?

Thanks,
Pedro Coelho

Sathish K [Syncfusion]
Replied On September 30, 2015 04:28 AM UTC

Hi Pedro,

Solution 1:
Kindly use the below code to get the WTable entity from the WParagraph entity.

Code example:
//Gets the bookmark by it's name

Bookmark bookmark = document.Bookmarks.FindByName("Bookmark1");

//Gets the owner paragraph of Bookmart start

WParagraph para = bookmark.BookmarkStart.OwnerParagraph;

//Checks whether paragaph is defined within table cell

if (para.IsInCell)

{

//Gets the table

WTable table = GetTable(para);

}

private WTable GetTable(Entity entity)

{

//Checks until WTable entity

while (!(entity is WTable))

{

if (entity.Owner != null)

entity = entity.Owner;

else

break;

}

return entity as WTable;
}

Solution 2:
Alternatively you shall modify your template document as below and get the WTable instance using BookamrkNavigator as suggested earlier.

Code example for Bookmark navigator:
//Move to the bookmark in word document 
bk.MoveToBookmark(
"Bookmark1");
//Gets the content for the current bookmark
TextBodyPart part = bk.GetBookmarkContent();
//Iterates the text body part contents
foreach (Entity entity in part.BodyItems)
{
//Gets the table 
if (entity is WTable)
{
//Process further on tables
WTable table = entity as WTable;
}
else if (entity is WParagraph)
{
//Process further on the paragraph
WParagraph paragraph = entity as WParagraph;
}
}

Regards,
Sathish


Pedro Coelho
Replied On September 30, 2015 10:07 AM UTC

Hi Sathish,

Thank you very much, the solution 1 works for my template.

I am very grateful, thanks.
Pedro

Sathish K [Syncfusion]
Replied On September 30, 2015 10:56 PM UTC

Hi Pedro,

We are happy to hear that the provided solution has resolved your issue. Please let us know if you need any further assistance. We will be happy to assist you as always.

Regards,
Sathish


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

;