How to apply border to an image in a worksheet in WinForms XlsIO?
Pictures in a worksheet can be formatted for a better view. XlsIO provides the feature to format pictures. This article explains how to apply borders to an image using XlsIO.
A picture added to a worksheet is referred to with the interface IPictureShape. The property Line in the interface allows setting border settings, which is shown in the code snippets below.
C#
ExcelEngine excelEngine = new ExcelEngine(); // Instantiate the Excel application object. IApplication application = excelEngine.Excel; // The workbook is opened. IWorkbook workbook; string inputPath = GetFullTemplatePath("Sample.xlsx"); workbook = application.Workbooks.Open(inputPath, ExcelOpenType.Automatic); // The first worksheet object in the worksheets collection is accessed. IWorksheet worksheet = workbook.Worksheets[0]; IPictureShape picShape = worksheet.Pictures.AddPicture(5, 3, @"..\..\Data\Img.png"); picShape.Line.ForeColor = Color.Red; picShape.Line.DashStyle = ExcelShapeDashLineStyle.Solid; picShape.Line.Weight = 3;
VB
Dim excelEngine As ExcelEngine = New ExcelEngine() ‘Instantiate the Excel application object. Dim application As IApplication = excelEngine.Excel 'The workbook is opened. Dim workbook As IWorkbook Dim inputPath As String = GetFullTemplatePath("Sample.xlsx") workbook = application.Workbooks.Open(inputPath, ExcelOpenType.Automatic) 'The first worksheet object in the worksheets collection is accessed. Dim worksheet As IWorksheet = workbook.Worksheets(0) Dim picShape As IPictureShape = worksheet.Pictures.AddPicture(5, 3, "..\..\Data\Img.png") picShape.Line.ForeColor = Color.Red picShape.Line.DashStyle = ExcelShapeDashLineStyle.Solid picShape.Line.Weight = 3
The sample illustrating this behavior can be downloaded here.
Take a moment to peruse the documentation where you can find basic Excel document processing options along with the features like import and export data, chart, formulas, conditional formatting, data validation, tables, pivot tables and protect the Excel documents, and most importantly, the PDF, CSV and Image conversions with code examples.
Conclusion
I hope you enjoyed learning about how to apply border to an image in a worksheet in WinForms XlsIO.
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!