Link Search Menu Expand Document

Import From JSON - C#

Spreadsheet SDK sample in C# demonstrating ‘Import From JSON’

Program.cs
using System.Diagnostics;
using System.IO;
using Bytescout.Spreadsheet;

namespace ImportFromJSON
{
    class Program
    {
        static void Main(string[] args)
        {
            using (Spreadsheet spreadsheet = new Spreadsheet())
            {
                // Load JSON string from file
                string jsonString = File.ReadAllText("sample.json");

            	// Import JSON
                spreadsheet.ImportFromJSON(jsonString);
                
                // Save spreadsheet
                spreadsheet.SaveAsXLS("result.xls");

				// Open the result file in default associated application
                Process.Start("result.xls");
            }
        }
    }
}

sample.json
[
  {
    "Column 1": "1",
    "Column 2": "2",
    "Column 3": "3",
    "Column 4": "4"
  },
  {
    "Column 1": "2",
    "Column 2": "3",
    "Column 3": "4",
    "Column 4": "5"
  },
  {
    "Column 1": "3",
    "Column 2": "4",
    "Column 3": "5",
    "Column 4": "6"
  },
  {
    "Column 1": "4",
    "Column 2": "5",
    "Column 3": "6",
    "Column 4": "7"
  },
  {
    "Column 1": "5",
    "Column 2": "6",
    "Column 3": "7",
    "Column 4": "8"
  },
  {
    "Column 1": "6",
    "Column 2": "7",
    "Column 3": "8",
    "Column 4": "9"
  },
  {
    "Column 1": "7",
    "Column 2": "8",
    "Column 3": "9",
    "Column 4": "10"
  },
  {
    "Column 1": "8",
    "Column 2": "9",
    "Column 3": "10",
    "Column 4": "11"
  },
  {
    "Column 1": "9",
    "Column 2": "10",
    "Column 3": "11",
    "Column 4": "12"
  },
  {
    "Column 1": "10",
    "Column 2": "11",
    "Column 3": "12",
    "Column 4": "13"
  }
]

Download Source Code (.zip)

Return to the previous page Explore Spreadsheet SDK


Copyright © 2016 - 2021 ByteScout