Page 1 of 1

delete CTSdtRow (without OpenDoPE)

PostPosted: Thu Aug 08, 2013 4:48 pm
by PoojaGe
Hi Jason,

Is there any alternate method to delete CTSdtRow in a word document(.docx) using docx4j apart from RemovalHandler since we dont want to use OpenDoPEHandler.
I want to delete CTSdtRow in my document(.docx) exactly the way as is shown in the above example.

Many Thanks,
Pooja

Re: delete CTSdtRow (without OpenDoPE)

PostPosted: Thu Aug 08, 2013 5:04 pm
by jason
Do you want to delete all of them, or some of them?

Do you want to delete their contents, or keep it?

Either way, there are 3 alternative approaches:

1 using XSLT, as shown in RemovalHandler. you can copy/modify that code.

2 using XPath to find the content controls

3 using TraversalUtil to find the content controls. If you study the OpenDoPE code, you'll see how this is done.

2 & 3 are explained in Getting Started. With 2 & 3, once you've found a content control, you delete it from the content list containing it.

Re 3, current dev sources now contain a package called 'finders':- https://github.com/plutext/docx4j/tree/ ... 4j/finders

Re: delete CTSdtRow (without OpenDoPE)

PostPosted: Thu Aug 08, 2013 5:41 pm
by PoojaGe
Hi Jason,

I want to delete some of them by identifying them with their tag value
I want to delete their contents as well

I am able to find the content controls and have them populated in the list.
But when try to do something like body.getContent.remove(list object), it returns false

Thanks,
Pooja

Re: delete CTSdtRow (without OpenDoPE)

PostPosted: Thu Aug 08, 2013 7:32 pm
by jason
which technique are you using to find the content controls?

PoojaGe wrote:when try to do something like body.getContent.remove(list object), it returns false


SdtRow wraps w:tr, so it'll be in the content of a table, not body.

2 things to be aware of:

1. so you'll need to identify the correct table. be careful using getParent to do that. there are some documented issues with it. If you are using TraversalUtil, in recent versions of docx4j TraversalUtil makes some effort to set parent correctly.

2. if you aren't finding it, it may be because the object in the list is wrapped in a JAXBElement

Re: delete CTSdtRow (without OpenDoPE)

PostPosted: Thu Aug 08, 2013 7:59 pm
by PoojaGe
Hi Jason,

I did some reading on finders and was able to find sample on BookmarksDeleter.java
Tried implementing the same for row level content controls and it worked :):)

Thanks alot...U guys rock!!!!

Cheers,
Pooja