简体   繁体   中英

Run Excel macro when excel is not installed

I have a excel workbook. I need to show it as a HTML page that will be refreshed automatically(say every 2 minutes). For that i need to run the calculations on every sheet and then save as HTML. I will figure out later how to swap the new HTML file for the old one later. I already have a macro in excel that does all the calculations and then saves as HTML every 2 min. All i need to do is call that macro

The problem is that the machine on which all this is to take place is a server machine and thus MS office cannot be installed on it. Thus i cannot use Excel COM Inter-op.

One was is if i could write a .net program or a Vb Script that will run the macro. But a .net program always uses inter-op.

Another way is if i could save the book as a HTML and run the macro in the HTML itself(Dont know if the HTML has the VB A code). Here also i found that i require Visual Basic Editor which i cant install( as it comes with excel only).

I would prefer not to use third party soft wares.

Can any of the above two procedures be implemented in the given conditions? if not is there any other way?

UPDATE:

Have been looking into open XML for a solution and have finally found that open XML 2.0 cannot run excel calculations as the SDK does not have the calculation engine. Does open XML SDK 2.5 have the calculation engine??

In short: You cannot run a macro without Excel installed. Worse: You should not intsall Excel on a Server. It is not recommended and impossible to do this in a stable way. My best bet would be something like this: Use a :net library which can read xlsx files, like EPPLUS and "translate" this macro into net, which the EPPLUS library as its foundation. Also, this is a lot fastrer than Interop (factor 10 - 100) and fits better into a Server infrastructure with ASP.NET (for example).

Have you considered putting the macro as a .NET Managed AddIn on a shared machine, executing the macro from the server using a shell command to open Excel on the shared machine and the macro runs on Open.

Then you can get the macro itself to export the data to HTML and copy the pages to your server.

As has been said, avoid installing Office on a server (though it has been done in the past, it's never advisable)

Most robust option would be to re-write your vba in .NET as a .NET Managed AddIn - then you have more control over processes, but as has been pointed out, NOT on a Server.

Thanks for the resonses. Found a way to show the excel as HTML in the given conditions.

Just FYI, I used a project known as NPOI. It is the .net version of POI used in java. It allows me to open edit and save excel workbooks without installing excel. plus it is opensource so i customized it according to my requirements.

https://npoi.codeplex.com/

https://github.com/tonyqus/npoi

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