Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWord
>
Tutorial
> Insert Excel workbook
The example shows you how to insert excel workbook in the word document.
import com.independentsoft.office.vml.EmbeddedOleObject; import com.independentsoft.office.vml.Image; import com.independentsoft.office.vml.OleDrawAspect; import com.independentsoft.office.vml.OleType; import com.independentsoft.office.vml.Shape; import com.independentsoft.office.vml.ShapeStyle; import com.independentsoft.office.word.EmbeddedObject; import com.independentsoft.office.word.Paragraph; import com.independentsoft.office.word.Run; import com.independentsoft.office.word.WordDocument; public class Example { public static void main(String[] args) { try { WordDocument doc = new WordDocument(); EmbeddedObject embeddedObject = new EmbeddedObject(); ShapeStyle imageShapeStyle = new ShapeStyle(); imageShapeStyle.setWidth("76pt"); imageShapeStyle.setHeight("48pt"); Shape imageShape = new Shape(); imageShape.setID("Shape1"); imageShape.setStyle(imageShapeStyle); Image image = new Image("c:\\test\\image1.emf"); //excel icon image.setTitle("image1"); //important imageShape.getContent().add(image); EmbeddedOleObject oleObject = new EmbeddedOleObject("c:\\test\\workbook.xlsx"); oleObject.setType(OleType.EMBEDDED_OBJECT); oleObject.setApplication("Excel.Sheet.12"); oleObject.setShapeID("Shape1"); oleObject.setDrawAspect(OleDrawAspect.ICON); oleObject.setObjectID("123"); embeddedObject.getContent().add(imageShape); embeddedObject.getContent().add(oleObject); Run run1 = new Run(); run1.add(embeddedObject); Paragraph paragraph1 = new Paragraph(); paragraph1.add(run1); doc.getBody().add(paragraph1); doc.save("c:\\test\\output.docx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*