Page 1 of 1

How to delete a line from docx file programatically ?

PostPosted: Mon Jan 19, 2009 6:33 am
by john_wilfred
Hi,

I am currently implementing 'unmarshallFromTemplate' to create word document based on existing docx template.

I am able to successfully replace tags but for tags that are not in the hash map I do get 'null' text in the document. I understand that this is a feature, however our requirement is to delete such lines.

I have figured a way to replace 'null' text with empty string, but it is not serving the purpose as we need to completely delete the entire line where there is 'null' text (or when the tags are not found in the hashmap).

As I am new to docx4j I am unable to figure this out. Could someone help please.

In Short : How to delete a line programatically using docx4j.

Thanks

Re: How to delete a line from docx file programatically ?

PostPosted: Mon Jan 19, 2009 12:21 pm
by jason
Hi John

When you say 'line' do you mean a paragraph, a line in a table, or something else (eg text up to a soft return)?

One way to do what you are after maybe to use 'unmarshallFromTemplate' multiple times - so you have a hashmap for each 'line', and you test for null entries before calling that 'unmarshallFromTemplate'.

docx4j doesn't at present have built in any more sophisticated form of document automation/assembly.

cheers

Jason