请参考如下代码
- Imports FarPoint.Win.Spread
- Imports FarPoint.Win.Spread.Model
- Public Class Form1
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Dim cfs As FarPoint.Win.Spread.Model.ICustomFunctionSupport
- 'Dim fi As FarPoint.CalcEngine.FunctionInfo
- cfs = FpSpread1.ActiveSheet.Models.Data
- cfs.AddCustomFunction(New DateDiffFunctionInfo())
- FpSpread1.ActiveSheet.SetFormula(0, 0, "DAYSDIFF(12/20/2017, 12/12/2017)")
- End Sub
- End Class
- Public Class DateDiffFunctionInfo
- Inherits FarPoint.CalcEngine.FunctionInfo
- Public Overrides ReadOnly Property Name() As String
- Get
- Return "DAYSDIFF"
- End Get
- End Property
- Public Overrides ReadOnly Property MinArgs() As Integer
- Get
- Return 2
- End Get
- End Property
- Public Overrides ReadOnly Property MaxArgs() As Integer
- Get
- Return 2
- End Get
- End Property
- Public Overrides Function Evaluate(ByVal args() As Object) As Object
- ' Get number of days between dates, return 0 on bad dates
- Dim date1 As Date = FarPoint.CalcEngine.CalcConvert.ToDateTime(args(0))
- Dim date2 As Date = FarPoint.CalcEngine.CalcConvert.ToDateTime(args(1))
- If IsDate(date1) And IsDate(date2) Then
- Return date1.Subtract(date2).Days
- Else
- Return 0
- End If
- End Function
- End Class
复制代码 |