将DOC文件转换为c#或php或.net中的DOCX

时间:2014-01-24 10:54:09

标签: c# php .net

我想将DOC文件转换为c#或php或.net中的DOCX。

有可能吗?

2 个答案:

答案 0 :(得分:1)

查看here,绝对可以通过互操作方法等。

但该页面上有一些替代方案,例如ofc tool

来自that页面的C#代码段。

static void Main(string[] args)
{
    Word._Application application = new Word.Application();
    object fileformat = Word.WdSaveFormat.wdFormatXMLDocument;
    DirectoryInfo directory = new DirectoryInfo(@"c:\abc");
    foreach (FileInfo file in directory.GetFiles("*.doc", SearchOption.AllDirectories))
    {
        if (file.Extension.ToLower() == ".doc")
        {
            object filename = file.FullName;
            object newfilename = file.FullName.ToLower().Replace(".doc", ".docx");
            Word._Document document = application.Documents.Open(filename);

            document.Convert();
            document.SaveAs(newfilename, fileformat);
            document.Close();
            document = null;
        }
    }
    application.Quit();
    application = null;
}

答案 1 :(得分:0)

对于批处理文档,您可以查看为Word创建托管AddIn。有关详细信息,请参阅http://msdn.microsoft.com/en-US/office/hh133430