.NET Excel Examples
Convert an Excel workbook to JSON using the Syncfusion .NET Excel Library
Overview
The Syncfusion® .NET Excel Library (XlsIO) enables you to create, read, and edit Excel documents programmatically without Microsoft Excel or interop dependencies. Using this library, you can convert an Excel workbook to a JSON file with schema using C#.
Watch this video to see how to convert an Excel workbook to a JSON file with schema using the Syncfusion .NET Excel Library:
Steps to convert an Excel file to JSON
Follow these steps to convert an Excel workbook to a JSON file with schema using the Syncfusion .NET Excel Library.
Step 1: Create a new project
Start by creating a new C# Console Application project.
Step 2: Install the NuGet package
Add the Syncfusion.XlsIO.Net.Core package to your project from NuGet.org.
Step 3: Include namespaces
Add the following namespaces to your Program.cs file:
using System;
using System.IO;
using Syncfusion.XlsIO;Step 4: Add code for converting an Excel workbook to JSON
Use the following code in the Program.cs file to convert an Excel workbook to a JSON file with schema.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorksheet worksheet = workbook.Worksheets[0];
//Save the workbook to a JSON filestream as schema.
FileStream jsonWithSchema = new FileStream(Path.GetFullPath("Output/Excel-Workbook-To-JSON-as-schema.json"), FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAsJson(jsonWithSchema, true);
//Dispose streams.
jsonWithSchema.Dispose();
inputStream.Dispose();
}NuGet installation
Get started quickly by downloading the installer and checking license information on the Downloads page.
Table of contents
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Learning
Technical support
