4

Is it possible to update an existing toc with apache poi/Word SDK/ other api's? Or is there a workaround for it? E.g. removing the old toc then grabbing all headlines and adding them to the new toc or inserting them into the right place without deleting them in the beginning.

Edit: I'm working with .doc but I could change it to .docx so it doesn't really matter.

user4157124
  • 2,809
  • 13
  • 27
  • 42
codewing
  • 674
  • 8
  • 25

2 Answers2

2

I did this now with the Office SDK (C#) and an AutoIT Script. The C# code sets the fields update flag in the settings (class). The AutoIT script opens word, clicks through the dialogues, saves and closes the doc again. It s dirty but working.

codewing
  • 674
  • 8
  • 25
0

If you are using XWPFDocument then just do document.enforceUpdateFields(). However it still prompts the user that would he/she like to update the referenced files each time the .docx is opened.

Chinmay
  • 731
  • 1
  • 8
  • 19
  • It is almost the same solution as mine. The only difference is that you are using the apache api and not the ms sdk. – codewing Mar 09 '15 at 10:00
  • Oh yeah. Apache poi is in the text because I forgot to edit it. I was just looking for the simplest way to update the fields/toc. So your answer is just as right as mine :) – codewing Mar 10 '15 at 10:51