Re: Embedding Excel sheet into word

hi

It works perfectly fine only problem I am facing is when I do an add ole object which is an excel file in my case I want to see the excel itself embedded on the word document what do I do for this.

Hi,

Thanks for your inquiry. Aspose.Cells supports converting Excel worksheets to images. A simple solution would be to just convert Worksheet to image and then use that preview/thumbnail image in DocumentBuilder.InsertOleObject method as follows:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Stream memoryStream = File.OpenRead(MyDir + "Worksheet.xls");
Shape oleObject = builder.InsertOleObject(memoryStream, "Excel.Sheet.8", false, Image.FromFile(MyDir + "SheetImage.jpg"));
doc.Save(MyDir + @"out.docx");

Hope, this helps.

Best regards,

let me re iterate the question.

what will it be if i have to preview an excel which is added as on ole.
for now i see the excel icon and once i double click that i can see data but what i want is the excel itself shows up in the word document.
Please let me know

I tried this

Shape oleObject = builder.insertOleObject("AccessingOleFrameData.xls", "Excel.Sheet.8", false,false , null);

doc.save("out.docx");

i get an error as

Exception in thread "main" java.lang.IllegalStateException: This is not a structured storage file.
at asposewobfuscated.zzRU.(Unknown Source)
at asposewobfuscated.zzT2.(Unknown Source)
at com.aspose.words.zzZ9D.zzZ(Unknown Source)
at com.aspose.words.zzZ9D.zzj(Unknown Source)
at com.aspose.words.zzZ9D.zzT(Unknown Source)
at com.aspose.words.DocumentBuilder.zzZ(Unknown Source)
at com.aspose.words.DocumentBuilder.insertOleObject(Unknown Source)

Hi Syeda,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

Your input Word document
The Excel file (AccessingOleFrameData.xls) you’re trying to embed or want to see preview of
Aspose.Words generated output DOCX file showing the undesired behavior
Please attach your expected document here for our reference. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document using Microsoft Word.
Please create a standalone console application (source code without compilation errors) that helps us reproduce your problem/error on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start further investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,

hi…for some reason my previous post got deleted.
PFA the file and details attached.
please check the output_expected.docx which explains my problem.
Please check and let me know at the earliest.

Hi,

Thanks for your inquiry. As mentioned earlier, Aspose.Cells for Java supports converting Excel worksheets to images. A simple solution would be to just convert Worksheet to image (either page by page or convert entire worksheet to one image) and then use that image in DocumentBuilder.InsertOleObject method as follows:.

You can pass any of the images to DocumentBuilder.InsertOleObject method as follows:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
BufferedImage image = ImageIO.read(new File("D:\\temp\\aspose\\entire.png"));
Shape oleObject = builder.insertOleObject("D:\\temp\\aspose\\interview.xlsx", true, false, image );
doc.save("D:\\temp\\aspose\\awjava-17.2.0.docx");

Please see attached Aspose.Cells for Java generated image files and Aspose.Words for Java generated output DOCX file.

Hope, this helps.

Best regards,

Thanks for the quick reply.

The problem is as per my requirement when I double click on the ole
i.e the excel on word document ,the preview should change when i click on different tabs on excel in the document.

Is this possible in the licensed version?

Please let me know of the possiblities .

Hi,

Thanks for your inquiry. Please attach your expected Word document (with Excel file embedded inside such that when you double click, the preview should change when you click on different tabs on Excel in the document) here for our reference. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document using Microsoft Word.

Best regards,