Saving an OpenXml Word document with thousands of headers and footers

Viewed 35

Yes you read that title right - thousands of headers and footers.

We are required to generate a massive Word document (think 20,000+ pages) and we are using the OpenXml SDK to do it. The document is comprised of thousands of reports, each of which may span multiple pages. We have the report generation down to a reasonable amount of time, except for the final step where we call WordProcessingDocument.Save() to save it to a file on disk. The operation hangs here for hours (I'm not really sure how many as we gave up after 4 hours).

It looks like the sheer number of headers and footers is somehow related to the length of time it takes to save the document, but I'm not sure exactly how.

Does anyone know of a way we can speed up the save process?

Edit: We ended up changing our reports to created "headers" and "footers" that are really part of the document body instead of using Word's headers and footers. This is not an ideal solution by any means but did allow us to move forward with our product.

As it turns out Word doesn't deal with thousands of headers and footers very well. This seems to be related to how many XML files are being generated inside the .docx file and how Microsoft manages then in their OpenXML library.

If anyone knows of a better way to generate documents with thousands of word headers and footers it would still be helpful for future updates!

0 Answers
Related