OpenXML SDK .docx文件和Open Office [英] OpenXML SDK .docx files and Open Office

查看:111
本文介绍了OpenXML SDK .docx文件和Open Office的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Microsoft的OpenXML SDK生成.docx文件的应用程序。最新版本的Open Office可以打开.docx,但它不会打开我的SDK代码生成的文件。如果我在Word中打开生成的文件并保存它,它将在Open Office中打开。然而,这并没有真正帮助我,因为我想知道我是否可以让我的应用程序对于没有Word的人来说是可行的。有没有人有幸在Open Office中打开OpenXML SDK生成的文档?

I have an application that uses Microsoft's OpenXML SDK to generate .docx files. The latest version of Open Office can open .docx, but it won't open a file that my SDK code generates. If I open a generated file in Word and save it, then it will open in Open Office. That however doesn't really help me all that much because I want to see if I can get my application to be viable for people who don't own Word. Has anybody had any luck getting OpenXML SDK generated docs to open in Open Office?

推荐答案

在这种情况下,解决方案是比较两个文件并查看不同之处然后相应地更新您的代码。



OpenXML是低级别的,因此有很多重要的细节...



我使用过OpenXML SDK 2.0但在我的情况下,我正在生成.xlsx文件。 SDK工具是必须的。它将允许您比较两个文件的内容。一旦你知道Word在保存文件时如何修复你的文件,你就会知道可能导致问题的原因。


甚至可以让你获得将第一个文件转换为第二个文件所需的C#代码。



它仍然会有很多作品。如上所述,SDK非常低级,细节对于正确而言非常重要。



顺便提一下,您是从现有文档开始创建文档的你修改了。最后一个选项可能更容易正确。



此外,只需做一些小改动并比较前后的文件就可以了解很多你应该怎么做。



顺便说一句,在我的情况下,我尝试过OpenOffice,但我尝试过Office 2003(兼容包),2007年,2010年和Excel在某些情况下需要查看器和一些细节,但不是全部。例如,观众需要完成所有计算并且还要退出Excel版本。
In that case, the solution is to compare both file and see what differs and then update your code accordingly.

OpenXML is low level so there is a lot of details that are important...

I have used OpenXML SDK 2.0 but in my case, I was generating .xlsx files. The SDK tool is a must. It will allows you to compare the content of both files. Once you know how Word "fix" your file when saving it, you will have a good idea of what might cause the problem.

It will even allows you to get the C# code required to convert the first file to the second one.

It will still be a lot of works. As mentionned, the SDK is very low level and details are important to get right.

By the way are you creating your document from scrath of you start from an existing document that you modify. This last option might be a bit easier to get right.

Also, it help a lot to just do a few small changes and compare the files before and after to see what you should do.

By the way, in my case, I have try OpenOffice but I have tried Office 2003 (with compatibility pack), 2007, 2010 and Excel viewer and some details were required in some cases but not all. For example, the viewer require that all computations are done and also recnt version of Excel.


迟到总比没有好,也许对某人有用。



要打开由ooxml sdk生成的docx,需要修补docx文件(docx只是一个压缩文件夹,因此可以手动或通过代码完成)。

1.在文件'_rels / .rels'中,你应该从'Relationship'节点的'Target'attr中删除斜杠。例如,

'< Relationship Target =< b> /word/document.xml < / b> Id =rId1/>'

应该变成

'< Relationship Target =< b> word / document.xml < / b>中Id =rId1/>'



2.在'word / _rels / document.xml.rels'文件中你应该删除'/ word /'定位'关系'节点的'attr'。例如,

'< Relationship Target =< b> /word/styles.xml < / b> Id =rId1/>'

应该变成

'< Relationship Target =< b> styles.xml < / b>中Id =rId1/>'



我为Apache OpenOffice 4.1.0找到了这个解决方案,它应该适用于其他版本。
Better late than never, maybe it will be useful for someone.

To open docx generated by ooxml sdk its needed to 'patch' docx file (docx is just a zipped folder, so it could be done manually, or by code).
1. in file '_rels/.rels' you should remove slash from 'Target' attr of 'Relationship' nodes. For example, was
'<Relationship Target="<b>/word/document.xml</b>" Id="rId1" />'
should became
'<Relationship Target="<b>word/document.xml</b>" Id="rId1" />'

2. in file 'word/_rels/document.xml.rels' you should remove '/word/' from 'Target' attr of 'Relationship' nodes. For example, was
'<Relationship Target="<b>/word/styles.xml</b>" Id="rId1" />'
should became
'<Relationship Target="<b>styles.xml</b>" Id="rId1" />'

I've found this solution for Apache OpenOffice 4.1.0, imho it should work for other versions.


这篇关于OpenXML SDK .docx文件和Open Office的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆