本篇文章将介绍通过Spire.Doc for Java添加OLE到Word文档的方法。
import com.spire.doc.*;
import com.spire.doc.documents.OleLinkType;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.DocOleObject;
import com.spire.doc.fields.DocPicture;
public class AddOLE {
public static void main(String[]args){
//创建文档
Document doc = new Document();
//添加段落
Section sec = doc.addSection();
Paragraph paragraph = sec.addParagraph();
//加载图片,并添加ole对象,链接到Word文档
DocPicture picture = new DocPicture(doc);
picture.loadImage("tp.png");
DocOleObject ole = paragraph.appendOleObject("test.docx",picture, OleObjectType.Word_Document);
//保存文档
doc.saveToFile("AddOLE.docx",FileFormat.Docx_2013);
doc.dispose();
}
}
添加效果如下:双击图片可编辑链接的Word文档