How to export data from XLS spreadsheet to DataSet with Spreadsheet SDK - ByteScout
announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More show modal
X
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!
show modal
Introducing PDF.Co
Try PDF.co for document processing & automation via Web APIs
Learn More show modal
show modal
Introducing MuPDF
Try MuPDF.NET for advanced document processing solutions in your .NET environment
Learn More show modal

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

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

This source code sample will show how to export data from XLS spreadsheet to dataset in C# and Visual Basic .NET using Bytescout Spreadsheet SDK.

C#

using System;
using System.Data;

namespace Bytescout.Spreadsheet.Demo.Csharp.ExportToDataSet
{
    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
            DataSet dataSet = spreadsheet.ExportToDataSet();

            // Close spreadsheet
            spreadsheet.Close();

            // Display data in the first data table in the dataset
            DataTable dt = dataSet.Tables[0];
            Console.WriteLine("Displaying contents of first datatable");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    Console.Write(dt.Rows&#91;i&#93;&#91;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 = "PeriodicTableOfElementsSpreadsheet.xls"

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

        'Get the data from the spreadsheet
        Dim ds As DataSet = spreadsheet.ExportToDataSet()

        'Close spreadsheet
        spreadsheet.Close()

        'Display data in first datatable of dataset
        Dim dt As DataTable = ds.Tables(0)
        Console.WriteLine("Displaying contents of first datatable")
        For i As Integer = 0 To dt.Rows.Count - 1
            For j As Integer = 0 To dt.Columns.Count - 1

                Console.Write(dt.Rows(i)(j) + " ")
            Next
            Console.WriteLine()
        Next

        'Pause
        Console.ReadLine()
    End Sub

End Module

Tutorials:

prev
next