How to export data from XLS spreadsheet to list with Spreadsheet SDK - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

How to export data from XLS spreadsheet to list with Spreadsheet SDK

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

These C# and Visual Basic .NET code samples show how to export data from Excel document to list and display the result array with Bytescout Spreadsheet SDK.

C#

using System;
using System.Collections;

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

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

            // Get the data from the spreadsheet
            IList planets = new string[10, 10];
            spreadsheet.ExportToList(planets);

            // Close spreadsheet
            spreadsheet.Close();

            // Display array
            string[,] planetsArray = planets as string[,];
            for (int i = 0; i < planetsArray.GetLength(0); i++)
            {
                for (int j = 0; j < planetsArray.GetLength(1); j++)
                {
                    Console.Write(planetsArray&#91;i, j&#93; + " ");
                }
                Console.WriteLine();
            }

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

    Sub Main()
        Dim inputFile As String = "ListOfPlanetsSpreadsheet.xls"
        
        'Open and load spreadsheet
        Dim spreadsheet As Spreadsheet = New Spreadsheet()
        spreadsheet.LoadFromFile(inputFile)

        'Get the data from the spreadsheet
        Dim planets(10, 2) As String
        spreadsheet.ExportToList(planets)

        'Close spreadsheet
        spreadsheet.Close()

        'Display array
        Dim planetsArray(,) As String = planets
        For i As Integer = 0 To planetsArray.GetLength(0) - 1
            For j As Integer = 0 To planets.GetLength(1) - 1
                Console.Write(planetsArray(i, j) + " ")
            Next
            Console.WriteLine()
        Next

        'Pause
        Console.ReadLine()
        
    End Sub

End Module

Tutorials:

prev
next