简体   繁体   中英

Calculations in excel using .net

Hi Stackoverflow Users

I was recently assigned to rewrite a excel document my company uses a lot. Originally it was written in matlab, but to easier distribute it, they migrated it to excel. It was done very bad, and therefore it worked on some computers and not on others. So it was rewritten to vba. But now they want it to be able to do very complex calculations like Monte Carlo simulations. therefore we wish to write it in c#.net for performance and development reasons. the last week i have tried and tried to learn how it was best done. I found several possible solutions, but i have not found a single way to do it which meets my 2 simple demands:

  1. The user doesn't have to go to any settings and add something, if it have to be done, it need to be done in code

  2. The calculations is done at the press of a button, so i need to be able to receive the event

I have spent so much time on the web, but i don't know exactly what to search for, so it all just seems like a big wall of unexplained, complex com-magic.

So what are your suggestion? Is there any solution which meet those demands? Any suggestions, references or any other help will be deeply appreciated.

Excel doesn't natively support C# in macros, so you're not going to be able to meet your first demand in a stand-alone spreadsheet. If you're willing to install an add-on into Excel, you might want to consider Excel-DNA . This would allow you to compile a .NET DLL containing the functions you want to add in to Excel.

Receiving an event from a button click is simply a case of adding a button control onto a sheet, and assigning a macro to it. This macro (eg a VBA function) will be run on demand when you click the button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM