EXCEL Write Images in C#, VB.NET

  • Demo
  • C# source
  • VB.Net source
 

The sample demonstrates how to write images to spreadsheet.

WriteImages.gif

		private void btnRun_Click(object sender, System.EventArgs e)
		{
			Workbook workbook = new Workbook();
			Worksheet sheet = workbook.Worksheets[0];

			sheet.Pictures.Add(1,1,@"..\..\..\..\..\..\Data\day.jpg");

			workbook.SaveToFile("sample.xls");
			ExcelDocViewer(workbook.FileName);
			
		}


		private void ExcelDocViewer( string fileName )
		{
			try
			{
				System.Diagnostics.Process.Start(fileName);
			}
			catch{}
		}

		Private Sub btnRun_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRun.Click
			Dim workbook As Workbook = New Workbook()
			Dim sheet As Worksheet = workbook.Worksheets(0)

			sheet.Pictures.Add(1,1,"..\..\..\..\..\..\Data\day.jpg")

			workbook.SaveToFile("sample.xls")
			ExcelDocViewer(workbook.FileName)

		End Sub

		Private Sub ExcelDocViewer(ByVal fileName As String)
			Try
				System.Diagnostics.Process.Start(fileName)
			Catch
			End Try
		End Sub