SciCalc 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SciCalc --version 0.1.0                
NuGet\Install-Package SciCalc -Version 0.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SciCalc" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SciCalc --version 0.1.0                
#r "nuget: SciCalc, 0.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SciCalc as a Cake Addin
#addin nuget:?package=SciCalc&version=0.1.0

// Install SciCalc as a Cake Tool
#tool nuget:?package=SciCalc&version=0.1.0                

XLFormulaParser

XLFormulaParser is a .NET library designed to parse and evaluate Excel-like formulas, including basic mathematical operations, cell references, ranges, and common functions (e.g., SUM, AVERAGE, MAX, etc.). This lightweight parser is ideal for projects that require Excel-like formula processing without depending on Excel itself.

Features

  • Basic Arithmetic: Supports operators like +, -, *, /, ^.
  • Comparisons: Includes operators like =, <>, <, >, <=, >=.
  • Excel Functions: Evaluate functions such as SUM, AVERAGE, COUNT, MAX, MIN, MEDIAN, STDEV, VAR, ROUND, and more.
  • Cell References and Ranges: Use cell references (A1, B2, etc.) and ranges (A1:B2) to retrieve and compute values.
  • Custom Functions: Extend the parser by adding custom functions to suit specific needs.

Installation

You can install XLFormulaParser via NuGet:

dotnet add package XLFormulaParser

Or, add it directly to your .csproj file:

<PackageReference Include="XLFormulaParser" Version="0.1.0" />

Basic Setup

using System;
using XLFormulaParser;

var parser = new XLFormulaParser();

// Define a function to get cell values based on their references
Func<string, object> getCellValue = reference =>
{
    // Return a value based on the cell reference; in practice, retrieve from your data source
    return reference switch
    {
        "A1" => 10,
        "A2" => 20,
        _ => 0
    };
};

// Evaluate a simple formula
string formula = "SUM(A1, A2, 30) / 2";
var result = parser.Evaluate(formula, getCellValue);

Console.WriteLine(result);  // Outputs: 30

Adding Custom Functions

parser.AddLookupFunction("CUSTOMFUNC", args =>
{
    // Implement your custom function logic here
    return args.Sum(x => Convert.ToDouble(x)) * 2;
});

// Using the custom function in a formula
string customFormula = "CUSTOMFUNC(A1, A2)";
var customResult = parser.Evaluate(customFormula, getCellValue);
Console.WriteLine(customResult);  // Output will depend on the custom function logic

Contributing

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Commit and push your changes.
  4. Open a pull request with a clear description of your changes.

Reporting Issues

Please open an issue in the GitHub repository if you encounter any bugs or have suggestions.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.3 81 11/3/2024
0.1.2 85 10/31/2024
0.1.1 70 10/31/2024
0.1.0 87 10/28/2024