简体   繁体   中英

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. The slution suggested here doesn't seem to work in my case.

I tried the following in nmy TestWebApp. My 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?

You should try to use EPPlus to achvieve this. Look at this question Writing and Executing VBA Macros on Excel without using Excel.Interop

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