Link Search Menu Expand Document

Add Image Into Existing Spreadsheet - C#

Spreadsheet SDK sample in C# demonstrating ‘Add Image Into Existing Spreadsheet’

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

namespace CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
			    // create new Spreadsheet object
                Spreadsheet spreadsheet = new Spreadsheet();
	spreadsheet.LoadFromFile("AdvancedReport.xls");

                // add new worksheet
                Worksheet sheet = spreadsheet.Workbook.Worksheets[0]; // get AdvancedReport worksheet

                // add a picture to worksheet
                sheet.Pictures.Add("image.jpg", 100, 100);
			
                if(File.Exists("Output.xls")){
                    File.Delete("Output.xls");
                }
                
                // Save it as XLS
                spreadsheet.SaveAs("Output.xls");

                // close the document
                spreadsheet.Close();

                // open output XLS
                Process.Start("Output.xls");


            }
            catch(Exception e){
                Console.WriteLine("CAN NOT EXECUTE: " + e.ToString());
                Console.WriteLine("\nPress any key to exit");
                Console.ReadKey();
            }

        }
    }
}

Download Source Code (.zip)

Return to the previous page Explore Spreadsheet SDK


Copyright © 2016 - 2021 ByteScout