Convert Excel file to word doc with selected worksheets using Aspose.Cells for .NET in C#

Hi, I am trying to see if ASPOSE.total library can export an Excel Sheet into a page within a word doc. Please shared any samples you can guide or confirm this is available within the library.

Thank you!

Hi,


There are two ways to accomplish your task.
e.g

1) Convert Excel sheet to image file - Aspose.Cells provides Sheet to Image feature (see the document for your reference: https://docs.aspose.com/display/cellsnet/Converting+Worksheet+to+Image+in+Aspose.Cells), so you may convert an Excel sheet to image and then insert that image to word document via Aspose.Words APIs.

2) Insert Excel files as embedded Ole Object into word document - you can insert MS Excel files into word document using DocumentBuilder.InsertOleObject method of Aspose.Words APIs. Please check the following code example.

Insert embedded Excel 97-2003 document as iconic OLE object from stream using predefined image:
e.g
Sample code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

Stream memoryStream = File.OpenRead(MyDir + “Book1.xls”);

Shape oleObject = builder.InsertOleObject(memoryStream, “Excel.Sheet.8”, true, null);

doc.Save(MyDir + @“out.docx”);

Hope, this helps a bit.

Thank you.

Thanks for your reply Amjad,



My problem is reading from existing Excel Workbook (ASPOSE) and supplying it via builder.insertOleObject method which its looking for inputstream. Can you tell me how I can take an existing Excel Workbook object (ASPOSE) and choose a sheet (#3) and insert it via OLE (editable) word doc?



I am not sure if we can read existing workbook and be able to choose the excel tab to insert via the insertOleObject method.

Hi,


Well, you may try to use Aspose.Cells APIs to read the Workbook and then save it to memory streams. Before saving to memory stream, see the documents for your reference:

Before, saving to memory streams, you may hide your unwanted worksheets and make your desired sheet active using Aspose.Cells APIs if it works for you.

Thank you.


I am already using ASPOSE.cell to get my Workbook. I need to be able to select a few excel tab from the workbook getWorksheets into the word doc. I need to know if we can do that and paste it into using DocumentBuilder with insertOleObject method.



How do I selectively read the ASPOSE workbook and select the tab I need into input stream. There is no method I can see in the ASPOSE.cell library to convert into input stream. Please advice

Hi,


Well, Aspose.Cells would save the final Excel file to streams/ output streams and you have to write your own JAVA codes to try to convert to InputStream from OutputStream or create InputStream from OutputStream, you may seek help browsing the internet for your needs.

And, to load your desired worksheets from the Excel into Workbook object (via Aspose.Cells), please see the document for your reference (the document is for .NET APIs but you may use the corresponding Aspose.Cells for JAVA APIs accordingly):
https://docs.aspose.com/display/cellsnet/Load+Specific+Sheets+in+a+Workbook


Thank you.