We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

OLE Object questions in Word

Using the DocumentBuilder class I can successfully insert an OLE object, but when I double click that object, it doesn’t open in the word document but in a new window, and changes I make aren’t being updated on the word document if I update the excel sheet (it’s an embedded object).

I’d like to embed an excel file in a word document as an OLE object, and then open it and edit within the Word application. How can I do that?

Hi Ben,

Thanks for your inquiry. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v15.6.0) from here and let us know how it goes on your side. Please check following code example for your kind reference.

Document doc = new Document();
var builder = new DocumentBuilder(doc);
Stream stream = File.OpenRead(MyDir + "in.xlsx");
var shape = builder.InsertOleObject(stream, "Excel.Sheet.12", false, null);
doc.Save(MyDir + "Out.docx");

If the problem still remains, please attach your input Word and Excel documents here for testing. I will investigate the issue on my side and provide you more information.

This worked, thank you!
I was using the Workbook SaveToStream() method to pass in the stream variable, but this did not work well. Using the File.OpenRead fixed the issue!
New question! When I insert the new OLE object, how do I control how many rows and columns are displayed on the Document?

Hi Ben,

Thanks for your inquiry. DocumentBuilder.InsertOleObject method returns Shape node object. You may use Shape.Width and Shape.Height to set the size of OLE. Please let us know if you have any more queries.

I’m not interested in setting the height and width of the OLE object, I want to control how many rows show on the OLE object when I double click it. If the excel file only contains two rows, is there a way to tell the OLE object that I only want to see the rows that have data?
After I embed an Excel OLE object and save the word Document, I open it. The OLE embedded object shows rows 1-10 and columns A-G. Instead, I want it to show only cells that have data, for example: A1 - H2. How can I specify what range Excel OLE objects show?

Hi Ben,

Thanks for sharing the detail. Unfortunately, Aspose.Words does not support the requested feature. It would be great if you please share your expected output document here for our reference. We will then log the requested feature accordingly.