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

Free Support Forum - aspose.com

Embedding Excel sheet into word not as Icon

Does ASPOSE have solution for embedding Excel Sheet in to word (not as attachment but a viewable cell block in word)?


Can this be done without converting into PDF. My firm doesn’t have aspose PDF license. I am able to insert a excel into word as icon by the following code:

string oWordTemplate = sTemplatePath.TrimEnd();
asWord = new Document(oWordTemplate);
DocumentBuilder asBuilder = new DocumentBuilder(asWord);
var asShape = asBuilder.InsertOleObject(sExcelFile, true, true, null);
asWord.Save(sWordFile);

or even by

Stream memStream = File.OpenRead(sExcelFile);
var asShape = asBuilder.InsertOleObject(memStream,“Excel.Sheet.8”,true,null);
asWord.Save(sWordFile);

But as soon as I turn the isIcon flag false, the doc becomes empty. The mentioned file has only one sheet and also I have attached the desired result word doc.

Hi,

Thanks for your posting and using Aspose APIs.

You are inserting excel into word as OLE object which is a right approach. However, this question is not related to Aspose.Cells because you are not embedding word into excel but you are doing reverse so this question is related to Aspose.Words. Therefore, I am moving your thread to Aspose.Words forum.

Also, you have provided the expected output word file, please also provide actual output word file. Aspose.Words team will look into your issue and help you asap.

Hi,


Thanks for your inquiry. Aspose.Cells supports converting Excel worksheets to images. A simple solution would be to just convert Worksheet to image and then use that preview image in DocumentBuilder.InsertOleObject method as follows:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

Stream memoryStream = File.OpenRead(MyDir + "Worksheet in Test.xls");

Shape oleObject = builder.InsertOleObject(memoryStream, "Excel.Sheet.8", false, Image.FromFile(MyDir + "SheetImage.jpg"));

doc.Save(MyDir + @"out.docx");


Hope, this helps.

Best regards,

Thanks for your prompt reply Hafeez. My company wants the excel to embedded into word not image, since they want to keep the option of updating the data. So is there anyway through aspose I could get the above attached file as output.

Hi,

Thanks for your inquiry. Well, you can insert/display excel file as an image in Word document. This embedded excel file in Word document is represented as a Shape node in Aspose.Words' DOM; you can loop through Shape nodes collection and get reference to the original object. You can modify the excel file using Aspose.Cells as follows:

Document doc = new Document(@"C:\test\embeddedDocument.docx");

// Get collection of shapes

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

int i = 0;

//Loop through all shapes

foreach (Shape shape in shapes)

{

if (shape.OleFormat != null)

{

if (!shape.OleFormat.IsLink)

{

//Extract OLE Excel object

if (shape.OleFormat.ProgId == "Excel.Sheet.12")

{

// Here you can use Aspose.Cells component

// to be able to convert MS Excel files to PDF

}

}

}

}

doc.Save(@"C:\test\out.docx");


You can insert it as a new OLE object using the code mentioned in my previous post and of-course after that remove the old Shape. You can insert new Shape after the old Shape using the CompositeNode.InsertAfter method.

Hope, this helps.

Best regards,

That solves it. Thanks!