Link Search Menu Expand Document

Copy Range - C#

Spreadsheet SDK sample in C# demonstrating ‘Copy Range’

Program.cs
using System.Diagnostics;
using System.IO;
using Bytescout.Spreadsheet;

namespace CopyRange
{
    class Program
    {
        static void Main(string[] args)
        {
            // Open spreadsheet from file
            Spreadsheet document = new Spreadsheet();
            document.LoadFromFile("example.xls");

            // Get first worksheet
            Worksheet worksheet = document.Workbook.Worksheets[0];

            // Select cell range
            Range range = worksheet.Range("A2:B8");

            // Copy range to C10 cell
            range.CopyInto("C10");

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

            // Save document
            document.SaveAs("changed.xls");

            // Close spreadsheet
            document.Close();

            // Open generated XLS document in default program
            Process.Start("changed.xls");
        }
    }
}

Download Source Code (.zip)

Return to the previous page Explore Spreadsheet SDK


Copyright © 2016 - 2021 ByteScout