This sample shows how to get data from XLS spreadsheet and export them to two-dimensional (2D) arrays in C# and Visual Basic .NET using Bytescout Spreadsheet SDK.
C#
using System; namespace Bytescout.Spreadsheet.Demo.Csharp.ExportTo2DArray { 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.ExportTo2DArray(); // Close spreadsheet spreadsheet.Close(); // Display data in data table for(int i = 0; i < stockPrices.GetLength(0); i++) { for(int j = 0; j < stockPrices.GetLength(1); j++) { Console.Write(stockPrices[i,j] + " "); } Console.WriteLine(); } // Pause Console.ReadLine(); } } } [/vb] <p><strong>VB.NET</strong></p> [vb]Module Module1 Sub Main() Dim inputFile As String = "StockPricesSpreadsheet.xls" 'Open and load spreadsheet Dim spreadsheet As Spreadsheet = New Spreadsheet spreadsheet.LoadFromFile(inputFile) 'Get the data from the spreadsheet Dim stockPrices(,) As String = spreadsheet.ExportTo2DArray() 'Close spreadsheet spreadsheet.Close() 'Display contents of the array For i As Integer = 0 To stockPrices.GetLength(0) - 1 Step 1 For j As Integer = 0 To stockPrices.GetLength(1) - 1 Step 1 Console.Write(stockPrices(i, j) + " ") Next Console.WriteLine() Next 'Pause Console.ReadLine() End Sub End Module