Wanna be a .Net / Excel GENIUS CODE MONKEY in seconds? Well let me show you how….
If you would like to know how to create sweet Charts on your excel spreadsheet straight from your code (especially if you are using VB) – do this.
- Open your excel spreadsheet.
- Record a macro and do all your cool charting stuff
- Open the Macro box from the Tools
- Choose your newly created Macro and click EDIT
Whalah – the Script editor will open up will all the proper VB code in there for you. Simply cut and paste this code into your code and then tell your PM that you are a friggin CODING genius and that you need a raise or you’re WALKING! (ok, that last part might be a bit much).
IF YOU do not know how to create an Excel doc in the first place from Code – check out my previous post entitled: EXCEL : Run, Fill, and Execute Macro… with .Net
** FINALLY you might have to do some small changes to the way the code is formatted… look below to see how I created my own chart object, added it to my workbook and then simply added my NINJA (ahem, macro) code:
‘ Generating the graph
Dim chart As Excel.Chart
chart = wkbk.Charts.Add()
With chart
.ChartType = Excel.XlChartType.xlColumnClustered
.SetSourceData(wksheet.Range(“C1:E11″), 2)
.SeriesCollection(1).Name = “=”"In Range”"”
.SeriesCollection(2).Name = “=”"Attempts”"”
.Location(Where:=Excel.XlChartLocation.xlLocationAsNewSheet, Name:=”Charted Data”)
.HasTitle = True
.ChartTitle.Characters.Text = “HFZ STATE REPORT”
.Axes(1, Excel.XlAxisGroup.xlPrimary).HasTitle = True
.Axes(1, Excel.XlAxisGroup.xlPrimary).AxisTitle.Characters.Text = “Tests”
.Axes(2, Excel.XlAxisGroup.xlPrimary).HasTitle = True
.Axes(2, Excel.XlAxisGroup.xlPrimary).AxisTitle.Characters.Text = “Attempts”
End With