Page 1 of 1

Trying to turn track changes on

PostPosted: Tue Sep 16, 2014 8:11 am
by stangsman
Here is my code that works for manipulating other portions of document.xml for a docx file, but I am having trouble changing a setting that is part of the settings.xml part. I am basically performing a string replacement that if successful will turn on track changes for the docx.

private static void xmlSettings(WordprocessingMLPackage wordMLPackage) throws JAXBException
{
DocumentSettingsPart part = wordMLPackage.getMainDocumentPart().getDocumentSettingsPart();
String xml = XmlUtils.marshaltoString(part.getJaxbElement(), true);

xml = xml.replaceAll("<w:defaultTabStop w:val=\"720\" />", "<w:trackRevisions /><w:defaultTabStop w:val=\"720\" />");//Turns track revisions on

Object obj = XmlUtils.unmarshalString(xml);
part.setJaxbElement((Document) obj);

//ERROR = The method setJaxbElement(CTSettings) in the type JaxbXmlPartXPathAware<CTSettings> is not applicable for the arguments (Document)

}

Can anyone see what I am not seeing?

Re: Trying to turn track changes on

PostPosted: Tue Sep 16, 2014 8:42 am
by jason
Instead of casting obj to Document, you should be casting to CTSettings.

As a general comment, you can use string replacement like that, but it is brittle.

Why not:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
part.getJaxbElement().setTrackRevisions(new BooleanDefaultTrue());
 
Parsed in 0.027 seconds, using GeSHi 1.0.8.4

Re: Trying to turn track changes on

PostPosted: Wed Sep 17, 2014 3:01 am
by stangsman
Both way work perfectly for my assignment.

Thank you.

Re: Trying to turn track changes on

PostPosted: Wed Sep 24, 2014 2:57 am
by stangsman
Hmmm...now I am actually stuck on one point here. Although this code above enables the track changes feature, my programmatically changed data doesn't show up in the marked up form that track changes features.

For example, what I am now experimenting with is comparing previous answers in a database on my docx form with the current responses found on the form. I would like to show the previous answers in the marked up form that the track changes feature provides for visual reasons side by side with my current data.

My method as shown above has mainly involved string substitutions or replacements to manipulate the xml of the document. The track changes feature doesn't provide for an easy string replace to work for this challenge.

Any direction would be appreciated.