简体   繁体   English

未安装excel时运行Excel宏

[英]Run Excel macro when excel is not installed

I have a excel workbook. 我有一个Excel工作簿。 I need to show it as a HTML page that will be refreshed automatically(say every 2 minutes). 我需要将其显示为将自动刷新的HTML页面(例如每2分钟刷新一次)。 For that i need to run the calculations on every sheet and then save as HTML. 为此,我需要在每个工作表上运行计算,然后另存为HTML。 I will figure out later how to swap the new HTML file for the old one later. 稍后,我将弄清楚如何将新的HTML文件替换为旧的HTML文件。 I already have a macro in excel that does all the calculations and then saves as HTML every 2 min. 我已经在excel中有了一个宏,可以执行所有计算,然后每2分钟将其另存为HTML。 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. 问题是,要在其上进行所有操作的计算机是服务器计算机,因此无法在其上安装MS Office。 Thus i cannot use Excel COM Inter-op. 因此,我无法使用Excel COM Inter-op。

One was is if i could write a .net program or a Vb Script that will run the macro. 一种是我是否可以编写将运行宏的.net程序或Vb脚本。 But a .net program always uses inter-op. 但是.net程序始终使用互操作。

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). 另一种方法是,如果我可以将书另存为HTML并在HTML本身中运行宏(不知道HTML是否具有VBA代码)。 Here also i found that i require Visual Basic Editor which i cant install( as it comes with excel only). 在这里我也发现我需要无法安装的Visual Basic编辑器(仅随Excel附带)。

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. 一直在研究开放XML的解决方案,最后发现开放XML 2.0无法运行excel计算,因为SDK没有计算引擎。 Does open XML SDK 2.5 have the calculation engine?? Open XML SDK 2.5是否具有计算引擎?

In short: You cannot run a macro without Excel installed. 简而言之:如果未安装Excel,则无法运行宏。 Worse: You should not intsall Excel on a Server. 更糟:您不应该在服务器上安装Excel。 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. 我最好的选择是:使用一个:net库,它可以读取xlsx文件(例如EPPLUS),并将此宏“转换”为net,这是EPPLUS库的基础。 Also, this is a lot fastrer than Interop (factor 10 - 100) and fits better into a Server infrastructure with ASP.NET (for example). 而且,这比Interop(系数10-100)要快得多,并且更适合使用ASP.NET的服务器基础结构(例如)。

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. 您是否考虑过将宏作为共享计算机上的.NET Managed AddIn放置,使用shell命令从服务器执行宏以在共享计算机上打开Excel,并且宏在Open上运行。

Then you can get the macro itself to export the data to HTML and copy the pages to your server. 然后,您可以获取宏本身,以将数据导出到HTML并将页面复制到服务器。

As has been said, avoid installing Office on a server (though it has been done in the past, it's never advisable) 如前所述,避免在服务器上安装Office(尽管过去已经做到了,但绝对不建议这样做)

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. 最可靠的选择是将.NET中的vba重新编写为.NET托管加载项-这样,您就可以更好地控制进程,但正如前面指出的那样,而不是在服务器上。

Thanks for the resonses. 感谢您的共鸣。 Found a way to show the excel as HTML in the given conditions. 找到了一种在给定条件下将Excel表现为HTML的方法。

Just FYI, I used a project known as NPOI. 仅供参考,我使用了一个称为NPOI的项目。 It is the .net version of POI used in java. 它是Java中使用的POI的.net版本。 It allows me to open edit and save excel workbooks without installing excel. 它使我无需安装excel就可以打开编辑并保存excel工作簿。 plus it is opensource so i customized it according to my requirements. 加上它是开源的,所以我根据我的要求对其进行了定制。

https://npoi.codeplex.com/ https://npoi.codeplex.com/

https://github.com/tonyqus/npoi https://github.com/tonyqus/npoi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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