Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
This tutorial provides a comprehensive guide on creating new spreadsheets using Iron XL in C#. It begins with the essential step of installing the Iron XL NuGet package if it's not already installed. The process involves setting up namespace imports and ensuring your license key is set. The creation of a new spreadsheet is accomplished with the Workbook.Create
method, which initializes a workbook in memory. Users can specify the Excel file format using the ExcelFileFormat.Xlsx
argument. An alternative overload of the Create
method allows for additional options, such as setting a default file format. Once the workbook is initialized, a worksheet is created, named, and then saved to disk using the SaveAs
method. The newly created spreadsheet can be opened in Excel. Following these steps, users can programmatically create spreadsheets tailored to their needs. The tutorial concludes by encouraging users to subscribe for more tutorials and try out Iron XL by downloading the trial version. A link in the description offers further guidance.
// This example demonstrates creating a new spreadsheet using Iron XL in C#.
// Import the necessary namespaces
using IronXL;
using System;
class CreateSpreadsheetExample
{
static void Main()
{
// Ensure you have set your Iron XL license key
IronXL.License.LicenseKey = "YOUR_LICENSE_KEY";
// Create a new Excel workbook in memory
var workbook = WorkBook.Create(ExcelFileFormat.Xlsx);
// Add a new worksheet to the workbook and name it
var worksheet = workbook.CreateWorkSheet("NewSheet");
// Example of setting a cell value
worksheet["A1"].Value = "Hello, IronXL!";
// Save the workbook to the specified file path
workbook.SaveAs("NewSpreadsheet.xlsx");
Console.WriteLine("Spreadsheet created successfully.");
}
}
// This example demonstrates creating a new spreadsheet using Iron XL in C#.
// Import the necessary namespaces
using IronXL;
using System;
class CreateSpreadsheetExample
{
static void Main()
{
// Ensure you have set your Iron XL license key
IronXL.License.LicenseKey = "YOUR_LICENSE_KEY";
// Create a new Excel workbook in memory
var workbook = WorkBook.Create(ExcelFileFormat.Xlsx);
// Add a new worksheet to the workbook and name it
var worksheet = workbook.CreateWorkSheet("NewSheet");
// Example of setting a cell value
worksheet["A1"].Value = "Hello, IronXL!";
// Save the workbook to the specified file path
workbook.SaveAs("NewSpreadsheet.xlsx");
Console.WriteLine("Spreadsheet created successfully.");
}
}
' This example demonstrates creating a new spreadsheet using Iron XL in C#.
' Import the necessary namespaces
Imports IronXL
Imports System
Friend Class CreateSpreadsheetExample
Shared Sub Main()
' Ensure you have set your Iron XL license key
IronXL.License.LicenseKey = "YOUR_LICENSE_KEY"
' Create a new Excel workbook in memory
Dim workbook = WorkBook.Create(ExcelFileFormat.Xlsx)
' Add a new worksheet to the workbook and name it
Dim worksheet = workbook.CreateWorkSheet("NewSheet")
' Example of setting a cell value
worksheet("A1").Value = "Hello, IronXL!"
' Save the workbook to the specified file path
workbook.SaveAs("NewSpreadsheet.xlsx")
Console.WriteLine("Spreadsheet created successfully.")
End Sub
End Class
Further Reading: How to Create New Spreadsheets