C# 将Word转为ODT、ODT转为Word

2025-11-19 06:42:54

1、在VS程序中打开“解决方案资源管理器”,鼠标右键点击“引用”,“管理NuGet包”:

C# 将Word转为ODT、ODT转为Word

2、点击“搜索”,在搜索框中输入搜索内容,点击包,安装:

C# 将Word转为ODT、ODT转为Word

3、依次点击“OK”,"我接受",等待程序安装。

C# 将Word转为ODT、ODT转为Word

4、完成安装后,编辑如下代码,实现格式转换:

1. Word转ODT

using Spire.Doc;

namespace WordtoODT

{

    class Program

    {

        static void Main(string[] args)

        {

            //创建Document类的对象

            Document document = new Document();

            //加载Word文档

            document.LoadFromFile("sample.docx");

            //保存为ODT格式

            document.SaveToFile("ToODT.odt", FileFormat.Odt);

        }

    }

}

2. ODT转Word

using Spire.Doc;

namespace ODTtoWord

{

    class Program

    {

        static void Main(string[] args)

        {

            //创建Document类的对象

            Document document = new Document();

            //加载ODT文档

            document.LoadFromFile("test.odt");

            //保存为Word格式

            document.SaveToFile("toWord.docx", FileFormat.Docx2013);

        }

    }

}

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢