I am using a self made software that merges docx documents using chunks.
The code can be found below. I think it’s common technique according to MSD forums.
I can open the original a.docx and the original b.docx document in the viewer
(spire.docviewer_hotfix_1.3.1)
But the merged document cannot be opened (the sandbox appears but nothing happened)
Opening in Word 2010 works well .
I attached the result doc a.docx
I would be very graceful for any suggestion.
Many thanks in advance
Best regards Andreas
Just checked V 1.3 and this Version opens the file but displays not the merged part (second chunk)
- Code: Select all
Using myDoc = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open("c:\temp\a.docx", True)
Dim altChunkId = "AltChunkId" + DateTime.Now.Ticks.ToString().Substring(0, 2)
Dim mainPart = myDoc.MainDocumentPart
Dim chunk = mainPart.AddAlternativeFormatImportPart(
DocumentFormat.OpenXml.Packaging.AlternativeFormatImportPartType.WordprocessingML, altChunkId)
Using fileStream As IO.FileStream = IO.File.Open("c:\temp\b.docx", IO.FileMode.Open)
chunk.FeedData(fileStream)
End Using
Dim altChunk = New DocumentFormat.OpenXml.Wordprocessing.AltChunk()
altChunk.Id = altChunkId
mainPart.Document.Body.InsertAfter(altChunk, mainPart.Document.Body.Elements(Of DocumentFormat.OpenXml.Wordprocessing.Paragraph).Last())
mainPart.Document.Save()
End Using