SciCalc 0.1.3
dotnet add package SciCalc --version 0.1.3
NuGet\Install-Package SciCalc -Version 0.1.3
<PackageReference Include="SciCalc" Version="0.1.3" />
paket add SciCalc --version 0.1.3
#r "nuget: SciCalc, 0.1.3"
// Install SciCalc as a Cake Addin #addin nuget:?package=SciCalc&version=0.1.3 // Install SciCalc as a Cake Tool #tool nuget:?package=SciCalc&version=0.1.3
SciCalc - XLFormulaParser
SciCalc - 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 SciCalc - XLFormulaParser
via NuGet:
dotnet add package SciCalc
Or, add it directly to your .csproj file:
<PackageReference Include="SciCalc" Version="0.1.0" />
Basic Setup
using System;
using using static SciCalc.Sci;
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
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit and push your changes.
- 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 | Versions 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. |
-
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.