如何使用C#运行现有excel工作表的excel宏?
您好,我正在尝试使用C#(visual studio)自动打开excel工作簿并为web应用程序运行其宏,是否有人建议这是否可行。您好,我在web上找到了一个解决方案,可用于如何运行现有应用程序的excel宏, 并运行其宏 此处宏的名称为:来自工作簿macro.xlsm的宏 下面是代码片段:如何使用C#运行现有excel工作表的excel宏?,c#,asp.net,excel,C#,Asp.net,Excel,您好,我正在尝试使用C#(visual studio)自动打开excel工作簿并为web应用程序运行其宏,是否有人建议这是否可行。您好,我在web上找到了一个解决方案,可用于如何运行现有应用程序的excel宏, 并运行其宏 此处宏的名称为:来自工作簿macro.xlsm的宏 下面是代码片段: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.U
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Office.Interop;
using Excel = Microsoft.Office.Interop.Excel;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
//~~> Define your Excel Objects
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkBook;
//~~> Start Excel and open the workbook.
xlWorkBook = xlApp.Workbooks.Open("C:\\Users\\d.b.venkatachalam\\Desktop\\Macro.xlsm");
xlApp.Visible = true;
//~~> Run the macros by supplying the necessary arguments
xlApp.Run("Macro");
}
}
}
当您说“对于web应用程序”-宏是在客户端还是在服务器上执行?(注意:如果答案是“在服务器上”,您应该寻找解决问题的替代方案)。