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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

DocIO: Tables in Word-Document

Thread ID:

Created:

Updated:

Platform:

Replies:

107282 Feb 22,2013 02:07 PM UTC Feb 10,2014 07:23 AM UTC WPF 5
loading
Tags: DocIO
Silvester Schneidt
Asked On February 22, 2013 02:07 PM UTC

Is it possible to hide or delete an existing table from Word document, if some condition is true (DataTable is empty for example)

DataTable mDataTable = GetTestOrder(ID);

if (mDataTable.Rows.Count == 0)
    REMOVE / DELETE / HIDE Table???
else
    doc.MailMerge.ExecuteGroup(mDataTable);

Ananda Kumar V [Syncfusion]
Replied On February 28, 2013 01:36 PM UTC

Hi Silvester,

Thank you for your interest in Syncfusion products.

To remove an existing table from word document, you can simply call below code snippet.

Code snippet:

//Get Table object

IWTable table = document.Section[0].Tables[0];

//Remove table if DataTable is empty

if (mDataTable.Rows.Count == 0)

        //Remove Table object from the child entity collection of first section’s textbody

        document.Section[0].Body.ChildEntities.Remove(table);

//Alternatively you can directly remove the table from child entity collection by providing index (location) in owner collection

document.Section[0].Body.ChildEntities.RemoveAt(0);

We have prepared a simple sample to illustrate this usage in below link. 
Sample Link:
GenerateWord.zip

If you are using mail merge with Groups in your application, there is an alternate solution by simply setting RemoveEmptyGroup property of MailMerge class to true and place the table in the input template within Begin and End Group fields, DocIO will handle the logic of removing empty groups (elements between Begin and End Group) when the data table is empty.

Code snippet:

//Removes Empty Group during Mailmerge           

document.MailMerge.RemoveEmptyGroup = true;

We have prepared a simple sample to illustrate this usage in below link. 
Sample Link:
GenerateWord_MailMerge.zip

kindly try running the above samples and let us know if this helps you.

Regards,
Ananda Kumar V



Olivier Lesage
Replied On November 8, 2013 05:33 PM UTC

Could you make sample files available for download please ? We have this message : 
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>199E58130EAC18DC</RequestId>
<HostId>
ZBdJKTT0BaW224/wFlzzDOAtqZuOFmQdYRcpbnOy28+psyqa6tD7SX772ODg4tlM
</HostId>
</Error>
Thanks a lot

We try the function RemoveEmptyGroup in this sample but it doesn't wotk like we want.
The sample :
"BeginGroup:Test"
The text "Fusion"
"EndGroup:Test"
We would nothing in the file when there is no "Test" (ie Test = null).
But we obtain :
The text

Thanks.

Sathish K [Syncfusion]
Replied On November 13, 2013 06:16 PM UTC

Hi Silvester,

 

Thank you for your update.

 

We have prepared the sample to illustrate your requirement to remove the document contents which is preserved in between the Merge field of BeginGroup and EndGroup when the DataTable doesn’t have any records. Please do find the sample from the attachment, try running the sample and let us know if this helps you.

 

Please let us know if you have any other questions.

 

Regards,

Sathish



GenerateWord_ca01c495.zip

Badri
Replied On February 7, 2014 04:59 PM UTC

I am unable to download the sample solutions provided. Getting "Failed-Server Problem" when trying to download. Can you please help?

Sathish K [Syncfusion]
Replied On February 10, 2014 07:23 AM UTC

Hi Badri,

 

Thank you for your interest in Syncfusion products.

 

Please find the attached sample which demonstrates how to remove the items preserved between the Merge field of BeginGroup and EndGroup when the DataTable doesn’t have any records.

 

Please let us know if you have any other questions.

 

Regards,

Sathish


Attachment: GenerateWord_133d802b.zip

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

;