In a certain document, we’re having a problem where it crashes MS Word in a specific set of circumstances:
- Use Aspose.Words NodeImporter to copy the sections of this document, using the routine below, and save it.
- Open MS Word 2003, go into VBA editor, and run “Documents.Open yourFilepath” (either in the immediate window, or in macro code) to open the file.
- Select the first or third paragraph (including the paragraph marker), and copy it.
- Now either close the document, or attempt to paste into another Word document. Either will cause MS Word to crash.
We don’t see the problem if we copy the contents of the document to a new document before working with it in Aspose. We have not been able to reproduce the problem without having used Aspose to copy the document. We don’t get the problem in Office 2000. We don’t get the problem if we double click the file to open it instead of using Documents.Open. We don’t have the problem if we don’t copy anything. We don’t have the problem if we only select a part of the first or third paragraph (without the paragraph marker), or if we select only the second or fourth paragraph.
I have attached a cleaned up version of the original document, before using Aspose. Since we can only attach one thing at a time, I will reply to this post and include the “after” document that has the problem in it.
Private Function FixStyles(ByVal fileBytes As Byte()) As Byte()
'Create a document object from a stream created from the byte array
Dim blobStream As New System.IO.MemoryStream(fileBytes)
Try
AsposeCommon.LoadLicence(True)
Dim uploadDoc As New Aspose.Words.Document(blobStream)
Dim newDoc As Aspose.Words.Document = CType(uploadDoc.Clone(False), Aspose.Words.Document)
Dim NodeImporter As New Aspose.Words.NodeImporter(uploadDoc, newDoc, Aspose.Words.ImportFormatMode.KeepSourceFormatting)
For Each srcSection As Aspose.Words.Section In uploadDoc
Dim dstSection As Aspose.Words.Node = NodeImporter.ImportNode(srcSection, True)
newDoc.AppendChild(dstSection)
Next
blobStream = New System.IO.MemoryStream
newDoc.Save(blobStream, Aspose.Words.SaveFormat.Doc)
fileBytes = blobStream.GetBuffer
Finally
blobStream.Dispose()
End Try
Return fileBytes
End Function