Powered by SpreadsheetGear
<%@ Page Language="C#" EnableViewState="true" %>

<!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 Compatible Chart Gallery Powered by SpreadsheetGear using ASP.NET and C#</title>
  <meta content="Excel Compatible Chart Gallery Powered by 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)
      {
          // Call routine to dynamically build the chart gallery categories based on the 
          // contents of an Open XML workbook from Excel 2007-2019 or Excel for Office 365.
          BuildCategories();

          // Build the image url and query string based on selected options.
          // NOTE: This url references the SpreadsheetGear Image Rendering Utility
          //       which will return an image to be displayed in the image control.
          string imageRenderingUtility = "spreadsheetgearimage.aspx";
          string file = "?file=" + HttpUtility.UrlEncode("files/chartgallery.xlsx");
          string worksheet = "&worksheet=" + HttpUtility.UrlEncode(ListCategory.SelectedValue);
          string shape = "&shape=" + HttpUtility.UrlEncode(ListType.SelectedValue);
          string url = imageRenderingUtility + file + worksheet + shape;

          // Set the Image Url.
          ImageMain.ImageUrl = url;

          // Show the Url being used to generate the image.
          LabelImageUrl.Text = url;
      }

      void BuildCategories()
      {
          // If this is the first time, or the user has selected a new category,
          // we need to populate or update the category and options listboxes.
          if (!Page.IsPostBack || ListCategory.SelectedValue != SaveCategory.Value)
          {
              // Open the chart gallery workbook.
              String filename = Server.MapPath("files/chartgallery.xlsx");
              SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(filename);

              // If page is loading for the first time...
              if (!Page.IsPostBack)
              {
                  // Dynamically build the category list using worksheet names.
                  foreach (SpreadsheetGear.IWorksheet worksheet in workbook.Worksheets)
                      ListCategory.Items.Add(worksheet.Name);

                  // Select the default category.
                  ListCategory.SelectedValue = "Combination";
              }

              // Get the currently selected category.
              string selectedCategory = ListCategory.SelectedValue;

              // Get the currently selected type.
              string selectedType = ListType.SelectedValue;

              // Clear the type list.
              ListType.Items.Clear();

              // Get the worksheet based on the selected category name.
              SpreadsheetGear.IWorksheet curWorksheet = workbook.Worksheets[selectedCategory];

              // Dynamically build the type list using shape names.
              foreach (SpreadsheetGear.Shapes.IShape shape in curWorksheet.Shapes)
                  ListType.Items.Add(shape.Name);

              // If page is loading for the first time...
              if (!Page.IsPostBack)
                  // Select the default type.
                  ListType.SelectedValue = "Area - Column - Line";
              else
                  // Select the first type.
                  ListType.SelectedIndex = 0;

              // Set the number of displayed rows to match the max number of items.
              int maxCount = Math.Max(ListCategory.Items.Count, ListType.Items.Count);
              ListCategory.Rows = ListType.Rows = maxCount;

              // Save the currently selected category so that we can
              // avoid updating the listboxes when the user changes the
              // selection in the Options listbox.
              SaveCategory.Value = selectedCategory;
          }

          // Set the focus to the type list.
          ListType.Focus();
      }

  </script>
</head>
<body style="font-family: Verdana; font-size: small">
  <form id="form1" runat="server">
    <h1>Excel Compatible Chart Gallery - Powered by SpreadsheetGear and ASP.NET</h1>

    <p>
      This sample dynamically creates a chart gallery which demonstrates some of the most commonly used Excel charting features using a single Open XML workbook from Excel 2007-2019 or Excel for Office 365.
    </p>

    <p>
      First, the Category listbox is populated from the list of worksheet names. Then, for the currently selected worksheet (category), the Options listbox is populated from the 
      names of the individual charts on that worksheet. Finally, the SpreadsheetGear Image Rendering Utility is used to render the image by setting the ImageUrl property of the 
      image to:
    </p>

    <asp:Label ID="LabelImageUrl" Font-Italic="true" runat="server" /><br /><br />

    <table cellpadding="4">
      <tr valign="top">
        <td><label>Category:</label></td>
        <td><label>Options:</label></td>
        <td nowrap><label>Image Generated by SpreadsheetGear Image Rendering Utility:</label></td>
      </tr>
      <tr valign="top">
        <td>
          <asp:ListBox ID="ListCategory" Width="100" Rows="8" AutoPostBack="true" runat="server"></asp:ListBox>
        </td>
        <td>
          <asp:ListBox ID="ListType" Width="160" Rows="8" AutoPostBack="true" runat="server"></asp:ListBox>
        </td>
        <td>
          <asp:Image ID="ImageMain" runat="server"></asp:Image>
        </td>
      </tr>
    </table>
    <asp:HiddenField ID="SaveCategory" runat="server" />
  </form>

  <h5>
    Copyright 2009-2017 © SpreadsheetGear LLC. All Rights Reserved.<br />
    <a href="https://www.spreadsheetgear.com">www.spreadsheetgear.com</a></h5>
</body>
</html>