Powered by SpreadsheetGear
<%@ Page Language="VB" 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">
<title>Gantt Chart with ASP.NET and VB.NET Returns Open XML (XLSX) Workbook Using SpreadsheetGear</title>
<meta content="Gantt Chart with ASP.NET, Visual Basic .NET 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="VB" runat="server">

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        ' Create a new workbook.
        Dim workbook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook()
        Dim worksheet As SpreadsheetGear.IWorksheet = workbook.Worksheets("Sheet1")
        Dim windowInfo As SpreadsheetGear.IWorksheetWindowInfo = worksheet.WindowInfo
        Dim cells As SpreadsheetGear.IRange = worksheet.Cells

        ' Load row titles using multiple cell text reference and iteration.
        Dim task As Integer = 1
        Dim cell As SpreadsheetGear.IRange
        For Each cell In cells("A1:A8")
            cell.Formula = "Task " + task.ToString()
            task = task + 1
        Next cell

        ' Start with zero and use formulas to calculate each additional start value.
        cells("B1").Formula = "0"
        cells("B2:B8").Formula = "=B1+C1"

        ' Load random duration values
        cells("C1:C8").Formula = "=INT(RAND() * 10) + 2"

        ' Add a chart to the worksheet's shape collection.
        ' NOTE: Calculate the coordinates of the chart by converting row and column
        '       coordinates to points.  Use fractional row and column values to get 
        '       coordinates anywhere in between row and column boundaries.
        Dim left As Double = windowInfo.ColumnToPoints(3.0)
        Dim top As Double = windowInfo.RowToPoints(1.0)
        Dim right As Double = windowInfo.ColumnToPoints(10.0)
        Dim bottom As Double = windowInfo.RowToPoints(18.0)
        Dim chart As SpreadsheetGear.Charts.IChart = _
            worksheet.Shapes.AddChart(left, top, right - left, bottom - top).Chart

        ' Set the chart's source data range, plotting series in columns.
        Dim source As SpreadsheetGear.IRange = cells("A1:C8")
        chart.SetSourceData(source, SpreadsheetGear.Charts.RowCol.Columns)

        ' Set the chart type to stacked bar to simulate a gantt chart.
        chart.ChartType = SpreadsheetGear.Charts.ChartType.BarStacked

        ' Set the distance between bars as a percentage of the bar width.
        chart.ChartGroups(0).GapWidth = 100

        ' Hide the first (Start) series values by setting the fill to none.
        chart.SeriesCollection(0).Format.Fill.Visible = False

        ' Change the theme color of the second (Duration) series.
        chart.SeriesCollection(1).Format.Fill.ForeColor.ThemeColor = _

        ' Reverse the category axis so that values are shown top to bottom.
        chart.Axes(SpreadsheetGear.Charts.AxisType.Category).ReversePlotOrder = True

        ' Add a chart title and change the font size.
        chart.HasTitle = True
        chart.ChartTitle.Text = "Estimated Days To Completion"
        chart.ChartTitle.Font.Size = 12

        ' Delete the legend.
        chart.HasLegend = False

        ' Stream the Excel workbook to the client in the Open XML file
        ' format compatible with Excel 2007-2019 and Excel for Office 365.
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        Response.AddHeader("Content-Disposition", "attachment; filename=report.xlsx")
        workbook.SaveToStream(Response.OutputStream, SpreadsheetGear.FileFormat.OpenXMLWorkbook)
    End Sub 'Page_Load