I have this function (SplitRun) that I am using in a class where I am highlighting text that I mark for find in a word docs.
private static Run splitRun(Run run, int position) throws Exception
{
Run afterRun = (Run)run.deepClone(true);
String sText = run.getText();
if (sText!= null && sText.length() >= position)
{
afterRun.setText(run.getText().substring(position));
run.setText(run.getText().substring((0), (0) + (position)));
run.getParentNode().insertAfter(afterRun, run);
}
return afterRun;
}
I have turned on the TrackChanges feature in the docx file. This works fine. But the document is not detecting & showing any changes even though the code has changed the font color. Why is this happening?
I introduced the following line after opening the doc so that the track changes API is set in my program.
doc.startTrackRevisions(“Test User”, Calendar.getInstance().getTime());
But when I run the program, I get a null pointer exception. The following is the stack trace
Exception in thread “main” java.lang.NullPointerException
at com.aspose.words.Run.setText(Unknown Source)
at tool.api.DocumentManagement.ReplaceEvaluatorFindAndHighlight.splitRun(ReplaceEvaluatorFindAndHighlight.java:95)
at tool.api.DocumentManagement.ReplaceEvaluatorFindAndHighlight.replacing(ReplaceEvaluatorFindAndHighlight.java:39)
at com.aspose.words.zz0V.zzZVz(Unknown Source)
at com.aspose.words.Range.replace(Unknown Source)
at tool.api.DocumentManagement.DocxHeaderFooterFixup.fixupDocxHeaderAndFooter(DocxHeaderFooterFixup.java:150)
at tool.api.DocumentManagement.DocxHeaderFooterFixup.main(DocxHeaderFooterFixup.java:42)