翻譯|使用教程|編輯:李顯亮|2020-11-20 09:51:54.637|閱讀 444 次
概述:Spire.Doc for Java 是一款專業(yè)的Java Word組件,開發(fā)人員使用它可以輕松地將Word文檔創(chuàng)建、讀取、編輯、轉(zhuǎn)換和打印等功能集成到自己的Java應(yīng)用程序中。本文將介紹如何將外部文件插入Java中的Word文檔。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Spire.Doc for Java 是一款專業(yè)的Java Word組件,開發(fā)人員使用它可以輕松地將Word文檔創(chuàng)建、讀取、編輯、轉(zhuǎn)換和打印等功能集成到自己的Java應(yīng)用程序中。
Spire.Doc for Java支持將外部文件(Word,Excel,PowerPoint,PDF,圖片,視頻等)作為OLE對(duì)象嵌入到Word文檔中。本文為您提供了一個(gè)如何將PDF文件插入Word文檔的示例。可點(diǎn)擊此處下載最新版測(cè)試。
示例代碼如下:
import com.spire.doc.Document; import com.spire.doc.FileFormat; import com.spire.doc.Section; import com.spire.doc.documents.OleObjectType; import com.spire.doc.documents.Paragraph; import com.spire.doc.fields.DocOleObject; import com.spire.doc.fields.DocPicture; public class InsertOLE { public static void main(String[] args) { //Create a Document object and load a Word document Document doc = new Document(); doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\source.docx"); //Get the last section Section section = doc.getLastSection(); //Add a paragraph Paragraph par = section.addParagraph(); //Load an image which will be inserted to Word document representing the embedded file DocPicture pdfIcon = new DocPicture(doc); pdfIcon.loadImage("C:\\Users\\Administrator\\Desktop\\pdf-icon.jpg"); //Insert a PDF file to the Word document as an OLE object par.appendOleObject("C:\\Users\\Administrator\\Desktop\\report.pdf", pdfIcon, OleObjectType.Adobe_Acrobat_Document); //Save to another file doc.saveToFile("EmbedDocument.docx", FileFormat.Docx_2013); } }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn