ByteScout Spreadsheet SDK - VB.NET - Set Custom Functions - ByteScout

ByteScout Spreadsheet SDK – VB.NET – Set Custom Functions

  • Home
  • /
  • Articles
  • /
  • ByteScout Spreadsheet SDK – VB.NET – Set Custom Functions

How to set custom functions in VB.NET using ByteScout Spreadsheet SDK

The tutorial shows how to set custom functions in VB.NET

These sample source codes on this page below are demonstrating how to set custom functions in VB.NET. What is ByteScout Spreadsheet SDK? It is the library (SDK) that is capable of writing, reading, modifying and calculating Excel and CSV spreadsheets. Most popular formulas can be calculated and reculculated with Excel installed. You may import or export data to and from CSV, XML, JSON as well as to and from databases, arrays. It can help you to set custom functions in your VB.NET application.

VB.NET code samples for VB.NET developers help to speed up coding of your application when using ByteScout Spreadsheet SDK. In order to implement the functionality, you should copy and paste this code for VB.NET below into your code editor with your app, compile and run your application. Enjoy writing a code with ready-to-use sample VB.NET codes.

Download free trial version of ByteScout Spreadsheet SDK from our website with this and other source code samples for VB.NET.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

Module1.vb
      
Imports Bytescout.Spreadsheet Module Module1 ' This example demonstrates the calculation of custom functions. Sub Main() ' Create Spreadsheet instance Dim spreadsheet As New Spreadsheet() spreadsheet.RegistrationName = "demo" spreadsheet.RegistrationKey = "demo" ' Load document spreadsheet.LoadFromFile("CustomFuncExample.xlsx") ' Add custom formula handler spreadsheet.CustomFunctionsCallback = AddressOf MyFunctions ' Calculate the first worksheet Dim worksheet = spreadsheet.Workbook.Worksheets(0) worksheet.Calculate() ' Save calculated values to neighbor cells to demonstrate custom functions are calculated worksheet("C2").Value = worksheet("B2").Value worksheet("C3").Value = worksheet("B3").Value worksheet("C4").Value = worksheet("B4").Value ' Save modified spreadsheet spreadsheet.SaveAs("result.xlsx") ' Cleanup spreadsheet.Dispose() ' Open saved spreadsheet in associated application (for demo purpose) Process.Start("result.xlsx") End Sub Private Function MyFunctions(ByVal funcname As String, ByVal args As Object(), ByRef handled As Boolean) As Object ' Handle "CUSTOMFUNC_FACTORIAL" function If String.Compare(funcname, "CUSTOMFUNC_FACTORIAL", StringComparison.OrdinalIgnoreCase) = 0 Then handled = True ' Compute factorial If args.Length > 0 Then Dim value As Integer = args(0) If value = 0 Or value = 1 Then Return 1 End If Dim f As Integer = 1 For i As Integer = 1 To value f = f * i Next Return f End If Return Nothing End If ' Handle "CUSTOMFUNC_SUM" function If String.Compare(funcname, "CUSTOMFUNC_SUM", StringComparison.OrdinalIgnoreCase) = 0 Then handled = True ' Compute the sum of values If args.Length > 0 Then Dim sum As Double For Each o As Object In args sum = sum + o Next Return sum End If Return Nothing End If Return Nothing End Function End Module

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Spreadsheet SDK Home Page

Explore ByteScout Spreadsheet SDK Documentation

Explore Samples

Sign Up for ByteScout Spreadsheet SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Spreadsheet SDK Home Page

Explore ByteScout Spreadsheet SDK Documentation

Explore Samples

Sign Up for ByteScout Spreadsheet SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next