带有Word 2003 +兼容包的C#Word Interop Saving docx [英] C# Word Interop Saving docx with Word 2003 + Compatibility Pack
问题描述
在我的开发机上,我在Win7 x64上安装了Office 2007.
On my dev machine, I have office 2007 installed on Win7 x64.
目标计算机是在WinXP x64上运行的Office 2003 +兼容包(用于读取/写入docx等).
The target machines are Office 2003 + Compatibility Pack (to read/write docx, etc.) running on WinXP x64.
除其他事项外,我的程序确实将命令打开/另存为doc文件,并将其转换为docx.
My program does, among other things, open/save as commands on doc files, converting them to docx.
它在我的机器上运行非常好,但可悲的是在目标机器上提供了大小为零的文件.没有异常被抛出,看起来工作正常,除了当我查看输出文件时,它的长度为零.
It runs wonderfully on my machine, but sadly gives zero-sized files on the target machines. No exceptions are thrown, it looks like it's working fine except when I look at the output file, it's zero-length.
有什么想法为什么会发生这种情况,以及如何解决它?
Any ideas why this is happening, and how to get around it?
我的最后解决方法是编写一个难看的Word/PowerPoint宏,该宏将打开一个文档并将其保存.我希望所有事情都可以从我的程序中自动发生,而无需打开Word/PowerPoint窗口.
My last-resort will be to write an ugly Word/PowerPoint macro which opens a document and saves it. I would prefer everything to happen automatically from my program without opening a Word/PowerPoint window.
推荐答案
无需自动执行Word,由于弹出消息,它相当缓慢且脆弱,您可能需要看看Microsoft的Office File Converter( ofc.exe),但用户界面不必要的复杂.
There is no need to automate Word, which is rather slow and brittle due to pop-up messages You might want to have a look at Microsoft's Office File Converter (ofc.exe), which however has an unnecessarily complicated user interface.
最简单,最快的方法是使用以下命令轻松地将.doc转换为.docx:
The simplest and fastest way would be to convert from .doc to .docx easily using the following command:
"C:\Program Files\Microsoft Office\Office12\wordconv.exe" -oice -nme <input file> <output file>
其中<输入文件>和<输出文件>必须是完全限定的路径名.
where <input file> and <output file> need to be fully qualified path names.
使用for
可以轻松地将该命令应用于多个文档:
The command can be easily applied to multiple documents using for
:
for %F in (*.doc) do "C:\Program Files\Microsoft Office\Office12\wordconv.exe" -oice -nme "%F" "%Fx"
您可以使用Process.Start
方法从C#运行此命令.
You can run this command from C# using the Process.Start
method.
这篇关于带有Word 2003 +兼容包的C#Word Interop Saving docx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!