Insert Pictures in Excel from VB.NET

The following VB.NET program demonstrates the process of inserting a picture into an Excel document. To accomplish this, we utilize the AddPicture method, which allows us to specify the PictureName along with its corresponding path, as well as the positional attributes such as Left, Top, Width, and Height.

By invoking the AddPicture method and providing the necessary parameters, we can seamlessly integrate images into our Excel files. This functionality enables us to enhance the visual appeal and overall quality of our Excel documents, making them more engaging and informative.

When working with pictures in Excel, it is crucial to ensure the accuracy of the specified PictureName and its corresponding path. Additionally, proper consideration should be given to the positioning of the picture within the Excel document, as the values for Left, Top, Width, and Height directly impact its placement and size.

excel_picture_insert.JPG

By incorporating pictures into our Excel files, we can effectively convey information, illustrate concepts, and create visually appealing reports or presentations. This adds depth and clarity to our data, allowing for more effective communication and analysis.

Full Source VB.NET
Imports Excel = Microsoft.Office.Interop.Excel Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet Dim misValue As Object = System.Reflection.Missing.Value xlApp = New Excel.ApplicationClass xlWorkBook = xlApp.Workbooks.Add(misValue) xlWorkSheet = xlWorkBook.Sheets("sheet1") 'add some text xlWorkSheet.Cells(1, 1) = "https://net-informations.com/vb/default.htm" xlWorkSheet.Cells(2, 1) = "Adding picture in Excel File" 'replace you picture to xl_pic.JPG xlWorkSheet.Shapes.AddPicture("C:\xl_pic.JPG", _ Microsoft.Office.Core.MsoTriState.msoFalse, _ Microsoft.Office.Core.MsoTriState.msoCTrue, 50, 50, 300, 45) xlWorkSheet.SaveAs("C:\vbexcel.xlsx") xlWorkBook.Close() xlApp.Quit() releaseObject(xlApp) releaseObject(xlWorkBook) releaseObject(xlWorkSheet) MsgBox("Excel file created , you can find the file c:\") End Sub Private Sub releaseObject(ByVal obj As Object) Try System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) obj = Nothing Catch ex As Exception obj = Nothing Finally GC.Collect() End Try End Sub End Class

When you execute this program , you will get an Excel file (C:\vbexcel.xlsx) with insert the picture.