【发布时间】:2017-04-19 11:29:16
【问题描述】:
我想从 ASP.NET 网页运行一个 .xlsm 文件,它使用 VBA 代码生成一些 .xml 文件。建议的解决方案 here 在我的情况下似乎不起作用。
我在 nmy TestWebApp 中尝试了以下操作。 我的 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>
在我的代码后面
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");
}
}
}
不确定是什么问题,请提供任何指针。另外,我们可以从页面将参数传递给这个 Excel 文件,以便 excel 文件以某种方式操作它们并生成 XML 文件吗?
【问题讨论】:
-
你不能。宏需要 Excel 本身才能运行。你想做什么?可能有更好的方法可以做到这一点,例如使用数据连接而不是宏来加载数据。在服务器上运行宏不是一个好主意,它们过于繁重,并且通常(总是)不适合像 Web 应用程序这样的高流量环境。