Samples

These sample demonstrates how to create a workbook in an MVC controller and let the user download it.

Create and download workbook

                
private const string ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

[HttpGet]
public IActionResult WebSample1()
{
    using(var package = new ExcelPackage())
    {
        var sheet = package.Workbook.Worksheets.Add("Sheet 1");
        sheet.Cells["A1:C1"].Merge = true;
        sheet.Cells["A1"].Style.Font.Size = 18f;
        sheet.Cells["A1"].Style.Font.Bold = true;
        sheet.Cells["A1"].Value = "Simple example 1";
        var excelData = package.GetAsByteArray();
        var fileName = "MyWorkbook.xlsx";
        return File(excelData, ContentType, fileName);
    }
}
                
            

This sample calls the WebSample1 action in the SamplesController. The workbook is created in memory, without any filesystem access.

Download workbook