Originally posted on https://ironsoftware.com/csharp/excel/tutorials/create-excel-file-net/
Creating Excel files in C# can be simple even without dependency on the legacy Microsoft.Office.Interop.Excel library.
In this tutorial we will use IronXL to create an Excel WorkBook file on any platform that supports .Net Framework 4.5 or .Net Core.
Before we start we need to install the IronXL Excel NuGet Package.
PM > Install-Package IronXL.Excel
As an alternative, the IronXL.Dll can be downloaded and added to your project.
//default file format is XLSX, we can override it using CreatingOptions
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
var sheet = workbook.CreateWorkSheet("example_sheet");
sheet["A1"].Value = "Example";
//set value to multiple cells
sheet["A2:A4"].Value = 5;
//set style to multiple cells
sheet["A5:A6"].Style.Font.Bold = true;
sheet["A6"].Value = "=SUM(A2:A4)";
if (sheet["A6"].IntValue == sheet["A2:A4"].IntValue)
Console.WriteLine("Basic test passed");
To learn more about creating Excel files in C# .Net, we encourage you to work with this code sample and explore the object reference to move forwards to meet you own project’s specific need.
Information contained on this page is provided by an independent third-party content provider. Frankly and this Site make no warranties or representations in connection therewith. If you are affiliated with this page and would like it removed please contact email@example.com