1

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.

Aref Zamani
  • 2,023
  • 2
  • 20
  • 40
  • 2
    Have you tried to simply save the workbook directly into a MemoryStream to avoid creating the file on disk? (According to the aspose documentation that should be easily possible: [Saving File to a Stream](https://docs.aspose.com/display/cellsjava/Saving+Excel+files+to+CSV,+PDF+and+other+formats#SavingExcelfilestoCSV,PDFandotherformats-SavingFiletoaStream)). – bassfader Nov 20 '17 at 14:16

1 Answers1

2

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

shakeel
  • 1,717
  • 10
  • 14