在 Java 中將 PowerPoint 簡報轉換為 Word 文件
Contents
[
Hide
]
概覽
本文為開發人員提供一個使用 Aspose.Slides 與 Aspose.Words 將 PowerPoint 與 OpenDocument 簡報轉換為 Word 文件的解決方案。分步指南將引導您完成轉換過程的每個階段。
將 PowerPoint 轉換為 Word
請依照下列說明將 PowerPoint 或 OpenDocument 簡報轉換為 Word 文件:
- 下載 Aspose.Slides for Java 與 Aspose.Words for Java 程式庫。
- 將 aspose-slides-x.x-jdk16.jar 與 aspose-words-x.x-jdk16.jar 加入您的 CLASSPATH。
- 使用以下程式碼片段將 PowerPoint 轉換為 Word:
Presentation pres = new Presentation("sample.pptx");
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
for (ISlide slide : pres.getSlides()) {
// 產生投影片圖像為位元組陣列串流
IImage image = slide.getImage(1, 1);
ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
image.save(imageStream, ImageFormat.Png);
image.dispose();
builder.insertImage(imageStream.toByteArray());
// 插入投影片的文字
for (IShape shape : slide.getShapes()) {
if (shape instanceof AutoShape) {
builder.writeln(((AutoShape) shape).getTextFrame().getText());
}
}
builder.insertBreak(BreakType.PAGE_BREAK);
}
doc.save("output.docx");
pres.dispose();
常見問答
需要安裝哪些元件才能將 PowerPoint 與 OpenDocument 簡報轉換為 Word 文件?
您只需將 Aspose.Slides for Java 與 Aspose.Words for Java 的相應套件新增至您的專案。兩個程式庫皆為獨立 API,無需安裝 Microsoft Office。
是否支援所有 PowerPoint 與 OpenDocument 簡報格式?
Aspose.Slides 支援所有簡報格式,包括 PPT、PPTX、ODP 以及其他常見檔案類型。這確保您可處理各版本 Microsoft PowerPoint 所建立的簡報。