I already created a docx file by aspose.word and I need to embed an worksheet to this file thus I created a workbook and worksheet .
Document doc = new Document();
Workbook workbook = new Workbook();
int i = workbook.Worksheets.Add();
Worksheet sheet = workbook.Worksheets[i];
and after filling cells in the sheet I save my excel file in storage and embedded it to my docx by using insertOleObject
and pass file address to this method by using file stream.
workbook.Save(dir+"output.xlx");
Stream memStream = File.OpenRead(dir+"output.xlx");
Shape oleObject = builder.InsertOleObject(memStream, "Excel.Sheet.2",false,null);
but I want to embed a worksheet(or workbook) directly without using workbook.Save
method and Stream
object.
As bassfader shared, first save your Workbook to Memory Stream. Besides, you can convert your Memory Stream into Byte Array. Then you can use the same code as you have shown to insert Workbook (which is now in form of memory stream or byte array) as Ole Object in your MS-Word Document.
Note: I am working as Developer Evangelist at Aspose