How to import data from Jagged array to XLS spreadsheet 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 import data from Jagged array to XLS spreadsheet with Spreadsheet SDK

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

See below the samples of importing data from jagged array to Excel spreadsheet in C# and Visual Basic .NET using Bytescout Spreadsheet SDK.

C#

using System.Diagnostics;
using System.IO;

namespace Bytescout.Spreadsheet.Demo.Csharp.ImportFromJaggedArray
{
    class Program
    {
        static void Main(string[] args)
        {
            const string fileName = "CSharpImportFromJaggedArray.xls";
            
            // Create a new spreadsheet
            Spreadsheet spreadsheet = new Spreadsheet();

            // Get the data from the jagged array that we want to import
            string[][] periodicTable = GetJaggedArray();

            // Import data into spreadheet
            spreadsheet.ImportFromJaggedArray(periodicTable);

            // Save the spreadsheet
            if (File.Exists(fileName)) File.Delete(fileName);
            spreadsheet.SaveAs(fileName);

            // Close spreadsheet
            spreadsheet.Close();
            
            // Open the spreadsheet
            Process.Start(fileName);
        }

        /// <summary>
        /// Creates a jagged array of the period table of elements
        /// </summary>
        /// <returns>Jagged array of the periodic table of elements</returns>
        private static string[][] GetJaggedArray()
        {
              string[][] periodicTable = {
                           new string[] {"H","He"},
                           new string[] {"Li","Be","B","C", "N", "O", "F", "Ne"},
                           new string[] {"Na","Mg","Al","Si", "P", "S", "Cl", "Ar"},
                           new string[] {"K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr"}
                        };
            return periodicTable;
        }
    }
}

VB.NET

Imports System.IO

Module Module1

    Sub Main()
        Const fileName As String = "VBNetImportFromJaggedArray.xls"

        'Create a new spreadsheet
        Dim spreadsheet As Bytescout.Spreadsheet.Spreadsheet = New Bytescout.Spreadsheet.Spreadsheet

        'Get the data from the jagged array that we want to import
        Dim periodicTable()() As String = GetJaggedArray()

        'Import data into spreadheet
        spreadsheet.ImportFromJaggedArray(periodicTable)

        'Save the spreadsheet
        If (File.Exists(fileName)) Then
            File.Delete(fileName)
        End If
        spreadsheet.SaveAs(fileName)

        'Close spreadsheet
        spreadsheet.Close()

        'Open the spreadsheet
        Process.Start(fileName)
    End Sub

    ''' <summary>
    ''' Creates a jagged array of the period table of elements
    ''' </summary>
    ''' <returns>Jagged array of the periodic table of elements</returns>
    Function GetJaggedArray() As String()()

        Dim periodicTable = {
            New String() {"H", "He"},
            New String() {"Li", "Be", "B", "C", "N", "O", "F", "Ne"},
            New String() {"Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar"},
            New String() {"K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr"}
            }

        Return periodicTable
    End Function

End Module

Tutorials:

prev
next