/ / Wie kann ich eine Excel-Formel analysieren? - c #, vb.net, übertreffen

Wie kann ich eine Excel-Formel analysieren? - c #, vb.net, übertreffen

Ich konvertiere die in einem komplexen Excel-Datenblatt enthaltenen Funktionen in ein ASP.Net-Projekt. In diesem Fall muss ich Excel wie Formula mit VB.NET oder c # analysieren.

Ich habe eine gitterähnliche Struktur, die Abrechnungszahlen anzeigt, und der Benutzer darf die Formel in den erforderlichen Zellen vorkonfigurieren.

Beispiel: - In meinem Datagrid Cell [2] [1] sollte ich konfigurieren können

Formel = Summe (Zelle [1] [1] + Zelle [1] [2]) .

Gibt es eine Möglichkeit, die Excel-Formel von vb.net/c# zu analysieren / verarbeiten?

Antworten:

0 für die Antwort № 1

Sie könnten umgehen FLIEHEN Bibliothek zur Auswertung von C # -ähnlichen Ausdrücken

// Create the calculation engine
CalculationEngine engine = new CalculationEngine();
ExpressionContext context = new ExpressionContext();
VariableCollection variables = context.Variables;

// Add some variables
variables.Add("x", 100);
variables.Add("y", 200);

// Add an expression to the calculation engine as "a"
engine.Add("a", "x * 2", context);

// Add an expression to the engine as "b"
engine.Add("b", "y + 100", context);

// Add an expression at "c" that uses the results of "a" and "b"
engine.Add("c", "a + b", context);

// Get the value of "c"
int result = engine.GetResult<int>("c");

// Update a variable on the "a" expression
variables["x"] = 200;

// Recalculate it
engine.Recalculate("a");

// Get the updated result
result = engine.GetResult<int>("c");