Powered by SpreadsheetGear
<%@ Page Language="VB" 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 VB.NET</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="VB" runat="server">

      Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

          ' 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.
          Dim imageRenderingUtility As String = "spreadsheetgearimageVB.aspx"
          Dim file As String = "?file=" + HttpUtility.UrlEncode("files/chartgallery.xlsx")
          Dim worksheet As String = "&worksheet=" + HttpUtility.UrlEncode(ListCategory.SelectedValue)
          Dim shape As String = "&shape=" + HttpUtility.UrlEncode(ListType.SelectedValue)
          Dim url As String = imageRenderingUtility + file + worksheet + shape

          ' Set the Image Url.
          ImageMain.ImageUrl = url

          ' Show the Url being used to generate the image.
          LabelImageUrl.Text = url

      End Sub 'Page_Load

      Sub 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 Not Page.IsPostBack Or ListCategory.SelectedValue <> SaveCategory.Value Then

              ' Open the chart gallery workbook.
              Dim filename As String = Server.MapPath("files/chartgallery.xlsx")
              Dim workbook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook(filename)

              ' If page is loading for the first time...
              If Not Page.IsPostBack Then

                  ' Dynamically build the category list using worksheet names.
                  Dim worksheet As SpreadsheetGear.IWorksheet
                  For Each worksheet In workbook.Worksheets
                      ListCategory.Items.Add(worksheet.Name)
                  Next worksheet

                  ' Select the default category.
                  ListCategory.SelectedValue = "Combination"

              End If

              ' Get the currently selected category.
              Dim selectedCategory As String = ListCategory.SelectedValue

              ' Get the currently selected type.
              Dim selectedType As String = ListType.SelectedValue

              ' Clear the type list.
              ListType.Items.Clear()

              ' Get the worksheet based on the selected category name.
              Dim curWorksheet As SpreadsheetGear.IWorksheet = workbook.Worksheets(selectedCategory)

              ' Dynamically build the type list using shape names.
              Dim shape As SpreadsheetGear.Shapes.IShape
              For Each shape In curWorksheet.Shapes
                  ListType.Items.Add(shape.Name)
              Next shape

              ' If page is loading for the first time...
              If Not Page.IsPostBack Then
                  ' Select the default type.
                  ListType.SelectedValue = "Area - Column - Line"
              Else
                  ' Select the first type.
                  ListType.SelectedIndex = 0
              End If

              ' Set the number of displayed rows to match the max number of items.
              Dim maxCount As Integer = Math.Max(ListCategory.Items.Count, ListType.Items.Count)
              ListCategory.Rows = maxCount
              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
          End If

          ' Set the focus to the type list.
          ListType.Focus()
      End Sub 'BuildCategories

  </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>