为什么在word 2013文档中替换自定义xml部分中的xml节点的值会使其损坏?(Why replacing the value of xml node in custom xml part in

编程入门 行业动态 更新时间:2024-10-06 04:00:56
为什么在word 2013文档中替换自定义xml部分中的xml节点的值会使其损坏?(Why replacing the value of xml node in custom xml part in word 2013 document makes it corrupt?)

我创建了一个Word 2013文档并执行了以下操作:

在设计时添加了纯文本内容控件。 在设计时添加了自定义Xml零件。 从Custom Xml Part的一个节点到纯文本内容控件的映射。 节点的值出现在Content控件中。 我保存并关闭了文档。 将其重命名为.zip并将其解压缩到一个文件夹。 编辑了customXml / item1.xml文件夹中的文件,这是我的自定义xml部分,并将节点的值从<Name>John</Name>更改为<Name>Harry</Name> 。 将其存档为zip文件并将其重命名为.docx。 当我打开文档时,它已损坏,Microsoft Word说: -

We're sorry. We can't open XYZ.docx because we found a problem with the contents. Microsoft Office cannot open this file because some parts are missing or invalid.

I created a Word 2013 document and did the following:

Added a Plain Text Content Control to it at design time. Added a Custom Xml Part at design time. Did a mapping from one node of Custom Xml Part to the Plain Text Content Control. The value of node appeared in the Content control. I saved and closed the document. Renamed it to .zip and extracted it to a folder. Edited the file in folder customXml/item1.xml which is my custom xml part and changed the value of node from <Name>John</Name> to <Name>Harry</Name>. Re archived it as a zip file and renamed it to .docx. When I opened the document, it was corrupted and Microsoft Word says:-

We're sorry. We can't open XYZ.docx because we found a problem with the contents. Microsoft Office cannot open this file because some parts are missing or invalid.

最满意答案

原因 - 您无法像在步骤8中那样解压缩并重新压缩.docx文件

指南 - 试试这个。 创建一个虚拟的.docx文件格式单词。 解压缩并重新压缩并尝试打开文件。 您将得到相同的错误,您将无法按预期使用它。

解决方案 - 如果要编辑.docx文件,请使用Open XML SDK并执行此操作。 这是一个很好的指南的链接 - http://msdn.microsoft.com/EN-US/library/office/cc850833(v=office.15).aspx 。 Open XML生产力工具也会派上用场 - http://dotnet.dzone.com/articles/using-openxml-sdk-productivity

I was zipping and unzipping incorrectly. We don't need any Open XML SDK.

What I was doing was: Right click on XYZ.docx.zip and select Extract to XYZ.docx. When it got extracted into the folder XYZ.docx, I edited the contents inside and then zipped the entire folder to XYZ.docx which is wrong.

When I got inside of folder and zipped only the contents to XYZ.docx.zip, it started working.

更多推荐

本文发布于:2023-08-07 11:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464118.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   使其   节点   文档   xml

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!