Powered by SpreadsheetGear
<%@ Page Language="C#" EnableViewState="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Excel Report to Open XML (xlsx) Workbook for Excel 2007-2019 and Excel for Office 365 using ASP.NET, C# and SpreadsheetGear</title>
<meta content="Excel Report to Open XML (xlsx) workbook for Excel 2007-2019 and Excel for Office 365 using ASP.NET, C# and SpreadsheetGear, a royalty free Microsoft Excel compatible spreadsheet component for the Microsoft .NET Framework featuring the fastest and most complete calculation engine available. Create, read, modify, calculate and write Microsoft Excel workbooks from your Microsoft .NET, ASP.NET, C#, VB.NET and Microsoft Office solutions. Integrates with Microsoft Visual Studio .NET, including IntelliSense and Dynamic Help." name="description" />
<script language="C#" runat="server">
     
    void Page_Load(Object sender, EventArgs e)
    {
        // Create a new workbook.
        SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
        SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets["Sheet1"];
        SpreadsheetGear.IRange cells = worksheet.Cells;
 
        // Set the worksheet name.
        worksheet.Name = "2010 Sales";
  
        // Create column titles and center.
        cells["B1"].Formula = "North";
        cells["C1"].Formula = "South";
        cells["D1"].Formula = "East";
        cells["E1"].Formula = "West";
        cells["B1:E1"].HorizontalAlignment = SpreadsheetGear.HAlign.Center;

        // Load row titles using multiple cell text reference and iteration.
        int quarter = 1;
        foreach (SpreadsheetGear.IRange cell in cells["A2:A5"])
            cell.Formula = "Q" + quarter++;

        // Load random data and format as $ using a multiple cell range.
        SpreadsheetGear.IRange body = cells[1, 1, 4, 4];
        body.Formula = "=RAND()*10000";
        body.NumberFormat = "$#,##0_);($#,##0)";
 
        // Stream the Excel workbook to the client in the Open XML file
        // format compatible with Excel 2007-2019 and Excel for Office 365.
        Response.Clear();
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        Response.AddHeader("Content-Disposition", "attachment; filename=report.xlsx");
        workbook.SaveToStream(Response.OutputStream, SpreadsheetGear.FileFormat.OpenXMLWorkbook);
        Response.End();
    }
    
</script>
</head>
<body>
</body>
</html>