本教程描述了使用最好的文档转换库之一在 C# 中**将 EPUB 转换为 Word 的过程,并提供了一个示例应用程序用于 C# EPUB 到 Word 转换器向您展示如何按照本指南中说明的工作流程进行开发。这篇文章还提供了有关如何自定义转换后的 Word 文件的信息。您可以在下面查看将电子书转换为 Word 文档的主要步骤和代码片段。
在 C# 中将 EPUB 转换为 Word 的步骤
- 从 NuGet 安装 GroupDocs.Conversion for .NET 包以将 EPUB 转换为 Word
- 添加对 GroupDocs.Conversion 命名空间的引用以将 EPUB 格式转换为 Word 格式
- 初始化 Converter 类以从磁盘加载输入的 EPUB 文件以转换为 Word 格式
- 创建和设置转换选项以自定义转换后的 Word 文件
- 最后调用Convert方法将EPUB保存为DOCX格式到磁盘
这些步骤使您能够通过编写几行代码和几次 API 调用,快速创建使用 C#* 将 EPUB 转换为 DOC 的功能。这些说明与平台无关,可用于任何支持 .NET 环境的流行操作系统,例如 Windows、Linux 和 macOS。此外,您无需安装任何其他软件即可使用此工作流和执行文档转换。
在 C# 中将 EPUB 转换为 Word 的代码
using System; | |
using GroupDocs.Conversion.Options.Convert; | |
namespace ConvertEpubToWordInCSharp | |
{ | |
class Program | |
{ | |
public static void Main(string[] args) // Main function to convert EPUB to Word using C# | |
{ | |
// Remove the watermark in output Word document by adding license | |
string licensePath = "GroupDocs.Conversion.lic"; | |
GroupDocs.Conversion.License lic = new GroupDocs.Conversion.License(); | |
lic.SetLicense(licensePath); | |
// Load the source EPUB file for conversion to Word | |
var converter = new GroupDocs.Conversion.Converter("sample.epub"); | |
// Set the conversion options for Word document to customize the output file | |
WordProcessingConvertOptions options = new WordProcessingConvertOptions(); | |
// Convert and save the EPUB in Word format | |
converter.Convert("converted.docx", options); | |
Console.WriteLine("Done"); | |
} | |
} | |
} |
在上面的代码片段中,创建了 C#* 应用程序中的 *EPUB 到 DOCX 转换器以进行演示。如您所见,此示例代码非常易于理解,可以帮助您在项目中快速使用它进行文档转换。您只需调整文件路径并安装提到的转换包即可运行此示例代码。
我们已经讨论了使用 C# 将 EPUB 转换为 Word 的文档转换过程,并为其制作了示例代码。最近,我们发表了一篇使用 C# 将 ODT 转换为 PDF 的文章,请查看 如何在 C# 中将 ODT 转换为 PDF 指南了解更多信息。