Question

I'm creating an Application-Level Add-in for MS Word 2007, 2010 & 2013 which needs to duplicate and modify a Content Control and it's contents 1 to 1000+ times.

Does anyone have any tips as to the best approach\methods to use when creating lots of duplicate Content Controls and modifying their contents?

So far I've hit a limit of around 800 duplicates before Word stops responding. This was achieved using Range.Copy and Range.PasteAndFormat and refreshing the screen periodically every 50-100 records using Globals.ThisAddIn.Application.ScreenRefresh(). Content Controls are modified by registering to the Globals.ThisAddIn.Application.ActiveDocument.ContentControlAfterAdd event.

Was it helpful?

Solution

Get the content as Flat OPC XML, manipulate it via the Open XML SDK, and then inject it back into your docx again.

See http://msdn.microsoft.com/en-us/library/office/ff191178(v=office.14).aspx

For more on Flat OPC, see http://ericwhite.com/blog/flat-opc-expanded/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top