找回密码
 立即注册

QQ登录

只需一步,快速开始

swallowdragon
金牌服务用户   /  发表于:2018-3-31 09:47  /   查看:3266  /  回复:1
ActiveSheet.AddCustomFunction(New QM()) 这个方法已过时,那如何增加自定义函数呢?

1 个回复

倒序浏览
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2018-4-2 09:12:52
沙发
请参考如下代码


  1. Imports FarPoint.Win.Spread
  2. Imports FarPoint.Win.Spread.Model

  3. Public Class Form1
  4.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  5.         Dim cfs As FarPoint.Win.Spread.Model.ICustomFunctionSupport
  6.         'Dim fi As FarPoint.CalcEngine.FunctionInfo
  7.         cfs = FpSpread1.ActiveSheet.Models.Data
  8.         cfs.AddCustomFunction(New DateDiffFunctionInfo())
  9.         FpSpread1.ActiveSheet.SetFormula(0, 0, "DAYSDIFF(12/20/2017, 12/12/2017)")
  10.     End Sub
  11. End Class
  12. Public Class DateDiffFunctionInfo
  13.     Inherits FarPoint.CalcEngine.FunctionInfo
  14.     Public Overrides ReadOnly Property Name() As String
  15.         Get
  16.             Return "DAYSDIFF"
  17.         End Get
  18.     End Property
  19.     Public Overrides ReadOnly Property MinArgs() As Integer
  20.         Get
  21.             Return 2
  22.         End Get
  23.     End Property
  24.     Public Overrides ReadOnly Property MaxArgs() As Integer
  25.         Get
  26.             Return 2
  27.         End Get
  28.     End Property
  29.     Public Overrides Function Evaluate(ByVal args() As Object) As Object
  30.         ' Get number of days between dates, return 0 on bad dates
  31.         Dim date1 As Date = FarPoint.CalcEngine.CalcConvert.ToDateTime(args(0))
  32.         Dim date2 As Date = FarPoint.CalcEngine.CalcConvert.ToDateTime(args(1))
  33.         If IsDate(date1) And IsDate(date2) Then
  34.             Return date1.Subtract(date2).Days
  35.         Else
  36.             Return 0
  37.         End If
  38.     End Function
  39. End Class
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部