要将 DOC 文件转换为 DOCX 文件,可以使用 Microsoft.Office.Interop.Word 库。以下是一个示例代码:

using Microsoft.Office.Interop.Word;

public void ConvertDocToDocx(string docFilePath, string docxFilePath)
{
    // 创建Word应用程序对象
    Application wordApp = new Application();

    // 打开DOC文件
    Document doc = wordApp.Documents.Open(docFilePath);

    // 将DOC文件另存为DOCX文件
    doc.SaveAs2(docxFilePath, WdSaveFormat.wdFormatDocumentDefault);

    // 关闭Word文件和应用程序对象
    doc.Close();
    wordApp.Quit();
}

使用示例:

string docFilePath = @"C:\path\to\input.doc";
string docxFilePath = @"C:\path\to\output.docx";

ConvertDocToDocx(docFilePath, docxFilePath);

请注意,此代码需要在安装了 Microsoft Office 的计算机上运行,并确保已添加对 Microsoft.Office.Interop.Word 库的引用。

C# 将DOC转换为DOCX:简单易行的方法

原文地址: https://www.cveoy.top/t/topic/qlcN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录