I have a spreadsheet that I'd like to compile into a form that I could call from C#.
Naturally, I'd like to be able to change the inputs to the spreadsheet before reading the calculated result.
What is your recommended method?
UPDATE:
To clarify, I want to make an existing Excel spreadsheet available as a web service that is callable from .NET. I can't have a dependency on Excel, as its running on a web server.
UPDATE:
I used the answer below, and it worked like a charm. Now I can prototype a formula in Excel, then convert it straight into C# and compile it into an assembly.
This question is also covered under Reading Excel Files as a Server Process.
It is quite easy to compile a workbook to EXE. In fact, the Excel compiler XLS Padlock compiles your Excel spreadsheet into an executable application (EXE file) where your formulas, VBA code and workbook file are protected. No complex coding is required.
Click Data>Consolidate (in the Data Tools group). In the Function box, click the summary function that you want Excel to use to consolidate the data. The default function is SUM. Select your data.
Step 1: Open MS Excel. Step 2: Go to Menu and select New >> click on the Blank workbook to create a simple worksheet. OR – Just press Ctrl + N: To create a new spreadsheet. Step 3: By default, Sheet1 will be created as a worksheet in the spreadsheet.
From Microsoft, there appears to be a framework called Excel Services "Develop A Calculation Engine For Your Apps"
Teaser excerpt:
This article discusses:
I have never used it, but the info-graphics on the main page are most encouraging.
Thanks for asking this :)
FlexCel API Mate within TMS Flexcel Studio for .NET lets you convert an existing Excel spreadsheet into C# code, recalculate the spreadsheet, and read the result out of a cell using an API call.
See the video tutorial of FlexCel ApiMate. The video states, quote:
ApiMate will convert an Excel file into a C#, VB.NET or Delphi.NET program.
The docs also state:
Recalculation of more than 200 Excel functions.
and:
You can add your own functions on the code to the already big list implemented by FlexCel, and use them as native functions in your report.
UPDATE
Here is clarification from TMS tech support:
Emailed question:
I'd like to do the following:
In short, I want to use FlexCel as an "Webserver Excel calculation engine", so we don't have to have Excel installed on the web server to perform spreadsheet calculations.
Are the steps I've described possible? Or have I misunderstood how the component works?
Emailed reply:
Besides this, for using it as recalculation engine, we have the "RecalculateCell()" method that won't recalculate the full spreadsheet, but only the cells needed to get the value in an specific cell. So, if for example your result is in A1, you can call RecalcCell in A1, and it will recalculate only all cells needed to get the value in A1 (including dependecies, so if A1 has a formula with a2, and a2 with a3, all 3 will be calculated).
There is also a RecalcExpression method, that will recalculate the value of any formula without needing to write it into a cell. So imagine you have a column of numbers at col A, and you want to know the sum. You could use RecalcExpression("=sum(A:A)"); to know the sum, without needing to enter a formula in B1 with the sum and then reading the value of that formula (which you could also do of course)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With