要するに、altchunk の内容を docx ソース ファイルにマージして、altchunk が多すぎる docx を開くときに問題が発生しないようにするにはどうすればよいですか?
背景:ファイルの作成時に動的に挿入された 5,000 個の altchunks を含む docx ファイルがあります。非常に多くの altcunks があり、それぞれに少なくとも 1 ページ分のコンテンツがあるため、ファイルは Word で開かれません。Word 2010 では「Word は作業ファイルを作成できませんでした」と報告され、Word 2007 では「開いているウィンドウが多すぎます」と報告されます。 、Office 相互運用機能で「ファイルが破損しているようです」と報告されます。
問題の原因は、altchunk コンテンツが docx ファイル構造内の別のファイルに保存されており、非常に多くのファイルを開く必要があるため、制限を超えていることだと思います。その場合、altchunk のコンテンツを docx の実際のソースにマージした方がよいでしょう。どうやってやるの?
プロセスでaltchunkを紛失したり、その定義が変更されたりしても、コンテンツが変更されていない限り問題ありません.
HTML スニペットを指定して、単一の altchunk を作成する方法の例を次に示します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)