Loading and saving workbook in ASP.NET Core
24 Jul 20262 minutes to read
Prerequisites
- Visual Studio 2022 (17.0 or later) with the ASP.NET and web development workload installed.
- .NET 8.0 SDK or later.
- Install the Syncfusion.XlsIO.Net.Core NuGet package in your ASP.NET Core project.
- Register your Syncfusion® license key in your project. Refer to the licensing overview for details.
Include the following namespace in your .cs file.
using Syncfusion.XlsIO;NOTE
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, you also have to add the
Syncfusion.Licensingassembly reference and include a license key in your projects. Please refer to this link to know about registering the Syncfusion® license key in your applications to use our components.
Opening an existing workbook
You can open an existing workbook by using the overloads of Open methods of IWorkbooks interface.
// Create a new instance of ExcelEngine
using (ExcelEngine excelEngine = new ExcelEngine())
{
// Initialize IApplication
IApplication application = excelEngine.Excel;
// Open an existing workbook through the Open method of IWorkbooks
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
}Saving an Excel workbook
You can also save the created or manipulated workbook using overloads of SaveAs methods.
// Create a new instance of ExcelEngine
using (ExcelEngine excelEngine = new ExcelEngine())
{
// Initialize IApplication
IApplication application = excelEngine.Excel;
// Open an existing workbook
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
// To-Do: some manipulation
// Set the version of the workbook
workbook.Version = ExcelVersion.Xlsx;
// Save the workbook
workbook.SaveAs("Output.xlsx");
}