如何在C#中创建新电子表格

How to Create New Spreadsheets

This article was translated from English: Does it need improvement?
Translated
View the article in English

XLSX is a modern file format for storing Microsoft Excel spreadsheets. It uses the Open XML standard, introduced in Office 2007. XLSX supports advanced features like charts and conditional formatting and is widely used for data analysis and business tasks.

XLS is the older binary format for Excel files used in earlier versions. It lacks the features of XLSX and is now less common.

Quickstart: Create a new XLSX workbook with IronXL

Use IronXL’s single line API to instantly generate a new workbook in XLSX format—no complex setup needed. Ideal for developers who want to get started quickly and build spreadsheets in C# in record time.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. Copy and run this code snippet.

    WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
  3. Deploy to test on your live environment

    Start using IronXL in your project today with a free trial
    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;

// Create spreadsheet
WorkBook workBook = WorkBook.Create();
Imports IronXL

' Create spreadsheet
Private workBook As WorkBook = WorkBook.Create()
$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;

// Create XLSX spreadsheet
WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX);
Imports IronXL

' Create XLSX spreadsheet
Private workBook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
$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;

// Create XLSX spreadsheet
WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX);
Imports IronXL

' Create XLSX spreadsheet
Private workBook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
$vbLabelText   $csharpLabel

常见问题解答

XLSX和XLS文件格式有什么区别?

XLSX是一种在Office 2007中引入的基于XML的文件格式,支持图表和条件格式等高级功能。相比之下,XLS是一种旧的二进制格式,功能较少且效率较低。

如何在C#中创建一个新的Excel工作簿?

您可以通过调用IronXL提供的WorkBook类中的静态Create方法,在C#中创建一个新的Excel工作簿。默认情况下,它会创建一个XLSX格式的工作簿。

在创建新的Excel工作簿时如何指定文件格式?

您可以通过在IronXL提供的WorkBook类的Create方法中使用ExcelFileFormat枚举,在创建新工作簿时指定文件格式。

CreatingOptions类在配置Excel工作簿中的作用是什么?

IronXL中的CreatingOptions类用于配置工作簿创建,特别是通过其DefaultFileFormat属性设置默认文件格式为XLSX或XLS。

如何在现有工作簿中添加新工作表?

要在IronXL中的工作簿中添加新工作表,请在您的工作簿对象上使用CreateWorkSheet方法,并提供所需的工作表名称。

使用IronXL创建Excel电子表格涉及哪些步骤?

要使用IronXL创建Excel电子表格,请下载该库,使用静态Create方法生成工作簿,选择文件格式(XLSX或XLS),并使用SaveAs方法导出工作簿。

在C#中创建Excel文件是否需要安装任何库?

是的,您需要从NuGet安装IronXL库以在C#中创建Excel电子表格。这提供了处理Excel文件所需的功能。

我可以使用IronXL创建XLS和XLSX文件吗?

可以,IronXL允许您创建XLS和XLSX文件,提供了根据您的具体项目需求的灵活性。

使用IronXL创建新的Excel工作簿时的默认文件格式是什么?

使用IronXL中的Create方法时的默认文件格式是XLSX。

在哪里可以获取用于创建Excel电子表格的C#库?

您可以从NuGet,这是.NET的包管理器,下载IronXL库,以便于在C#项目中创建Excel电子表格。

Chaknith Bin
软件工程师
Chaknith 在 IronXL 和 IronBarcode 工作。他在 C# 和 .NET 方面有着深厚的专业知识,帮助改进软件并支持客户。他从用户互动中获得的见解有助于更好的产品、文档和整体体验。
准备开始了吗?
Nuget 下载 1,686,155 | 版本: 2025.11 刚刚发布