简体   繁体   中英

How to split a document in OpenXML SDK

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?

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM