Merge altchunk content into docx source

In short: How to merge altchunks content into source docx files to prevent problems opening docx that has too many altchunks?

Background: I have a docx file with 5000 altchunks that were dynamically inserted when the file was created. Because there are so many altcunks, each with at least 1 page of content, the file will not open in Word - in Word 2010 reports "Word cannot create work file", Word 2007 reports "Too many windows open" and Office interop reports : "The file appears to be damaged."

I believe the source of the problem is that altchunk content is stored in different files in the docx file structure and has to open so many files that exceed some limit. In this case, I would be better off merging the content of the altchunk into the actual docx source. How can i do this?

It's okay if I lose altchunk in the process, or change the definition until the content changes.

Here's an example of how one altchunk is created, given a snippet of HTML htmlText

:

''// add a part to the document for the HTML chunk
Const snippetChunkID As String = "HtmlSnippetChunk"
Dim snippetChunkPart As AlternativeFormatImportPart = currentDocument.MainDocumentPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Html, snippetChunkID)

''// feed HTML into new chunk
Dim stream As New MemoryStream(Encoding.Default.GetBytes("<html><body>" & htmlText & "</body></html>"))
snippetChunkPart.FeedData(stream)
stream.Close()
stream.Dispose()

''// insert chunk after the placeholder element
Dim snippetAltChunk As New AltChunk() With {.Id = snippetChunkID}
placeholderElement.InsertAfter(snippetAltChunk, placeholderElement)

      

+3
.net ms-office office-automation openxml


source to share


No one has answered this question yet

Check out similar questions:

968
What is the correct mime type for docx, pptx, etc.?
sixteen
Add HTML string to OpenXML document (* .docx)
3
adding images to openxml file generated with altchunk
1
The docx document is corrupted when copied although OpenXML C #
1
Converting altChunk to Paragraph with open xml
1
Unable to combine XML document content from Word 2010 files
1
AltChunk conversion to paragraphs and runs
0
Combine docx files into one and keep the formatting of numbered lists
0
ooxml altChunk is invisible
0
Expand the docx files, compare their contents and create a new merged docx file



All Articles
Loading...
X
Show
Funny
Dev
Pics