ByteScout Data Extraction Suite - C# - Use custom functions with spreadsheet sdk - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

ByteScout Data Extraction Suite – C# – Use custom functions with spreadsheet sdk

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

How to use custom functions with spreadsheet sdk in C# with ByteScout Data Extraction Suite

If you want to learn more then this tutorial will show how to use custom functions with spreadsheet sdk in C#

Quickly learn how to use custom functions with spreadsheet sdk in C# with this sample source code. What is ByteScout Data Extraction Suite? It is the bundle that includes three SDK tools for data extraction from PDF, scans, images and from spreadsheets: PDF Extractor SDK, Data Extraction SDK, Barcode Reader SDK. It can help you to use custom functions with spreadsheet sdk in your C# application.

The following code snippet for ByteScout Data Extraction Suite works best when you need to quickly use custom functions with spreadsheet sdk in your C# application. Just copy and paste the code into your C# application’s code and follow the instructions. Want to see how it works with your data then code testing will allow the function to be tested and work properly.

You can download free trial version of ByteScout Data Extraction Suite from our website with this and 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 Data Extraction Suite Home Page

Explore ByteScout Data Extraction Suite Documentation

Explore Samples

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

Explore ByteScout Data Extraction Suite Documentation

Explore Samples

Sign Up for ByteScout Data Extraction Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next