FormulasDemo.aspx.cs
using System;
using System.Data;
using System.IO;
using System.Web.UI;
using ExpertXls.ExcelLib;
using ExcelLibraryDemos;
/// <summary>
/// Formulas: the workbook code is in App_Code\FormulasDemo.cs.
/// </summary>
public partial class FormulasDemoPage : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void buttonCreate_Click(object sender, EventArgs e)
{
ExcelWorkbookFormat format = radioXlsx.Checked ? ExcelWorkbookFormat.Xlsx_2007 : ExcelWorkbookFormat.Xls_2003;
byte[] workbookBytes;
try
{
// create the workbook in memory; the input files are in the folders of the web site
using (MemoryStream stream = new MemoryStream())
{
FormulasDemo.CreateWorkbook(format, Server.MapPath("~"), stream);
workbookBytes = stream.ToArray();
}
}
catch (Exception ex)
{
labelError.Text = "The workbook could not be created: " + Server.HtmlEncode(ex.Message);
return;
}
WorkbookDownload.Send(Response, workbookBytes, FormulasDemo.OutputName + DemoLayout.GetExtension(format), format);
}
}