Link Search Menu Expand Document

Add Images to Spreadsheet - C#

Spreadsheet SDK sample in C# demonstrating ‘Add Images to Spreadsheet’

Program.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using Bytescout.Spreadsheet;

namespace AddImages
{
	class Program
	{
		static void Main(string[] args)
		{
			// Create spreadsheet
			Spreadsheet doc = new Spreadsheet();
			// Add worksheet
			Worksheet worksheet = doc.Worksheets.Add();

			// Put an image on the worksheet with 10 pixel margin from the top-left corner of the worksheet
			worksheet.Pictures.Add("image1.jpg", 10, 10);
			// Put second image to 200 pixel offset and resize it to 250x200 px
			worksheet.Pictures.Add("image2.jpg", 200, 200, 250, 200);

			// Delete output file if exists
			if (File.Exists("output.xls"))
			{
				File.Delete("output.xls");
			}

			// Save document
			doc.SaveAs("output.xls");

			// Close spreadsheet
			doc.Close();

			// Open generated XLS document in default application
			Process.Start("output.xls");

			doc.Dispose();
		}
	}
}

Download Source Code (.zip)

Return to the previous page Explore Spreadsheet SDK