Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Fri Dec 23, 2022 11:15 pm

it is possible to insert an OleObjects in excel, and that the object is a pdf file?

I have seen that they have examples but for an image.


I would appreciate your answer.
Thanks.

PolloKulos
 
Posts: 7
Joined: Sun Mar 28, 2021 3:23 am

Mon Dec 26, 2022 9:17 am

Hi,

Thanks for your inquiry.
Please refer to the following code to achieve your requirement, if you have any further questions, just feel free to contact us.
Code: Select all
        static void Main(string[] args)
        {
            //load Excel file
            Workbook workbook = new Workbook();
            Worksheet ws = workbook.Worksheets[0];
            ws.Range["A1"].Text = "Here is an OLE Object.";
            //insert OLE object
            string pdfFile = "sample.pdf";
            Image image = GenerateImage(pdfFile);
            IOleObject oleObject = ws.OleObjects.Add(pdfFile, image, OleLinkType.Embed);
           
            oleObject.Location = ws.Range["B4"];
            oleObject.ObjectType = OleObjectType.AdobeAcrobatDocument;
            //save the file
            String result = "InsertOLEObjects_result.xlsx";
            workbook.SaveToFile(result, ExcelVersion.Version2010);
        }

        private static Image GenerateImage(string fileName)
        {

            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(fileName);
            return pdf.SaveAsImage(0);
           
        }



Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 999
Joined: Tue Nov 15, 2022 3:59 am

Mon Dec 26, 2022 4:46 pm

I have applied the code, and if I embed my file as an image type.

but I want to embed a pdf file, by clicking on it I can see the entire pdf document, that is possible?

Thanks

PolloKulos
 
Posts: 7
Joined: Sun Mar 28, 2021 3:23 am

Tue Dec 27, 2022 2:37 am

Hi,

Thanks for your feedback.
Kindly note that our Spire.XLS is based on MS Excel standard, when you insert an object in Excel manually, Excel will auto generate an icon and you need to double click it to open the linked object. For your requirement, I am afraid that it is not supported in Excel document at present.
If you have other questions, just feel free to contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 999
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.XLS