How can I evaluate Excel functions in c# Console App? - c#

I have to create a function in C# allowing to calculate Excel formulas entered in a string:
for example :
ROUND(COUNTIF(['YES', 'NO'],'YES')*(100/4),1)
I absolutely have to use a free library, but I can't find anything to do so in C#.
Has anyone come across this problem before ?
Thanks for your help
Explications of the app context :
This function receives as a parameter a string which has already been generated on another application over which I do not have control.
the need is to find a way evaluate this kind of string containing some Excel functions.

EPPlus v4 is LGPL. It can create Excel files but not execute them AFAIK. But you could automate Excel afterwards.
As #DS_London said: it is a weird use case, are you sure you got it right?

Related

How do I get my dynamo code into visual studio?

I currently have a dynamo project with a useful macro that I use in Revit, however, I can only run this if I have dynamo and Revit open at the same time.
I would like to add this macro onto my ribbon tab within Revit but cannot do this while the macro is built in dynamo.
Is there a way I can either:
Export the macro I have made inside dynamo into a .dll?
Open it up in visual studio and build the code in there?
View the code in dynamo?
Many thanks,
Dan
There are a number of ways to achieve this.
Most of them involve several different translation steps.
All of them would require you to access, extract and save the Python source code in an external text file to begin with.
Not being very familiar with the Dynamo and Python side of things, coming from the C# .NET add-in side, I would suggest trying to integrate your code into the pyRevit IronPython script library once you have it in hand:
http://thebuildingcoder.typepad.com/blog/2016/04/the-pyrevit-ironpython-script-library.html
Afaik, that is easy and provides exactly what you are asking for.

Is it possible to run prolog from C#?

I want to call a prolog program from C#. Is that possible?
I process the user input by c# and write into a file. I then want to call a prolog program which uses that file, then I want to show the content of the file to the user by c#.
Yes, if you don't want to link the two programs to a single binary but simply have one (C#) call the other (prolog) this can be done. And for any other language you can run on your computer too.
If you base your data exchange on files you need one file to send data from C#->prolog and perhaps a second one to return the result (prolog->C#)
You will find lots of examples to make C# call an external program here on SO (for example Launching an application (.EXE) from C#?)
If prolog does not allow you to pass the filename as parameter when you call it you will have to work with fixed filenames:
C# writes a request.txt
C# calls prolog program
Prolog reads request.txt and creates response.txt
Reading from files should be covered by the language, depending on the "dialect" even reading command line parameters should be.
If you use SWI-Prolog, you should google SWI-Prolog interface to C# and F#

Excel 2010 equation editor access via C#(VSTO)/ VBA

I need to get access to Equation Editor that's built in Excel 2010. In Word2010 it's quite simple as it provides OMath interface to access it via C# or VBA. There's no such thing in Excel eventhough it's possible to insert equations this way. Has anyone solved this problem ?
I need to extract the equation from the eqution object in a text way (no metter if it's Latex, MATHML or any other language. It just has to be a single string)
Of course I can use MathType to do this (Actually I've alredy done this with MathType) but I don't want to force the User to buy MathType as Excel has built in feature that would do the trick.
Have you tried adding an OLE object first, as mentioned in this link?
http://www.techyv.com/questions/it-possible-equation-editor-vba-excel-2010
I don't have an enormous amount of experience with Excel's equation behaviour but it seems Excel doesn't use the OMath object. As far as I understand:
You can add a new Equation with:
ActiveSheet.OLEObjects.Add(ClassType:="Equation.3", Link:=False, DisplayAsIcon:=False)
And subsequently, you can access these objects using the OLEObjects collection:
ActiveSheet.OLEObjects.Item(1)

Call VB method in C# using Interop

Okey here's the situation: I've got a microsoft excel macro in vb that I want to call using C#. I've already tried creating a workbook using Microsoft.Office.Interop.Excel, however I don't want to have to run an excel process to run the macro.
So then I thought why not make a vb class library with my code in it so i can still run it and have a clean dll file. It's not needed to keep any sheet related functions since the macro reads a .lua(UTF-8)text file with some advanced regex functions that I just can't get recreated in C#.
Is it possible for me to make the library use interop as well so i can just call the function in my C#? Any examples would be greatly appreciated.
First I assume you are working with VB6 and not VB Script?
I have never worked with VB 6 or earlier, but I think your best be will be to create a COM object and then you can call the COM object from .NET using C#. Here is a quick link I found through BING that I believe will help you get started if this in an option for you.
Walkthrough: Implementing Inheritance with COM Objects (Visual Basic)
I noticed these two statements:
I don't want to have to run an excel process to run the macro
and
the macro reads a .lua(UTF-8)text file with some advanced regex functions that I just can't get recreated in C#
Those two goals are incompatible. The macro relies on excel functions to run. The only way provided by Microsoft to accomplish this is to completely load the Excel app. There is no way to only run the macro.

Simple ,fast script support for a c# application

I have developed an application which can create Xml files from Xml schema with some user defined rules for generating value for each node.
I want to give my user the ability to write scripts for generating value for each node and in this scripts user should be able to refer to generated value of other nodes .
a simple script will be something like :
returtn (#node1.value + 10) ;
I don't know what will be the value of #node1.value because the file generation process hasn't started yet.
so what is the solution do I have to replace it every time with the generated value and then run the script or is there a better way to do something like this ?
may be I have to run this script thousand of times to generate value for created instances so which scripting language is the fastest one for me to use ?
thanks
You can look at IronPython.
If you are looking for a script language with a sysntax similar to C#, then you can look at CS-Script.
Have you looked at using C# as your scripting language?
http://www.csscript.net/
Use locks :-). If someone invokes get_method of the property that isn't set just lock the caller until value is set.
PowerShell embeds well into a C# application, here's how from the PowerShell Team Blog

Categories

Resources