在C#中以编程方式将 MS Project MPP 转换为 Word 文档

168 阅读1分钟

Microsoft Project ( MPP ) 文件用于不同的项目管理任务,例如组织和跟踪项目以及管理资源。如果希望文档形式的项目数据进一步修改和共享,可以通过将 MPP 文件转换为 Word DOC / DOCX格式来实现。在本文中,将学习如何使用 C# 将 MPP 文件转换为 Word 文档。

  • 使用 C# 将 MPP 文件转换为 Word DOC/DOCX 文件

我们将使用Aspose.PDF for .NETAspose.Tasks for .NET。前者是用于处理 Microsoft Project (MPP) 文件的 API,而后者是用于创建、读取和更新 PDF 文件的 API。我们将使用 Aspose.Tasks for .NET API 将 MPP 文件转换为 PDF 格式,使用 Aspose.PDF for .NET API 将生成的 PDF 文件转换为 Word 文件。下载最新版Aspose.PDF for .NET

使用 C# 将 MPP 文件转换为 Word DOC/DOCX 文件

可以使用下面给出的步骤轻松地将 MPP 文件转换为 Word 文档。

  • 使用Project 类加载 MPP 文件 。
  • 创建MemoryStream类的实例。
  • 使用Project.Save(Stream stream, SaveFileFormat format)方法将项目作为 PDF 保存到流中。
  • 使用Document类从流中加载 PDF 。
  • 使用Document.Save(string outputFileName, SaveFormat format)方法将 PDF 保存为 Word 文档。

以下示例代码显示了如何使用 C# 将 MPP 文件转换为 Word 文档。

// Load the MPP file
Project project = new Project("SourceDirectory\\Tasks\\project_test.mpp");

// Create an instance of the MemoryStream class
MemoryStream stream = new MemoryStream();

// Save the project as PDF to the MemoryStream
project.Save(stream, SaveFileFormat.PDF);

// Load the PDF from the MemoryStream
Document document = new Document(stream);

// Save the PDF as DOCX
document.Save("OutputDirectory\\SaveProjectAsDocx_out.docx", SaveFormat.DocX);

如果您有任何疑问或需求,请随时加入Aspose技术交流群(761297826),我们很高兴为您提供查询和咨询。