简体   繁体   English

从ASP.NET页运行.xlsm文件

[英]Run a .xlsm file from ASP.NET Page

I want to run a .xlsm file from ASP.NET Web Page where it generates some .xml file using VBA code. 我想从ASP.NET网页运行.xlsm文件,在其中使用VBA代码生成一些.xml文件。 The slution suggested here doesn't seem to work in my case. 在我看来, 这里建议的解决方案似乎不起作用。

I tried the following in nmy TestWebApp. 我在nmy TestWebApp中尝试了以下方法。 My Webform1.aspx 我的Webform1.aspx

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"  OnClientClick="return Callxlsm(); "/>
    </div>
    </form>
</body>
    <script type="text/javascript">
        function Callxlsm() {
            alert("Hello");
            var MyObject = new ActiveXObject('WScript.Shell');
            MyObject.Run('file:///K:\NLMData\POC\TestWebApp\TestWebApp\Files\AMM_ModelWizard.xlsm');
        }
    </script>
</html>

in my code behind 在我的代码后面

    using System;

namespace TestWebApp
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Write("Hello");
        }
    }
}

Not sure whats the issue, any pointers pls.Also, can we pass in parameters to this Excel file from the Page so the excel file manipulates them in certain way and generates the XML file? 不知道是什么问题,任何指针都不能。此外,我们可以从Page中将参数传递到此Excel文件中,以便excel文件以某种方式操纵它们并生成XML文件吗?

You should try to use EPPlus to achvieve this. 您应该尝试使用EPPlus实现这一目标。 Look at this question Writing and Executing VBA Macros on Excel without using Excel.Interop 看看这个问题,而不使用Excel.Interop在Excel上编写和执行VBA宏

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

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