在C#中运行Excel中的vba脚本
当我尝试在C#应用程序的excel文件中运行一个vba脚本时遇到问题。 我的代码是:
public void RunMacro(string path, string macro) { Excel.Application app = null; Excel.Workbooks workbooks = null; Excel.Workbook workbook = null; app = new Excel.Application(); if (app == null) return; app.Visible = false; ChangeCulture(); workbooks = app.Workbooks; workbook = workbooks.Open(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); LogWrapper.Debug("Run Macro start"); app.Run(macro, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing , Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing , Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing , Type.Missing, Type.Missing, Type.Missing); LogWrapper.Debug("Run macro finish"); workbook.Close(false, Type.Missing, Type.Missing); app.Quit(); ReleaseObject(app); ReleaseObject(workbook); }
我点击我的网页浏览器中的button后,运行这个方法,浏览器一直工作(“等待本地主机…”)。 在Firebug中我看不到任何请求。 我的LogWrapper只logging第一个信息(“运行macros启动”)。 事件查看器中没有任何有关此执行的信息。 在任务pipe理器进程EXCEL.EXE使用100%的处理器。 而我等了半个小时的结果仍然是一无所获。
当我将vba脚本名称更改为运行时,出现在excel文件中找不到vba脚本的错误。 我的vba脚本非常简单:
Sub start() Range("A3").Select ActiveCell.Value = "def" Range("A4").Select End Sub
有人知道我应该在哪里search有关这个问题的信息?
这是IIS USER权限的问题。 当我更改权限或打开Windows身份validation时,一切正常。
- 在用C#XmlWriter创build的XML Excel文档的单元格中显示多行文本值
- 阅读肮脏的Excel表格的最佳途径
- 使用Excel数据的简单任务不会导致“ContextSwitchDeadlock”
- Excel C#不能更新:数据库只读
- 每当新版本的excel发布时,引用tlb都会丢失,我必须再次从excel中再次引用.tlb文件
- 如何使用Epplus从Base64编码的图像在Excel中插入图片
- 使用CLSID {00024500-0000-0000-C000-000000000046}检索组件的COM类工厂失败,同时在任务调度程序中configurationexe
- 用c#打开的Excel在服务器上得到错误
- 使用OpenXml将TimeSpan写入单元格,而不使用CellValues.Date DataType