自动化:如何自动将 .doc 转换为 .docx? [英] Automation: how to automate transforming .doc to .docx?

查看:20
本文介绍了自动化:如何自动将 .doc 转换为 .docx?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个文件夹中有一堆 .doc 文件,我需要将它们转换为 .docx.

I have a bunch of .doc files in a folder which I need to convert to .docx.

手动将 .doc 转换为 .docx 非常简单:

To manually convert the .doc to .docx is pretty simple:

  1. 在 Word 2007 中打开 .doc
  2. 点击另存为...
  3. 另存为 .docx

但是,对数百个文件执行此操作绝对不好玩.=p

However, doing this for hundreds of files definitely ain't fun. =p

您将如何自动执行此操作?

How would you automate this?

推荐答案

自动化 Word.

如果您使用的是 .NET,请将 Microsoft.Office.Interop.Word(确保它是 12 版 - 相当于 Word 2007 以便您可以实现上述目标)引用程序集到您的项目并使用它来自动化 Word 应用程序做你想做的事情.伪代码

If you are using .NET, add Microsoft.Office.Interop.Word (make sure it is version 12 - equivalent to Word 2007 so you can achieve the above) reference assembly to your project and use it it automate word app to do exactly what you want to do above. The pseudocode

  • 创建应用程序对象
  • 使用应用程序对象打开一个文档(通过提供文件名)
  • 使用应用程序对象通过向其提供格式和输出文件名来执行另存为
  • 关闭当前文档
  • 循环上面的内容,直到完成所有文档
  • 用于释放 Word 或 Doc 对象的内务代码

您可以在 google 上找到大量示例,只需在 C# 中搜索 Word Automation 或类似内容即可.

You can find plenty of example on google, just search for Word Automation in C# or something along that line.

这篇关于自动化:如何自动将 .doc 转换为 .docx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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