.NET Excel Examples
Convert an Excel Document to CSV with 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 document to CSV format using C#.
Watch this video to see how to convert an Excel document to CSV format using the Syncfusion .NET Excel Library:
Steps to convert an Excel file to CSV
Follow these steps to convert an Excel document to CSV format 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 namespace
Add the following namespace to your Program.cs file:
using Syncfusion.XlsIO;Step 4: Add Excel-to-CSV conversion code
Use the following code in the Program.cs file to convert an Excel document to CSV.
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);
//Save the workbook as a stream.
FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Sample.csv"), FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(outputStream, ",");
//Dispose streams.
outputStream.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
