이 짧은 자습서에는 C#에서 PowerPoint를 Word로 변환하는 데 필요한 모든 정보가 포함되어 있습니다. PPTX와 같은 기존 PowerPoint 프레젠테이션을 로드한 다음 DOCX 파일과 같은 Word 문서로 저장하는 방법을 배우게 됩니다. 또한 **PowerPoint를 C#**에서 Word로 변경하기 위한 이 요구 사항을 달성하기 위해 여러 라이브러리를 사용하는 방법도 배우게 됩니다.
C#에서 PowerPoint를 Word로 변환하는 단계
- 저장소에서 Aspose.Slides for .NET 및 Aspose.Words for .NET를 추가하도록 개발 환경을 구성합니다.
- 소스 프레젠테이션을 Presentation 클래스 개체에 로드
- 메모리 스트림 객체 생성
- 로드된 프레젠테이션을 HTML 파일로 메모리 스트림에 저장
- 로드 형식을 HTML로 설정하여 HTML 스트림의 로드를 제어하는 LoadOptions 클래스 객체 생성
- 메모리 스트림에 저장된 HTML 데이터를 Aspose.Words에서 Document 클래스 개체로 로드합니다.
- 결과 문서를 DOCX로 저장
이 단계에서는 Aspose.Slides 및 Aspose.Words와 같은 두 개의 라이브러리를 동시에 사용하여 *C#*에서 PowerPoint를 Word로 내보내는 방법을 설명합니다. 먼저 Presentation 클래스를 사용하여 템플릿 PowerPoint 프레젠테이션을 로드한 다음 이 로드 프로세스를 사용자 지정하는 옵션과 함께 메모리 스트림에 HTML 파일로 저장합니다. 마지막 단계에서 이 메모리 스트림을 Document 클래스 개체에 로드한 다음 DOCX 파일에 저장합니다.
C#에서 PPTX를 DOCX로 변환하는 코드
using System.IO; | |
using Aspose.Slides; | |
using Aspose.Slides.Export; | |
namespace AsposeProjects | |
{ | |
class Program | |
{ | |
static void Main(string[] args) // Main function to convert PPTX to DOCX | |
{ | |
// Load Slides license | |
Aspose.Slides.License lic = new Aspose.Slides.License(); | |
lic.SetLicense(@"Aspose.Total.lic"); | |
// Load Words license | |
Aspose.Words.License lic2 = new Aspose.Words.License(); | |
lic2.SetLicense(@"Aspose.Total.lic"); | |
// Load the source presentation | |
Presentation pres = new Presentation("sample.pptx"); | |
// Create aa new memory stream | |
MemoryStream stream = new MemoryStream(); | |
// Save the loaded presentation as an HTML in the memory stream | |
pres.Save(stream, SaveFormat.Html); | |
// Create LoadOptions class object to customize the loading of the HTML format data | |
Aspose.Words.Loading.LoadOptions options = new Aspose.Words.Loading.LoadOptions() { LoadFormat = Aspose.Words.LoadFormat.Html }; | |
// Load memory stream into a Document class object | |
Aspose.Words.Document doc = new Aspose.Words.Document(stream, options); | |
// Save the loaded document as a DOCX file | |
doc.Save("output.docx"); | |
} | |
} | |
} |
이 코드는 소스 파일 이름만 제공하여 Presentation 클래스 개체를 사용하여 C#*에서 PPTX를 DOCX로 변환하는 프로세스를 보여주지만 Aspose.Slides 라이브러리의 LoadOptions 개체를 사용하여 암호 설정과 같은 다른 속성을 설정할 수 있습니다. 프레젠테이션은 암호로 보호되어 있으며 오류 또는 경고 발생 시 콜백 기능 설정 등 몇 가지 이름을 지정합니다.
이 자습서에서는 기존 프레젠테이션을 로드한 다음 Word 문서로 저장하여 PowerPoint를 C#의 Word 문서로 변환하는 방법을 배웠습니다. 기존 프레젠테이션을 로드하는 대신 새 프레젠테이션을 만드는 과정을 알아보려면 C#을 사용하여 PowerPoint 프레젠테이션을 만드는 방법 문서를 참조하세요.