Embed Pdf in excel file

I emmbedded a pdf file in excel using aspose, but when i open the excel file and double click on the pdf icon it gets opened in excel and outside also. i dont want it to be opened in excel file

string ImageUrl = ConfigurationManager.AppSettings["PdfImageUrl"];//@"C:\Users\ramanam\Desktop\EmbedFile\New folder\pdficon.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 pdf file path in a variable.
string path = ConfigurationManager.AppSettings["PdfUrl"];
//@"C:\Users\ramanam\Documents\Visual Studio 2010\Projects\PyramidFTP\PyramidFTP\Uploads\Report\6962\74ff6420-dff2-4d45-be83-fb74d01db44f.pdf";
//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();
sheetReport.OleObjects.Add(r + 1, dt2.Columns.Count, 40, 40, imageData);
//Set embedded ole object data.
sheetReport.OleObjects[r].ObjectData = objectData;
//FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Document.doc");
sheetReport.OleObjects[r].FileFormatType = FileFormatType.Pdf;

Hi Ramna,

Thanks for your posting and using Aspose.Cells.

Please set OleObject.DisplayAsIcon as true and it should fix your issue. Please add the following line inside your code.

sheetReport.OleObjects[r].DisplayAsIcon = true;

It will now open your pdf outside MS-Excel.

C#
string ImageUrl =
ConfigurationManager.AppSettings[“PdfImageUrl”];//@“C:\Users\ramanam\Desktop\EmbedFile\New
folder\pdficon.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 pdf file path in a variable.
string path = ConfigurationManager.AppSettings[“PdfUrl”];

//@“C:\Users\ramanam\Documents\Visual Studio
2010\Projects\PyramidFTP\PyramidFTP\Uploads\Report\6962\74ff6420-dff2-4d45-be83-fb74d01db44f.pdf”;
//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();
sheetReport.OleObjects.Add(r + 1, dt2.Columns.Count, 40, 40, imageData);
//Set embedded ole object data.
sheetReport.OleObjects[r].ObjectData = objectData;
sheetReport.OleObjects[r].DisplayAsIcon = true;
//FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + “Document.doc”);
sheetReport.OleObjects[r].FileFormatType = FileFormatType.Pdf;

It worked, Thank you :slight_smile:

Hi Ramna,

Thanks for your feedback and using Aspose.Cells.

It is good to know that your issue is resolved now. Let us know if you encounter any other issue, we will be glad to look into it and help you further.