These C# and Visual Basic .NET samples will show how to import data from list to Excel spreadsheet with Bytescout Spreadsheet SDK.
C#
using System.Collections; using System.Diagnostics; using System.IO; namespace Bytescout.Spreadsheet.Demo.Csharp.ImportFromList { class Program { static void Main(string[] args) { const string fileName = "CSharpImportFromList.xls"; // Create a new spreadsheet Spreadsheet spreadsheet = new Spreadsheet(); // Get the data from the 2D array that we want to import IList planets = GetList(); // Import data into spreadheet spreadsheet.ImportFromList(planets); // 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 list of planets /// </summary> /// <returns>List of planets</returns> private static IList GetList() { string[,] planets = new string[9,1]; planets[0,0] = "Mercury"; planets[1,0] = "Venus"; planets[2,0] = "Earth"; planets[3,0] = "Mars"; planets[4,0] = "Jupiter"; planets[5,0] = "Saturn"; planets[6,0] = "Uranus"; planets[7,0] = "Neptune"; planets[8,0] = "Pluto"; return planets; } } }
VB.NET
Imports System.IO Module Module1 Sub Main() Const fileName As String = "VBNetImportFromList.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 list As IList = GetList() 'Import data into spreadheet spreadsheet.ImportFromList(list) '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 list of planets ''' </summary> ''' <returns>A list of planets</returns> ''' <remarks></remarks> Function GetList() As IList Dim planets(9, 1) As String planets(0, 0) = "Mercury" planets(1, 0) = "Venus" planets(2, 0) = "Earth" planets(3, 0) = "Mars" planets(4, 0) = "Jupiter" planets(5, 0) = "Saturn" planets(6, 0) = "Uranus" planets(7, 0) = "Neptune" planets(8, 0) = "Pluto" Return planets End Function End Module