create histogram in excel using c# with analys32.xll
<p>This is VB code for creating a histogram in excel. The code got executed successfully. But my work is to create histogram in excel with the help of c#. I converted the below code into c# code but there are few errors which i couldn't solve.If anyone knows about using analys32.xll in c# please help me.</p>

<p>Public Class Form1</p>

<pre><code>Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    ''' This project requires project references to
    ''' The Excel object library - e.g. Excel9.olb or Excel8.olb

    Dim oXl As Excel.Application
    Dim oBook As Excel.Workbook
    Dim oSheet As Excel.Worksheet
    Dim oRange As Excel.Range
    Dim oAddIn As Excel.AddIn

    'Launch Excel and make it visible
    oXl = CreateObject("Excel.application")
    oXl.Visible = True
    oBook = oXl.Workbooks.Add
    oSheet = oBook.Worksheets.Item(1)

    ' Add the Excel Analysis ToolPak library
    oXl.AddIns.Add(Filename:=oXl.LibraryPath &amp; "\analysis\analys32.xll")
    oAddIn = oXl.AddIns.Item("Analysis ToolPak")

    ' Register all the Analysis ToolPak functions
    '  See Microsoft Knowledge Base Article 213489
    oXl.RegisterXLL("Analys32.xll")

    ' Add the Excel Analysis ToolPak - VBA AddIn -
    '  it's the Automation interface to the Analysis ToolPak library
    ' Now open the .xla so that you can run its Auto_Open macro now, and others later.
    ' See Microsoft Knowledge Base article 213489
    oXl.Workbooks.Open(oXl.LibraryPath &amp; ("\Analysis\ATPVBAEN.xlam"))
    oXl.Workbooks("atpvbaen.xlam").RunAutoMacros(1)

    'Excel 2007 uses the xlam file extension
    'oXl.Workbooks.Open oXl.LibraryPath &amp; "\analysis\atpvbaen.xlam"
    'oXl.Workbooks("atpvbaen.xlam").RunAutoMacros 1

    ' Fill the worksheet with some data
    ' Create and fill the Input Range - See Microsoft Knowledge Base
    ' Article 141684 or 214269
    oRange = oSheet.Cells(1, 1)
    oRange.Value = "87"
    oRange = oSheet.Cells(2, 1)
    oRange.Value = "27"
    oRange = oSheet.Cells(3, 1)
    oRange.Value = "45"
    oRange = oSheet.Cells(4, 1)
    oRange.Value = "62"
    oRange = oSheet.Cells(5, 1)
    oRange.Value = "3"
    oRange = oSheet.Cells(6, 1)
    oRange.Value = "52"
    oRange = oSheet.Cells(7, 1)
    oRange.Value = "20"
    oRange = oSheet.Cells(8, 1)
    oRange.Value = "43"
    oRange = oSheet.Cells(9, 1)
    oRange.Value = "74"
    oRange = oSheet.Cells(10, 1)
    oRange.Value = "61"

    ' Create and populate the Bin Range
    oRange = oSheet.Cells(1, 2)
    oRange.Value = "20"
    oRange = oSheet.Cells(2, 2)
    oRange.Value = "40"
    oRange = oSheet.Cells(3, 2)
    oRange.Value = "60"
    oRange = oSheet.Cells(4, 2)
    oRange.Value = "80"

    ' Chart the Histogram on a new Worksheet
    ' See Microsoft Knowledge Base article 213489
    oXl.Run("ATPVBAEN.XLAM!Histogram", oXl.ActiveSheet.Range("$A$1:$A$10"), _
            "", oXl.ActiveSheet.Range("$B$1:$B$4"), _
            False, False, True, False) ' True = Chart

    'Excel 2007 uses the xlam file extension
    'oXl.Run "ATPVBAEN.XLAM!Histogram", oXl.ActiveSheet.Range("$A$1:$A$10"), _
    '        "", oXl.ActiveSheet.Range("$B$1:$B$4"), _
    '        False, False, True, False ' True = Chart

    'Clean up
    oAddIn = Nothing
    oRange = Nothing
    oSheet = Nothing
    oBook = Nothing
    oXl.UserControl = True
    oXl = Nothing
End Sub
</code></pre>

<p>End Class</p>
