I tried to create an Excel document which contains another Excel (Emulating the function using Excel menu insert > object > Create from File > Display as icon).
I found the sample code from
The following changed code generate an Excel with an image icon embeded in sheet 1 cell (0,0). But when I double click the icom, error happens "Cannot start the source application for this object".
Could you please send me the sample code to do the work? Thanks.
//Instantiate a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
//Define a string variable to store the image path.
string ImageUrl = @"C:\Temp\Excel.jpg";
//Get the picture into the streams.
FileStream fs = File.OpenRead(ImageUrl);
//Define a byte array.
byte[] imageData = new Byte[fs.Length];
//Obtain the picture into the array of bytes from streams.
fs.Read(imageData, 0, imageData.Length);
//Close the stream.
fs.Close();
//Get an excel file path in a variable.
string path = @"C:\Temp\LookupTable.xlsx";
//Get the file into the streams.
fs = File.OpenRead(path);
//Define an array of bytes.
byte[] objectData = new Byte[fs.Length];
//Store the file from streams.
fs.Read(objectData, 0, objectData.Length);
//Close the stream.
fs.Close();
//Add an Ole object into the worksheet with the image
//shown in MS Excel.
sheet.OleObjects.Add(0, 0, 100, 100, imageData);
//Set embedded ole object data.
sheet.OleObjects[0].ObjectData = objectData;
workbook.Save(@"C:\Temp\MyExcel.xlsx", new OoxmlSaveOptions(SaveFormat.Xlsx));