How to export data from XLS spreadsheet to Jagged array with Spreadsheet SDK

  • Home
  • /
  • Articles
  • /
  • How to export data from XLS spreadsheet to Jagged array with Spreadsheet SDK

This example will help you in exporting data from XLS spreadsheet to jagged array in C# and Visual Basic .NET using Bytescout Spreadsheet SDK.

C#

using System;

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

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

            // Get the data from the spreadsheet
            string[][] stockPrices = spreadsheet.ExportToJaggedArray();

            // Close spreadsheet
            spreadsheet.Close();

            // Display data in jagged array
            for (int i = 0; i < stockPrices.GetLength(0); i++)
            {
                Console.Write(stockPrices&#91;i&#93;&#91;0&#93; + " ");
                Console.Write(stockPrices&#91;i&#93;&#91;1&#93; + " ");
                Console.WriteLine();
            }

            // Pause
            Console.ReadLine();
        }
    }
}
&#91;/vb&#93;
<p><strong>VB.NET</strong></p>
Module Module1

    Sub Main()
        Dim inputFile As String = "StockPricesSpreadsheet.xls"

        'Open and load spreadsheet
        Dim spreadsheet = New Spreadsheet()
        spreadsheet.LoadFromFile(inputFile)

        'Get the data from the spreadsheet
        Dim stockPrices()() As String = spreadsheet.ExportToJaggedArray()

        'Close spreadsheet
        spreadsheet.Close()

        'Display data in jagged array
        For i As Integer = 0 To stockPrices.GetLength(0) - 1
            Console.Write(stockPrices(i)(0) + " ")
            Console.Write(stockPrices(i)(1) + " ")
            Console.WriteLine()
        Next

        'Pause
        Console.ReadLine()
    End Sub

End Module

prev
next