Link Search Menu Expand Document

Copy Worksheet Data To Clipboard - C#

Spreadsheet SDK sample in C# demonstrating ‘Copy Worksheet Data To Clipboard’

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

namespace CopyWorksheetDataToClipboard
{
    class Program
    {
        [STAThreadAttribute]
        static void Main(string[] args)
        {
            // Spreadsheet document
            using (Spreadsheet document = new Spreadsheet())
            {
                // Load Input File
                document.LoadFromFile("SimpleReport.xls");

                // Create stream and export CSV data to stream
                MemoryStream ms = new MemoryStream();
                document.Worksheets[0].SaveAsCSV(ms, "\t");

                // Convert memory stream to string
                var tabSeparatedData = Encoding.UTF8.GetString(ms.ToArray());

                // Copy data to clipboard
                System.Windows.Forms.Clipboard.SetText(tabSeparatedData);
            }

            Console.WriteLine("Data copied to clipboard!");
            Console.ReadLine();
        }
    }
}

Download Source Code (.zip)

Return to the previous page Explore Spreadsheet SDK


Copyright © 2016 - 2021 ByteScout