Link Search Menu Expand Document

Export To DataTable - C#

Spreadsheet SDK sample in C# demonstrating ‘Export To DataTable’

Program.cs
using System;
using System.Data;

namespace Bytescout.Spreadsheet.Demo.Csharp.ExportToDataTable
{
    class Program
    {
        static void Main(string[] args)
        {
            const string inputFile = @"PeriodicTableOfElementsSpreadsheet.xls";

            // Open and load spreadsheet
            Spreadsheet spreadsheet = new Spreadsheet();
            spreadsheet.LoadFromFile(inputFile);

            // Get the data from the spreadsheet
            DataTable dt = spreadsheet.ExportToDataTable();

            // Close spreadsheet
            spreadsheet.Close();

            // Display array
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    Console.Write(dt.Rows[i][j] + " ");
                }
                Console.WriteLine();
            }

            // Pause
            Console.ReadLine();
        }
    }
}

Download Source Code (.zip)

Return to the previous page Explore Spreadsheet SDK