ChartsDemo.aspx.cs
using System;
using System.Data;
using System.IO;
using System.Web.UI;
using ExpertXls.ExcelLib;
using ExcelLibraryDemos;
/// <summary>
/// Charts: the workbook code is in App_Code\ChartsDemo.cs.
/// </summary>
public partial class ChartsDemoPage : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
foreach (ExcelChartType chartType in ChartsDemo.ChartTypes2D)
listChartType.Items.Add(chartType.ToString());
foreach (ExcelChartType chartType in ChartsDemo.ChartTypes3D)
listChartType.Items.Add(chartType.ToString());
}
}
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())
{
ChartsDemo.CreateWorkbook(format, Server.MapPath("~"), stream,
(ExcelChartType)Enum.Parse(typeof(ExcelChartType), listChartType.SelectedValue), radioSeriesByRows.Checked);
workbookBytes = stream.ToArray();
}
}
catch (Exception ex)
{
labelError.Text = "The workbook could not be created: " + Server.HtmlEncode(ex.Message);
return;
}
WorkbookDownload.Send(Response, workbookBytes, ChartsDemo.OutputName + DemoLayout.GetExtension(format), format);
}
}