ByteScout Spreadsheet SDK - C# - Import From Dataset - ByteScout

ByteScout Spreadsheet SDK – C# – Import From Dataset

  • Home
  • /
  • Articles
  • /
  • ByteScout Spreadsheet SDK – C# – Import From Dataset

How to import from dataset in C# with ByteScout Spreadsheet SDK

This code in C# shows how to import from dataset with this how to tutorial

Import from dataset is easy to implement in C# if you use these source codes below. What is ByteScout Spreadsheet SDK? It is the SDK component for writing, reading, modifying and calculating Excel and CSV spreadsheets. Can calculate and reculculate formulas with Excel installed. You may import or export data to and from CSV, XML, JSON. Supports export to databases, arrays, streams. It can help you to import from dataset in your C# application.

Fast application programming interfaces of ByteScout Spreadsheet SDK for C# plus the instruction and the code below will help you quickly learn how to import from dataset. In your C# project or application you may simply copy & paste the code and then run your app! This basic programming language sample code for C# will do the whole work for you to import from dataset.

Our website provides trial version of ByteScout Spreadsheet SDK for free. It also includes documentation and source code samples.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

Program.cs
      
using System.Data; using System.Diagnostics; using System.IO; namespace Bytescout.Spreadsheet.Demo.Csharp.ImportFromDataSet { class Program { static void Main(string[] args) { const string fileName = "CSharpImportFromDataSet.xls"; // Create a new spreadsheet Spreadsheet spreadsheet = new Spreadsheet(); // Get the data from the dataset that we wish to import DataSet periodicTableAndScientists = GetDataSet(); // Import data into spreadheet spreadsheet.ImportFromDataSet(periodicTableAndScientists); // Insert row with column captions for (int i = 0; i < periodicTableAndScientists.Tables.Count; i++) { DataTable dataTable = periodicTableAndScientists.Tables[i]; Worksheet worksheet = spreadsheet.Worksheets[i]; worksheet.Rows.Insert(0); for (int colIndex = 0; colIndex < dataTable.Columns.Count; colIndex++) { worksheet.Cell(0, colIndex).Value = dataTable.Columns[colIndex].Caption; } } // 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 data set of the periodic table of elements and some famous scientists /// </summary> /// <returns>A data set of the periodic table of elements and some scientists</returns> private static DataSet GetDataSet() { DataTable periodicTable = GetDataTableOfElements(); DataTable scientists = GetDataTableOfScientists(); DataSet dataset = new DataSet(); dataset.Tables.Add(periodicTable); dataset.Tables.Add(scientists); return dataset; } /// <summary> /// Creates a data table of the periodic table of elements /// </summary> /// <returns>A data table of the periodic table of elements</returns> private static DataTable GetDataTableOfElements() { DataTable periodicTable = new DataTable("PeriodicTable"); periodicTable.Columns.Add("Name", typeof(string)); periodicTable.Columns.Add("Symbol", typeof(string)); periodicTable.Columns.Add("AtomicNumber", typeof(int)); DataRow dr = periodicTable.Rows.Add(); dr[0] = "Hydrogen"; dr[1] = "H"; dr[2] = "1"; dr = periodicTable.Rows.Add(); dr[0] = "Helium"; dr[1] = "He"; dr[2] = "2"; dr = periodicTable.Rows.Add(); dr[0] = "Lithium"; dr[1] = "Li"; dr[2] = "3"; dr = periodicTable.Rows.Add(); dr[0] = "Beryllium"; dr[1] = "Be"; dr[2] = "4"; dr = periodicTable.Rows.Add(); dr[0] = "Boron"; dr[1] = "B"; dr[2] = "5"; dr = periodicTable.Rows.Add(); dr[0] = "Carbon"; dr[1] = "C"; dr[2] = "6"; return periodicTable; } /// <summary> /// Creates a data table of scientists /// </summary> /// <returns>A data table of scientists</returns> private static DataTable GetDataTableOfScientists() { DataTable scientistsTable = new DataTable("Scientists"); scientistsTable.Columns.Add("Name", typeof(string)); DataRow dr = scientistsTable.Rows.Add(); dr[0] = "Antoine Lavoisier"; dr = scientistsTable.Rows.Add(); dr[0] = "Julius Lothar Meyer "; dr = scientistsTable.Rows.Add(); dr[0] = "Dmitri Ivanovich Mendeleev"; return scientistsTable; } } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Spreadsheet SDK Home Page

Explore ByteScout Spreadsheet SDK Documentation

Explore Samples

Sign Up for ByteScout Spreadsheet SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Spreadsheet SDK Home Page

Explore ByteScout Spreadsheet SDK Documentation

Explore Samples

Sign Up for ByteScout Spreadsheet SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next