我们可以使用asp.net运行宏吗?如果是这样,如何在IIS中部署? [英] Can we run macro using asp.net ? If so, how to deploy in IIS ?

查看:87
本文介绍了我们可以使用asp.net运行宏吗?如果是这样,如何在IIS中部署?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我已经实施了Asp.net应用程序。在那个应用程序中,我试图调用Macro。它在当地工作得很好。当我在IIS 7中部署时,我得到以下错误。请任何人都可以帮助我。



Hi All,

I have implemented Asp.net application. In that application i was trying to call Macro. It was working fine in local. When i deploy in IIS 7, i m getting below error. Please any one can help me.

System.UnauthorizedAccessException

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.





ASP.Net代码



ASP.Net Code

string executableLocation = Server.MapPath("~/AMDReport/Macro/");
        string xslLocation = Path.Combine(executableLocation, "AMD_to_Interface_Prerequisites.xlsm");


        // Object for missing (or optional) arguments.
        object oMissing = System.Reflection.Missing.Value;

        // Create an instance of Microsoft Excel
        Excel.ApplicationClass oExcel = new Excel.ApplicationClass();

        // Make it visible
        oExcel.Visible = true;

        // Define Workbooks
        Excel.Workbooks oBooks = oExcel.Workbooks;
        Excel._Workbook oBook = null;

        // Get the file path
        string path = xslLocation;

        //Open the file, using the 'path' variable
        oBook = oBooks.Open(path, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);

        // Run the macro, "First_Macro"
        RunMacro(oExcel, new Object[] { "Macro_AMD_to_Interface_Prerequisites" });

        // Quit Excel and clean up.
        oBook.Close(false, oMissing, oMissing);
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook);
        oBook = null;
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks);
        oBooks = null;
        oExcel.Quit();
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel);
        oExcel = null;

        //Garbage collection
        GC.Collect();

推荐答案

错误80040154表示服务器上未安装Office。



您应该阅读以下Microsoft知识库文章:

Error 80040154 means Office is not installed on the server.

You should read the following Microsoft knowledgebase article:



Microsoft目前不建议也不支持从任何无人参与的非交互式客户端应用程序或组件(包括ASP,ASP.NET)自动化Microsoft Office应用程序,DCOM和NT服务),因为Office在此环境中运行时可能会出现不稳定的行为和/或死锁。


Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.





似乎没有以任何方式执行宏没有 Excel,但使用ASP.NET中的Excel并不容易,推荐或支持。



There doesn't seem to be any way to execute macros without Excel, but using Excel from ASP.NET is not easy, recommended, or supported.


看看这里:< a href =http://www.codeproject.com/Articles/664154/Programmatic-Execution-of-an-Ex>从网站上远程机器上的Excel宏的编程执行 [ ^ ]



我建议阅读: Office的服务器端自动化的注意事项 [ ^ ]。请注意
Have a look here: Programmatic Execution of an Excel Macro on Remote Machine from a Website[^]

I'd suggest to read this: Considerations for server-side Automation of Office[^]. Note that
MS写道:

Microsoft强烈建议许多不需要安装Office的替代方案服务器端,可以比自动化更高效,更快地执行大多数常见任务。

Microsoft strongly recommends a number of alternatives that do not require Office to be installed server-side, and that can perform most common tasks more efficiently and more quickly than Automation.





Finall结论:不要专注于MS Excel。而不是它,尝试创建自定义类来操纵数据。



Finall conclusion: Do not focus on MS Excel. Rather than it, try to create custom classes to manipulate data.


这篇关于我们可以使用asp.net运行宏吗?如果是这样,如何在IIS中部署?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆