Hi Team,
Hi,
Thanks for your posting and using Aspose.Cells for Java.
Yes, it is possible to embed MS-Word document into MS-Excel document as an Ole object using Aspose.Cells for Java.
Please see the code below.
I have attached the source docx Microsoft Word file which has been embedded as OLE object into output xlsx file. I have also attached the output.xlsx file generated by this code.
Please also see the screenshot for more help.
The code is fully commented so it will not be difficult for you to understand
Java
//This is your image file, you can use any
String imgFile =“D:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Blue hills.jpg”;
//This is your docx file, you can also use Aspose.Words to create docx file programmatically
String docFile =“F:/Shak-Data-RW/Downloads/source.docx”;
//We need the byte[] byte array for both image and docx file to continue
File file = new File(imgFile);
byte[] binaryImg = new byte[(int)file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(binaryImg);
file = new File(docFile);
byte[] binaryDoc = new byte[(int)file.length()];
fis = new FileInputStream(file);
fis.read(binaryDoc);
//Insert OLE object into a workbook
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
int idxOle = worksheet.getOleObjects().add(4, 4, 200, 200, binaryImg);
OleObject objOle = worksheet.getOleObjects().get(idxOle);
objOle.setObjectData(binaryDoc);
objOle.setProgID(“Document”);
objOle.setSourceFullName(“source.docx”);
workbook.save(“F:/Shak-Data-RW/Downloads/output.xlsx”);
Hi Faiz,
Hi Team/Faiz,
Hi,
Thanks for your posting and using Aspose.Cells for Java.
Well, you will have to specify the image for your ole object to make it work. You can choose the cell in which you want to insert the ole object. This is specified in the worksheet.getOleObjects().add(4, 4, 200, 200, binaryImg) method.
For more information on the ole object, please see the following documentation article for your reference.
http://www.aspose.com/docs/display/cellsjava/Managing+OLE+Objects