4

I need to split a document in OpenXml sdk 2.0. The document has sections that each have a footer with a text element (name of the section). Is there a straightforward way to copy from one OpenXml document to another?

jle
  • 9,316
  • 5
  • 48
  • 67

3 Answers3

3

DocumentBuilder is the tool you are looking for. See for example, http://blogs.msdn.com/b/ericwhite/archive/2010/01/08/how-to-control-sections-when-using-openxml-powertools-documentbuilder.aspx

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • I was able to make this work but I had to remove all of the images from my document first. It only works with embedded images or it errors out... – jle Jan 20 '11 at 14:48
3

This would require a lot of work on your part to copy and merge stylesheets among other things. I'd recommend using altChunk to do the merging for you as it will take care of all the hard stuff for you. Here are two links to help explain it more: How to Use altChunk for Document Assembly and How to: Assemble Multiple Word Processing Documents in One

amurra
  • 15,221
  • 4
  • 70
  • 87
  • @jle - I might be not understanding exactly what you mean by "split off". Altchunk will take sections from various word docs and split them out so you can merge them into a new document of your choosing. Do you not have access to creating a templated word doc so you can use this? Otherwise you are going to have a really hard time getting all the styles to look right by doing the splitting manually. – amurra Jan 20 '11 at 12:28
  • 1
    I want to divide a document into sections based on the sections in the document. – jle Jan 20 '11 at 15:44
0

I have done similar to what you describe using just the OpenXmlSDK. Though I have to say it wasn't much fun, and I was left wanting a solution I didn't have to carve myself. In my case I had to keep footers/headers etc. with section content and split the document into several other documents.

At the time I couldn't locate any samples on identifying which section an element belonged to, and had to write a utility myself. (The way word splits sections is by injecting a section break after the content, and the SDK didn't seem to provide any helpers.) I then had to locate the header definition by using the headerReference and grab that content too, before creating a new document and injecting the header, footer, and section content.

I wish you the best of luck!

damoe
  • 221
  • 1
  • 3