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.


<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>ZH-CN</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin-top:0pt; mso-para-margin-right:0pt; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0pt; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–>

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.