Ms word Word在使用openxml拆分docx后,在xxx.docx中发现无法读取的内容

Ms word Word在使用openxml拆分docx后,在xxx.docx中发现无法读取的内容,ms-word,openxml,openxml-sdk,Ms Word,Openxml,Openxml Sdk,我有一个完整的.docx,其中包括两个数学问题,docx嵌入了一些图片和MathType方程(oleobject),我根据分割文档,得到两个文件(first.docx,second.docx),first.docx工作正常,而second.docx在我试图打开它时会弹出一个警告对话框: "Word found unreadable content in second.docx. Do you want to recover the contents of this document? If yo

我有一个完整的.docx,其中包括两个数学问题,docx嵌入了一些图片和MathType方程(oleobject),我根据分割文档,得到两个文件(first.docx,second.docx),first.docx工作正常,而second.docx在我试图打开它时会弹出一个警告对话框:

"Word found unreadable content in second.docx. Do you want to recover the contents of this document? If you trust the source of this document, click Yes."
单击“是”后,可以打开文档,内容也正确,我想知道第二个.docx有什么问题?我已经用“OpenXMLSDK2.5生产力工具”检查过了,但没有发现任何原因。非常感谢您的帮助。谢谢

这三个文件已上载到

显示一些代码:

        byte[] templateBytes = System.IO.File.ReadAllBytes(TEMPLATE_YANG_FILE);
        using (MemoryStream templateStream = new MemoryStream())
        {
            templateStream.Write(templateBytes, 0, (int)templateBytes.Length);

            string guidStr = Guid.NewGuid().ToString();

            using (WordprocessingDocument document = WordprocessingDocument.Open(templateStream, true))
            {
                document.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);

                MainDocumentPart mainPart = document.MainDocumentPart;

                mainPart.Document = new Document();
                Body bd = new Body();

                foreach (DocumentFormat.OpenXml.Wordprocessing.Paragraph clonedParagrph in lst)
                {
                    bd.AppendChild<DocumentFormat.OpenXml.Wordprocessing.Paragraph>(clonedParagrph);

                    clonedParagrph.Descendants<Blip>().ToList().ForEach(blip =>
                    {
                        var newRelation = document.CopyImage(blip.Embed, this.wordDocument);
                        blip.Embed = newRelation;
                    });

                    clonedParagrph.Descendants<DocumentFormat.OpenXml.Vml.ImageData>().ToList().ForEach(imageData =>
                    {
                        var newRelation = document.CopyImage(imageData.RelationshipId, this.wordDocument);
                        imageData.RelationshipId = newRelation;
                    });
                }

                mainPart.Document.Body = bd;
                mainPart.Document.Save();
            }

            string subDocFile = System.IO.Path.Combine(this.outDir, guidStr + ".docx");
            this.subWordFileLst.Add(subDocFile);

            File.WriteAllBytes(subDocFile, templateStream.ToArray());
        }

使用生产力工具,发现oleobjectx.bin未被复制,所以我在复制Blip和ImageData后添加了以下代码:

clonedParagrph.Descendants<OleObject>().ToList().ForEach(ole =>
{
    var newRelation = document.CopyOleObject(ole.Id, this.wordDocument);
    ole.Id = newRelation;
});
clonedparph.subjects().ToList().ForEach(ole=>
{
var newRelation=document.CopyOleObject(ole.Id,this.wordDocument);
ole.Id=newRelation;
});

解决了问题。

您没有提到如何使用生产力工具。您是否将修复后的文档保存为新名称,关闭它,然后在工具中打开原始(有问题)文档并使用比较功能查看更改了什么?@Cindy Meister,谢谢,我比较了second.docx和一个新修复的文档,发现修复后的docx中/word/_rels/document2.xml.rels和/word/_rels/document.xml.rels之间存在差异,我发现一些嵌入/oleObjectx.bin(x是1,2,3 4)在second.docx(错误的docx)中丢失了,我不知道在拆分时如何复制这些oleobjects。@Cindy Meister,在拆分过程中,复制是基于段落的,也会处理Blip和ImageData。但是oleobject不是以特殊方式处理的。我认为oleobject包含在段落中。我不能为您回答这个问题,至少不能以这种格式回答。首先:看看Prod.Tool为从第一个版本创建修复版本而生成的代码——这应该会给你一些线索。如果这没有帮助,我建议您使用问题下方的链接将问题更改为真正的问题是什么(您的代码没有复制OLE对象)。。。。。。保留背景信息(基于“链接”拆分文档)。然后,由于xyz(提供一些详细信息)没有正确复制,问题第二个文档无效。包括“坏”和“修复”文档的相关Word Open XML。还包括您根据生产力工具生成的代码处理问题的尝试,并描述它如何没有产生正确的结果。
clonedParagrph.Descendants<OleObject>().ToList().ForEach(ole =>
{
    var newRelation = document.CopyOleObject(ole.Id, this.wordDocument);
    ole.Id = newRelation;
});