C# + VB.NET: Create a new Excel File in .NET Create a new Excel File in .NET
using IronXL;

// Create new Excel WorkBook document
WorkBook workBook = WorkBook.Create();

// Convert XLSX to XLS
WorkBook xlsWorkBook = WorkBook.Create(ExcelFileFormat.XLS);

// Create a blank WorkSheet
WorkSheet workSheet = workBook.CreateWorkSheet("new_sheet");

// Add data and styles to the new worksheet
workSheet["A1"].Value = "Hello World";
workSheet["A1"].Style.WrapText = true;
workSheet["A2"].BoolValue = true;
workSheet["A2"].Style.BottomBorder.Type = IronXL.Styles.BorderType.Double;

// Save the excel file as XLS, XLSX, CSV, TSV, JSON, XML, HTML and streams
workBook.SaveAs("sample.xlsx");
Imports IronXL

' Create new Excel WorkBook document
Private workBook As WorkBook = WorkBook.Create()

' Convert XLSX to XLS
Private xlsWorkBook As WorkBook = WorkBook.Create(ExcelFileFormat.XLS)

' Create a blank WorkSheet
Private workSheet As WorkSheet = workBook.CreateWorkSheet("new_sheet")

' Add data and styles to the new worksheet
Private workSheet("A1").Value = "Hello World"
Private workSheet("A1").Style.WrapText = True
Private workSheet("A2").BoolValue = True
Private workSheet("A2").Style.BottomBorder.Type = IronXL.Styles.BorderType.Double

' Save the excel file as XLS, XLSX, CSV, TSV, JSON, XML, HTML and streams
workBook.SaveAs("sample.xlsx")

<p>The IronXL library can be used to create Excel documents from XLS and XLSX formats. Using IronXL intuitive APIs to edit and populate your workbook. Accessing Cell's value with <code>Value</code> property. Cell's style can also be changed using IronXL.</p> <p>The <code>Style</code> properties below can all be configured:</p> <ul> <li><code>DiagonalBorder</code></li> <li><code>Indention</code></li> <li><code>Rotation</code></li> <li><code>FillPattern</code></li> <li><code>VerticalAlignment</code></li> <li><code>HorizontalAlignment</code></li> <li><code>DiagonalBorderDirection</code></li> <li><code>WrapText</code></li> <li><code>ShrinkToFit</code></li> <li><code>TopBorder</code></li> <li><code>RightBorder</code></li> <li><code>LeftBorder</code></li> <li><code>BackgroundColorFont</code></li> <li><code>BottomBorder</code></li> <li><code>SetBackgroundColor</code></li> </ul> <p>Please note that for CSV, TSV, JSON, and XML file format each file will be created corresponding to each sheet. The naming convention would be <code>fileName.sheetName.format</code>. In the example above the output for CSV format would be <code>sample.new_sheet.csv</code></p>

C# + VB.NET: Read Excel Files without Interop Read Excel Files without Interop
using IronXL;
using System;
using System.Linq;

// Supported for XLSX, XLS, XLSM, XLTX, CSV and TSV
WorkBook workBook = WorkBook.Load("sample.xlsx");

// Select worksheet at index 0
WorkSheet workSheet = workBook.WorkSheets[0];

// Get any existing worksheet
WorkSheet firstSheet = workBook.DefaultWorkSheet;

// Select a cell and return the converted value
int cellValue = workSheet["A2"].IntValue;

// Read from ranges of cells elegantly.
foreach (var cell in workSheet["A2:A10"])
{
    Console.WriteLine("Cell {0} has value '{1}'", cell.AddressString, cell.Text);
}

// Calculate aggregate values such as Min, Max and Sum
decimal sum = workSheet["A2:A10"].Sum();

// Linq compatible
decimal max = workSheet["A2:A10"].Max(c => c.DecimalValue);
Imports IronXL
Imports System
Imports System.Linq

' Supported for XLSX, XLS, XLSM, XLTX, CSV and TSV
Private workBook As WorkBook = WorkBook.Load("sample.xlsx")

' Select worksheet at index 0
Private workSheet As WorkSheet = workBook.WorkSheets(0)

' Get any existing worksheet
Private firstSheet As WorkSheet = workBook.DefaultWorkSheet

' Select a cell and return the converted value
Private cellValue As Integer = workSheet("A2").IntValue

' Read from ranges of cells elegantly.
For Each cell In workSheet("A2:A10")
	Console.WriteLine("Cell {0} has value '{1}'", cell.AddressString, cell.Text)
Next cell

' Calculate aggregate values such as Min, Max and Sum
Dim sum As Decimal = workSheet("A2:A10").Sum()

' Linq compatible
Dim max As Decimal = workSheet("A2:A10").Max(Function(c) c.DecimalValue)

<p>IronXL is an Excel Library for C# and .NET which allows developers to load/read Excel data from <strong>XLSX, XLS, XLSM, XLTX, CSV and TSV</strong> Documents <em>without using Microsoft.Office.Interop.Excel</em>. Although all the available file format can be read with <code>Load</code> method, <code>LoadCSV</code> method is recommended to use for CSV file format.</p> <h2 id="anchor-selecting-worksheet">Selecting Worksheet</h2> <p><strong>WorkSheet</strong> represents one page or tab within the <strong>WorkBook</strong>. Each WorkSheet can be selected to read and manipulate.</p> <ul> <li>By worksheet's index position in worksheet collection: <code>workBook.WorkSheets [0]</code></li> <li>By worksheet's name as parameter in GetWorkSheet method: <code>workBook.GetWorkSheet("workSheet")</code></li> <li>By <strong>DefaultWorkSheet</strong> property from workbook: <code>workBook.DefaultWorkSheet</code></li> <li>Please note that this option will get the first worksheet in the workbook. If there were no worksheets, it will create and return a new worksheet with the name &quot;Sheet1&quot;.</li> </ul> <p>Furthermore, each individual <strong>Range</strong>, <strong>Row</strong>, and <strong>Column</strong> can be selected from <strong>WorkSheet</strong> to access/modify Cell's data and apply formula.</p> <p>Navigate to <a href="/csharp/excel/examples/select-excel-range/" target="_blank" rel="nofollow noopener noreferrer">Select Excel Range</a> to know more about selecting <strong>Range</strong>, <strong>Row</strong>, and <strong>Column</strong>.</p> <div class="hsg-featured-snippet"> <h2>How to Load Existing Spreadsheets</h2> <ol> <li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronXL.Excel/" target="_blank" rel="nofollow noopener noreferrer"><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronPdf/" target="_blank" rel="nofollow noopener noreferrer">Download the C# library for loading spreadsheets</a></li> <li>Use the static <code>Load</code> method to load a spreadsheet</li> <li>Support XLSX, XLS, XLSM, XLTX, CSV and TSV file formats</li> <li>Access the sheets in the loaded spreadsheet object</li> <li>Edit and export the workbook</li> </ol> </div>

C# + VB.NET: Work with Excel WorkSheets Work with Excel WorkSheets
using IronXL;

// Create new Excel spreadsheet
WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX);

// Create worksheets (workSheet1, workSheet2, workSheet3)
WorkSheet workSheet1 = workBook.CreateWorkSheet("workSheet1");
WorkSheet workSheet2 = workBook.CreateWorkSheet("workSheet2");
WorkSheet workSheet3 = workBook.CreateWorkSheet("workSheet3");

// Set worksheet position (workSheet2, workSheet1, workSheet3)
workBook.SetSheetPosition("workSheet2", 0);

// Set active for workSheet3
workBook.SetActiveTab(2);

// Remove workSheet1
workBook.RemoveWorkSheet(1);

workBook.SaveAs("manageWorkSheet.xlsx");
Imports IronXL

' Create new Excel spreadsheet
Private workBook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)

' Create worksheets (workSheet1, workSheet2, workSheet3)
Private workSheet1 As WorkSheet = workBook.CreateWorkSheet("workSheet1")
Private workSheet2 As WorkSheet = workBook.CreateWorkSheet("workSheet2")
Private workSheet3 As WorkSheet = workBook.CreateWorkSheet("workSheet3")

' Set worksheet position (workSheet2, workSheet1, workSheet3)
workBook.SetSheetPosition("workSheet2", 0)

' Set active for workSheet3
workBook.SetActiveTab(2)

' Remove workSheet1
workBook.RemoveWorkSheet(1)

workBook.SaveAs("manageWorkSheet.xlsx")

<p><strong>IronXL</strong> library makes managing worksheet using C# code as easy as possible. The actions of create &amp; delete worksheet, change worksheets position, set active worksheet in Excel file can be achieved without using Office Interop.</p> <h2 id="anchor-create-worksheet">Create Worksheet</h2> <p>The <code>CreateWorkSheet</code> method allows creating worksheet possible. It requires the worksheet name as the only parameter.</p> <h2 id="anchor-set-worksheet-position">Set Worksheet Position</h2> <p><code>SetSheetPosition</code> method can be used to change or move worksheet position. The two parameters are required. The worksheet name as String and its index position as Integer.</p> <h2 id="anchor-set-active-worksheet">Set Active Worksheet</h2> <p>Set active worksheet means to set which worksheet to be opened by default when the workbook is opened. To achieve this use <code>SetActiveTab</code> method with the index position of the worksheet.</p> <h2 id="anchor-remove-worksheet">Remove Worksheet</h2> <p>Removing the worksheet can also be done with IronXL. Use <code>RemoveWorkSheet</code> method along with index position of the worksheet. In the case of worksheet's position is unknown, the name of the worksheet can also be used to delete the worksheet.</p> <p>Please note that all the index position mentioned above follows zero-based indexing.</p> <div class="hsg-featured-snippet"> <h2>How to Manage an Excel Worksheet in C&num;</h2> <ol> <li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronXL.Excel/" target="_blank" rel="nofollow noopener noreferrer">Install C# library to manage worksheets in Excel</a></li> <li>Utilize <code>CreateWorkSheet</code> method to create worksheet</li> <li>Change worksheet position in C# with <code>SetSheetPosition</code></li> <li>Use <code>SetActiveTab</code> to set which worksheet to be opened by default</li> <li>Remove or delete worksheet using <code>RemoveWorkSheet</code> C# function</li> </ol> </div>

C# + VB.NET: Convert Spreadsheet File Types Convert Spreadsheet File Types
using IronXL;
using System.IO;

// Import any XLSX, XLS, XLSM, XLTX, CSV and TSV
WorkBook workBook = WorkBook.Load("sample.xlsx");

// Export the excel file as XLS, XLSX, XLSM, CSV, TSV, JSON, XML
workBook.SaveAs("sample.xls");
workBook.SaveAs("sample.xlsx");
workBook.SaveAs("sample.tsv");
workBook.SaveAsCsv("sample.csv");
workBook.SaveAsJson("sample.json");
workBook.SaveAsXml("sample.xml");

// Export the excel file as Html, Html string
workBook.ExportToHtml("sample.html");
string htmlString = workBook.ExportToHtmlString();

// Export the excel file as Binary, Byte array, Data set, Stream
byte[] binary = workBook.ToBinary();
byte[] byteArray = workBook.ToByteArray();
System.Data.DataSet dataSet = workBook.ToDataSet(); // Allow easy integration with DataGrids, SQL and EF
Stream stream = workBook.ToStream();
Imports IronXL
Imports System.IO

' Import any XLSX, XLS, XLSM, XLTX, CSV and TSV
Private workBook As WorkBook = WorkBook.Load("sample.xlsx")

' Export the excel file as XLS, XLSX, XLSM, CSV, TSV, JSON, XML
workBook.SaveAs("sample.xls")
workBook.SaveAs("sample.xlsx")
workBook.SaveAs("sample.tsv")
workBook.SaveAsCsv("sample.csv")
workBook.SaveAsJson("sample.json")
workBook.SaveAsXml("sample.xml")

' Export the excel file as Html, Html string
workBook.ExportToHtml("sample.html")
Dim htmlString As String = workBook.ExportToHtmlString()

' Export the excel file as Binary, Byte array, Data set, Stream
Dim binary() As Byte = workBook.ToBinary()
Dim byteArray() As Byte = workBook.ToByteArray()
Dim dataSet As System.Data.DataSet = workBook.ToDataSet() ' Allow easy integration with DataGrids, SQL and EF
Dim stream As Stream = workBook.ToStream()

<p>The <strong>IronXL</strong> library enable a very convenience and safe way to convert from commonly used spreadsheet file format to the require format to be used in the next process of your .Net project. The available formats are shown below:</p> <h2 id="anchor-load">Load</h2> <ul> <li>XLS</li> <li>XLSX</li> <li>XLSM</li> <li>XLTX</li> <li>CSV</li> <li>TSV</li> </ul> <h2 id="anchor-export">Export</h2> <ul> <li>XLS, XLSX, XLSM, CSV and TSV</li> <li>JSON</li> <li>XML</li> <li>HTML</li> <li>In code data types:</li> <li>HTML string</li> <li>Binary</li> <li>Byte array</li> <li>Data set</li> <li>Memory stream</li> </ul> <div class="hsg-featured-snippet"> <h2>How to Convert and Export (XLSX, XLS, XLSM, XLTX, CSV) in C&num;</h2> <ol> <li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronXL.Excel/" target="_blank" rel="nofollow noopener noreferrer">Install C# library to convert Excel file to other file formats</a></li> <li>Use <code>WorkBook</code> class to load or create new XLS or XLSX</li> <li>View, add or modify data in Excel spreadsheet in C#</li> <li>Utilize methods in <code>WorkBook</code> class to export the spreadsheet.</li> <li>Check the exported file in specified directory.</li> </ol> </div> <p>Exporting Excel into <code>System.Data.DataSet</code> and <code>System.Data.DataTable</code> objects allow easy interoperability or integration with <code>DataGrids</code>, SQL and EF.</p> <p>You can download a file project from this <a href="https://ironsoftware.com/csharp/excel/downloads/convert-excel-spreadsheet.zip" target="_blank" rel="nofollow noopener noreferrer">link</a>.</p>

C# + VB.NET: Excel to SQL via System.Data.DataSet Excel to SQL via System.Data.DataSet
using IronXL;
using System;
using System.Data;

// Supported for XLSX, XLS, XLSM, XLTX, CSV and TSV
WorkBook workBook = WorkBook.Load("sample.xlsx");

// Convert the whole Excel WorkBook to a DataSet
DataSet dataSet = workBook.ToDataSet();

foreach (DataTable table in dataSet.Tables)
{
    Console.WriteLine(table.TableName);

    // Enumerate by rows or columns first at your preference
    foreach (DataRow row in table.Rows)
    {
        for (int i = 0 ; i < table.Columns.Count ; i++)
        {
            Console.Write(row[i]);
        }
    }
}
Imports IronXL
Imports System
Imports System.Data

' Supported for XLSX, XLS, XLSM, XLTX, CSV and TSV
Private workBook As WorkBook = WorkBook.Load("sample.xlsx")

' Convert the whole Excel WorkBook to a DataSet
Private dataSet As DataSet = workBook.ToDataSet()

For Each table As DataTable In dataSet.Tables
	Console.WriteLine(table.TableName)

	' Enumerate by rows or columns first at your preference
	For Each row As DataRow In table.Rows
		For i As Integer = 0 To table.Columns.Count - 1
			Console.Write(row(i))
		Next i
	Next row
Next table

<p>Convert any XLSX, XLS, XLSM, XLTX, CSV and TSV file to a <code>System.Data.DataTable</code> for full interoperability with <code>System.Data.SQL</code> or to populate a <strong>DataGrid</strong>. This <code>DataTable</code> object can contain collection of tables, relationships, and constraints.</p>

C# + VB.NET: Excel to SQL and DataGrid via DataTable Excel to SQL and DataGrid via DataTable
using IronXL;
using System;
using System.Data;

// Supported for XLSX, XLS, XLSM, XLTX, CSV and TSV
WorkBook workBook = WorkBook.Load("sample.xlsx");

// Select default sheet
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Convert the worksheet to DataTable
DataTable dataTable = workSheet.ToDataTable(true);

// Enumerate by rows or columns first at your preference
foreach (DataRow row in dataTable.Rows)
{
    for (int i = 0 ; i < dataTable.Columns.Count ; i++)
    {
        Console.Write(row[i]);
    }
}
Imports IronXL
Imports System
Imports System.Data

' Supported for XLSX, XLS, XLSM, XLTX, CSV and TSV
Private workBook As WorkBook = WorkBook.Load("sample.xlsx")

' Select default sheet
Private workSheet As WorkSheet = workBook.DefaultWorkSheet

' Convert the worksheet to DataTable
Private dataTable As DataTable = workSheet.ToDataTable(True)

' Enumerate by rows or columns first at your preference
For Each row As DataRow In dataTable.Rows
	For i As Integer = 0 To dataTable.Columns.Count - 1
		Console.Write(row(i))
	Next i
Next row

<p>Convert XLSX, XLS, XLSM, XLTX, CSV and TSV file to a <code>System.Data.DataTable</code> for full interoperability with <code>System.Data.SQL</code> or to populate a <code>DataGrid</code>.</p> <p>Input <code>true</code> to <code>ToDataTable</code> method to set the first row as column names of the table. The <code>DataTable</code> can populate a <code>DataGrid</code>.</p> <p>You can download a file project from this <a href="https://ironsoftware.com/csharp/excel/downloads/excel-sql-datatable.zip" target="_blank" rel="nofollow noopener noreferrer">link</a>.</p> <div class="hsg-featured-snippet"> <h2>How to Convert Excel to SQL DataTable in C&num;</h2> <ol> <li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronXL.Excel/" target="_blank" rel="nofollow noopener noreferrer">Install an Excel library to convert Excel to SQL DataTable.</a></li> <li>Select the default Worksheet</li> <li>Create a <code>DataTable</code> from data using <code>ToDataTable</code>.</li> <li>Process values iteratively.</li> </ol> </div>

Human Support related to The Excel .NET Library

Support From Our .NET Team

Iron .NET Excel product development team is on hand to support all of your questions. Get in touch with questions on our library.

Our engineer team has over 10 years of experience dealing with .NET software. You will find our software being used by thousands of reputable SMEs, developers, governments, and more. Our experience has also allowed us to develop a helpful customer support model with resources you can trust. Our team works to ensure your software is running smoothly and makes sense for your business.

Raise a Ticket
Excel In Csharp NET Cropped related to The Excel .NET Library

.NET Library Capabilities

Our .NET Excell Install can facilitate creating a new Excel file in .NET, read Excel files without any Microsoft Interop, working with various Excel worksheets and ranges, converting spreadsheet file types into what you need, (i.e. XLS/XLSX/CSV/TSV/JSON) and Excel to SQL connections via System.Data.DataSet and DataGrid via DataTable.

Some of our key net excel library features include recalculating excel formulas each time a sheet is edited, sorting capabilities for ranges, columns, and rows, and stylizing items such as fonts, size, background patterns, alignments, etc.

Essentially, you get all the Excel functionality without any of the Microsoft Interop. You also have more customizable options that can give your spreadsheets a more polished look. The possibilities are endless with the NuGet download of our .NET library. 

Works with .NET, C#, .NET CORE, XLSX, VB.NET

.NET Library Features
Read And Write Multiple Formats Cropped related to The Excel .NET Library

Read & Write Spreadsheet Formats in .NET

IronXL allows you to read & write Excel Spreadsheets in your .NET APPs. Read & Edit XLS/XLSX/CSV/TSV - Save & Export to XLS/XLSX/CSV/TSV/JSON.

More
Fast Native SQL Support Cropped related to The Excel .NET Library

SQL Supported

Transfer Data between Excel, SQL and GridViews using System.Data.DataSet and System.Data.DataTable objects.

Code Samples
Edit Excel Data Formulas Filters Sorting Cropped related to The Excel .NET Library

Edit Excel Formulas

Supports Microsoft Excel formulas. Easy to use WorkSheet [“A1:B10”] syntax. Combine and set ranges intuitively. Sort by Ranges, Columns and Rows.

Learn More
Style Cells Cropped related to The Excel .NET Library

Style Excel Spreadsheets

Set Font, Size, Background, Border, Alignment and format.

Get Started Now
Visual Studio - C# Create Excel Spreadsheet .NET Library - for Excel document Creation and Editing.

.NET Projects made with Visual Studio

The IronXL integration platform is helpful for a number of different industries and functions. You will find applicability with accounting and finance systems, business digitization, enterprise content management, and data/reporting fields.

IronXL puts Excel tools in your projects easily with Visual Studio .NET installer.
You can download the software product from this link.

PM > Install-Package IronXL.Excel Download DLL Free
Supports:
  • .NET Core 2.0 and above
  • .NET Framework 4.0 and above support C#, VB, F#
  • Microsoft Visual Studio. .NET Development IDE Icon
  • NuGet Installer Support for Visual Studio
  • JetBrains ReSharper C# language assistant compatible
  • Microsoft Azure C# .NET  hosting platform compatible

.NET Licensing & Pricing

Free community development licenses. Commercial licenses from $749.

Project C# + VB.NET Library Licensing

Project

Developer C# + VB.NET Library Licensing

Developer

Organization C# + VB.NET Library Licensing

Organization

Agency C# + VB.NET Library Licensing

Agency

SaaS C# + VB.NET Library Licensing

SaaS

OEM C# + VB.NET Library Licensing

OEM

View Full License Options  

Excel Spreadsheet Tutorials for .NET

How to Create Excel Files in .NET

C# Excel ASP.NET

Jonas Schmidt - C# Developer

How to Create Excel Files in C#

See How Jonas uses IronXL to generate Excel Files without using Office Interop...

View Jonas' Excel File Generation Tutorial
Reading and Writing Excel Tutorial + Code Examples in C# & VB.NET

C# Excel XLSX

Elijah Williams - Product Development Engineer

Open and Edit Excel Files in C# or VB.NET

Elijah shares a no-nonsense approach to reading Excel data into C# Applications...

See Elijah's Excel Reading & Editing Tutorial
Tutorial + Code Examples VB.NET PDF Creation and Editing | VB.NET & ASP.NET PDF

C# Excel Data

Rebecca White - .NET Solution Director

How to Read Excel Files into .NET Apps.

Rebecca's code walkthrough for reading Excel data into a .NET application...

Read Becky's C# Tutorial
.NET Coders use IronXL for...

Accounting and Finance Systems

  • # Receipts
  • # Reporting
  • # Invoice Printing
Add Excel Support to ASP.NET Accounting and Finance Systems

Business Digitization

  • # Documentation
  • # Ordering & Labelling
  • # Paper Replacement
C# Business Digitization Use Cases

Enterprise Content Management

  • # Content Production
  • # Document Management
  • # Content Distribution
.NET CMS Excel Support

Data and Reporting Applications

  • # Performance Tracking
  • # Trend Mapping
  • # Reports
C# Excel Reports
Iron Software Enterprise .NET Component Developers

Thousands of corporations, governments, SMEs and developers alike trust Iron software products.

Iron's team have over 10 years experience in the .NET software component market.

Iron Customer Icon
Iron Customer Icon
Iron Customer Icon
Iron Customer Icon
Iron Customer Icon
Iron Customer Icon
Iron Customer Icon
Iron Customer Icon