How to Place a PDF file Inside the WinForms Excel?
WinForms Excel document can be placed inside an Excel cell using the OLE objects concept available in Syncfusion® XlsIO. The concept of OLE helps to link or embed documents.
The following code snippet explains how to place a PDF document in an Excel cell.
C#
using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Excel2016; IWorkbook workbook = application.Workbooks.Create(1); IWorksheet sheet = workbook.Worksheets[0]; Image image = Image.FromFile("../../Data/Image.png"); // Select the object, image for the display icon and the type of the OLEObject to insert IOleObject ole = sheet.OleObjects.Add("../../Data/ExcelToPDF.pdf", image, OleLinkType.Embed); workbook.SaveAs("LinkedObjects.xlsx"); System.Diagnostics.Process.Start("LinkedObjects.xlsx"); }
VB.NET
Using excelEngine As ExcelEngine = New ExcelEngine Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Excel2016 Dim workbook As IWorkbook = application.Workbooks.Create(1) Dim sheet As IWorksheet = workbook.Worksheets(0) Dim image As Image = Image.FromFile("../../Data/Image.png") 'Select the object, image for the display icon and the type of the OLEObject to insert Dim ole As IOleObject = sheet.OleObjects.Add("../../Data/ExcelToPDF.pdf", image, OleLinkType.Embed) workbook.SaveAs("LinkedObjects.xlsx") System.Diagnostics.Process.Start("LinkedObjects.xlsx") End Using
A complete working C# sample can be downloaded from PDFInExcelCell.zip
Take a moment to peruse the documentation, where you can find basic worksheet data manipulation options along with features like Conditional Formatting, worksheet calculations through Formulas, adding Charts in worksheets or workbooks, organizing and analyzing data through Tables and Pivot Tables, appending multiple records to worksheets using Template Markers, and most importantly PDF and Image conversions with code examples.
Refer here to explore the rich set of Syncfusion Essential® XlsIO features.
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion® license key in your application to use the components without trial message
Conclusion
I hope you enjoyed learning about how to place a PDF file inside the WinForms Excel.
You can refer to our XIsIO’s feature tour page to learn about its other groundbreaking features. Explore our UG documentation and online demos to understand how to manipulate data in Excel documents.
If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion components.
If you have any queries or require clarification, please let us know in the comments below or contact us through our support forums, Support Tickets, or feedback portal. We are always happy to assist you!