Custom Aggregation

Posted by: kingmanb on 8 September 2017, 3:21 pm EST

  • Posted 8 September 2017, 3:21 pm EST

    I'd like to perform a custom column footer aggregation in VB. Once I've set the aggregation type:
    "FpSpread1.Sheets(0).ColumnFooter.SetAggregationType(0, 1, FarPoint.Win.Spread.Model.AggregationType.Custom"
    What do I do? The sheet uses a custom ".Models.Data" and I have tried to Overloads Function GetAggregationResult, but it doesn't seem to work.
    Could you show a simple example on how to do this?
    Many thanks
  • Replied 8 September 2017, 3:21 pm EST

    Hi Kingman,

    Setting AggregationType property to Custom allows you to set custom formula for Column Footer Aggregation.
    Please refer to the following blog article which explains setting custom formula for column footer aggregation:
    http://sphelp.grapecity.com/2013/10/29/how-to-set-custom-formula-for-column-footer-aggregation/

    Hope it helps
    Regards
  • Replied 8 September 2017, 3:21 pm EST

    Hi Shubham,
    Your example gets me close to where I want to be, but since my cells value is a custom class, not a number, I need to extract the decimal value part of the class before I sum the column. I was hoping a "Public Overloads Function GetAggregationResult" in the subclassed "DefaultSheetDataModel" would allow me to process the aggregating myself. the overload never fires, though. My questions are, where is the aggregating taking place, and can I get to it?
    Thanks,
    Kingman
  • Marked as Answer

    Replied 8 September 2017, 3:21 pm EST

    Hi Shubham,
    Even though I hate to deprive you of the opportunity to respond to my questions, I expanded upon your initial suggestion and used a custom function in the footer to do all the converting required. It works fine!
    Many thanks again,
    Kingman

    Public Class NumberClassValueInfo
    Inherits FarPoint.CalcEngine.FunctionInfo
    Private Sheet As SheetView
    Public Sub New(ss As SheetView)
    Sheet = ss
    End Sub
    Public Overrides ReadOnly Property Name As String
    Get
    Return "NumberValue"
    End Get
    End Property
    Public Overrides ReadOnly Property MinArgs As Integer
    Get
    Return 1
    End Get
    End Property
    Public Overrides ReadOnly Property MaxArgs As Integer
    Get
    Return 1
    End Get
    End Property
    Public Overrides Function Evaluate(ByVal args() As Object) As Object
    If args(0) IsNot Nothing Then
    Dim ca As CalcReference = args(0)
    Dim dt As Decimal = 0
    Dim c As Cell
    Dim rowIndex, columnIndex As Integer
    For rowIndex = ca.Row To ca.Row + ca.RowCount - 1
    For columnIndex = ca.Column To ca.Column + ca.ColumnCount - 1
    c = Sheet.Cells(rowIndex, columnIndex)
    If c.Value IsNot Nothing Then
    If c.Value.GetType Is GetType(cv) Then
    dt = dt + c.Value.Value
    End If
    End If
    Next
    Next
    Return dt
    End If
    End Function
    Public Overrides Function AcceptsReference(ByVal i As Integer) As Boolean
    Return True
    End Function
    End Class
  • Replied 8 September 2017, 3:21 pm EST

    Hello,

    We are glad to know that your issue is resolved. Thanks for sharing the code with us.

    Thanks,
    Reeva
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels