Get started with IronXL

Start using IronXL in your project today with a free trial.

First Step:
green arrow pointer


Create Spreadsheet Example

Use the static method Create to create an Excel workbook that can be used to store a collection of sheets or worksheets. By default, this method will create an Excel workbook in XLSX format.

:path=/static-assets/excel/content-code-examples/how-to/create-spreadsheet-create-spreadsheet.cs
using IronXL;

// The following code demonstrates how to create a new spreadsheet using the IronXL library.
// Ensure that you have the IronXL library installed and properly referenced in your project
// to use its functionality for workbook creation and other spreadsheet operations.

class SpreadsheetExample
{
    static void Main()
    {
        // Create a new workbook, which acts as a container for one or more worksheets.
        WorkBook workBook = WorkBook.Create();
        
        // Create a new worksheet within the workbook. Specify the name of the worksheet.
        WorkSheet sheet = workBook.CreateWorkSheet("Sheet1");

        // Example data to populate into the worksheet.
        sheet["A1"].Value = "Hello, World!";
        sheet["A2"].Value = "This is an example of using IronXL.";

        // Save the workbook to a file. Specify the path where the file will be saved.
        workBook.SaveAs("ExampleSpreadsheet.xlsx");

        // Note: Additional operations to add more worksheets, populate additional data, 
        // and perform other manipulations can be added here as needed.
    }
}
Imports IronXL



' The following code demonstrates how to create a new spreadsheet using the IronXL library.

' Ensure that you have the IronXL library installed and properly referenced in your project

' to use its functionality for workbook creation and other spreadsheet operations.



Friend Class SpreadsheetExample

	Shared Sub Main()

		' Create a new workbook, which acts as a container for one or more worksheets.

		Dim workBook As WorkBook = WorkBook.Create()



		' Create a new worksheet within the workbook. Specify the name of the worksheet.

		Dim sheet As WorkSheet = workBook.CreateWorkSheet("Sheet1")



		' Example data to populate into the worksheet.

		sheet("A1").Value = "Hello, World!"

		sheet("A2").Value = "This is an example of using IronXL."



		' Save the workbook to a file. Specify the path where the file will be saved.

		workBook.SaveAs("ExampleSpreadsheet.xlsx")



		' Note: Additional operations to add more worksheets, populate additional data, 

		' and perform other manipulations can be added here as needed.

	End Sub

End Class
$vbLabelText   $csharpLabel

Choose Spreadsheet Type

The Create method also accepts an ExcelFileFormat enum that you can use to specify whether you want to create an XLSX or XLS file. Both file formats are for storing Microsoft Excel spreadsheets, with XLSX being the modern, XML-based format introduced in Office 2007, while XLS is the older binary format used in earlier versions. XLS is now less common due to its limited features and lower efficiency compared to XLSX.

:path=/static-assets/excel/content-code-examples/how-to/create-spreadsheet-spreadsheet-type.cs
using IronXL;

try
{
    // Create a new workbook in XLSX format.
    WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX);

    // Add a worksheet to the workbook.
    WorkSheet sheet = workBook.CreateWorkSheet("Sheet1");

    // Populate the worksheet with some data.
    sheet["A1"].Value = "Hello";
    sheet["B1"].Value = "World";

    // Save the workbook to a specified path.
    workBook.SaveAs("example.xlsx");

    Console.WriteLine("Workbook created and saved successfully.");
}
catch (Exception ex)
{
    // Handle potential exceptions, such as file I/O issues.
    Console.WriteLine($"An error occurred: {ex.Message}");
}
Imports IronXL



Try

	' Create a new workbook in XLSX format.

	Dim workBook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)



	' Add a worksheet to the workbook.

	Dim sheet As WorkSheet = workBook.CreateWorkSheet("Sheet1")



	' Populate the worksheet with some data.

	sheet("A1").Value = "Hello"

	sheet("B1").Value = "World"



	' Save the workbook to a specified path.

	workBook.SaveAs("example.xlsx")



	Console.WriteLine("Workbook created and saved successfully.")

Catch ex As Exception

	' Handle potential exceptions, such as file I/O issues.

	Console.WriteLine($"An error occurred: {ex.Message}")

End Try
$vbLabelText   $csharpLabel

There is another overload for the Create method, which takes CreatingOptions as a parameter. However, the CreatingOptions class currently has only one property, DefaultFileFormat, which is used to configure whether to create an XLSX or XLS file. Check the code below for reference:

:path=/static-assets/excel/content-code-examples/how-to/create-spreadsheet-spreadsheet-type.cs
using IronXL;

try
{
    // Create a new workbook in XLSX format.
    WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX);

    // Add a worksheet to the workbook.
    WorkSheet sheet = workBook.CreateWorkSheet("Sheet1");

    // Populate the worksheet with some data.
    sheet["A1"].Value = "Hello";
    sheet["B1"].Value = "World";

    // Save the workbook to a specified path.
    workBook.SaveAs("example.xlsx");

    Console.WriteLine("Workbook created and saved successfully.");
}
catch (Exception ex)
{
    // Handle potential exceptions, such as file I/O issues.
    Console.WriteLine($"An error occurred: {ex.Message}");
}
Imports IronXL



Try

	' Create a new workbook in XLSX format.

	Dim workBook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)



	' Add a worksheet to the workbook.

	Dim sheet As WorkSheet = workBook.CreateWorkSheet("Sheet1")



	' Populate the worksheet with some data.

	sheet("A1").Value = "Hello"

	sheet("B1").Value = "World"



	' Save the workbook to a specified path.

	workBook.SaveAs("example.xlsx")



	Console.WriteLine("Workbook created and saved successfully.")

Catch ex As Exception

	' Handle potential exceptions, such as file I/O issues.

	Console.WriteLine($"An error occurred: {ex.Message}")

End Try
$vbLabelText   $csharpLabel

Frequently Asked Questions

What is the difference between XLSX and XLS file formats?

XLSX is a modern, XML-based file format introduced in Office 2007, supporting advanced features like charts and conditional formatting. XLS is the older binary format with fewer features and is less efficient.

How can I create a new Excel workbook using IronXL?

You can create a new Excel workbook using IronXL by calling the static method 'Create' from the WorkBook class. This method defaults to creating an XLSX format workbook.

How do I specify the file format when creating a new workbook with IronXL?

You can specify the file format when creating a new workbook by using the 'ExcelFileFormat' enum in the 'Create' method of the WorkBook class.

What is the purpose of the CreatingOptions class in IronXL?

The CreatingOptions class in IronXL is used to configure workbook creation, specifically to set the default file format to either XLSX or XLS.

How do you add a new worksheet to a workbook in IronXL?

To add a new worksheet to a workbook in IronXL, use the 'CreateWorkSheet' method on your workbook object and provide the desired sheet name.

How can I save a workbook created with IronXL?

You can save a workbook created with IronXL by using the 'SaveAs' method on the WorkBook object, specifying the desired file path and name.

Is it necessary to install IronXL before creating spreadsheets?

Yes, you need to install the IronXL library from NuGet before you can create spreadsheets using its features.

Can I create both XLS and XLSX files using IronXL?

Yes, IronXL allows you to create both XLS and XLSX files, providing flexibility depending on your requirements.

What is the default file format when using the 'Create' method in IronXL?

The default file format when using the 'Create' method in IronXL is XLSX.

Where can I download the IronXL library?

You can download the IronXL library from NuGet, which is the package manager for .NET.

Chaknith related to Choose Spreadsheet Type
Software Engineer
Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.