ByteScout Barcode Suite - C# - Use custom functions with spreadsheet sdk - ByteScout

ByteScout Barcode Suite – C# – Use custom functions with spreadsheet sdk

  • Home
  • /
  • Articles
  • /
  • ByteScout Barcode Suite – C# – Use custom functions with spreadsheet sdk

How to use custom functions with spreadsheet sdk in C# using ByteScout Barcode Suite

Learning is essential in computer world and the tutorial below will demonstrate how to use custom functions with spreadsheet sdk in C#

These source code samples are assembled by their programming language and functions they apply. Want to use custom functions with spreadsheet sdk in your C# app? ByteScout Barcode Suite is designed for it. ByteScout Barcode Suite is the bundle that privides 3 SDK products to generate barcodes (Barcode SDK), read barcodes (Barcode Reaer SDK) and read and write spreadsheets (Spreadsheet SDK).

This prolific sample source code in C# for ByteScout Barcode Suite contains various functions and other necessary options you should do calling the API to use custom functions with spreadsheet sdk. Simply copy and paste in your C# project or application you and then run your app! Enjoy writing a code with ready-to-use sample codes in C#.

If you want to try other source code samples then the free trial version of ByteScout Barcode Suite is available for download from our website. Just try other source code samples for C#.

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

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

Program.cs
      
using System; using System.Diagnostics; using Bytescout.Spreadsheet; namespace CustomFunctions { /// <summary> /// This example demonstrates the calculation of custom functions. /// </summary> class Program { static void Main(string[] args) { // Create Spreadsheet instance Spreadsheet spreadsheet = new Spreadsheet(); spreadsheet.RegistrationName = "demo"; spreadsheet.RegistrationKey = "demo"; // Load document spreadsheet.LoadFromFile(@"CustomFuncExample.xlsx"); // Add custom formula handler spreadsheet.CustomFunctionsCallback = new CustomFunctionsCallback(MyFunctions); // Calculate the first worksheet Worksheet 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"); } public static object MyFunctions(string funcName, object[] args, ref bool handled) { // Handle "CUSTOMFUNC_FACTORIAL" function if (String.Compare(funcName, "CUSTOMFUNC_FACTORIAL", StringComparison.OrdinalIgnoreCase) == 0) { handled = true; // Compute factorial if (args.Length > 0) { int value = (int)(double) args[0]; if (value == 0 || value == 1) return 1; int f = 1; for (int i = 1; i <= value; i++) f = f * i; return f; } return null; } // Handle "CUSTOMFUNC_SUM" function if (string.Compare(funcName, "CUSTOMFUNC_SUM", StringComparison.OrdinalIgnoreCase) == 0) { handled = true; // Compute the sum of values if (args.Length > 0) { double sum = 0; foreach (var o in args) sum += (double)o; return sum; } return null; } return null; } } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Barcode Suite Home Page

Explore ByteScout Barcode Suite Documentation

Explore Samples

Sign Up for ByteScout Barcode Suite 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 Barcode Suite Home Page

Explore ByteScout Barcode Suite Documentation

Explore Samples

Sign Up for ByteScout Barcode Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next