[英]Automating regression analysis excel with C#
I have tried using the following code to run excel regression analysis on the specified range of data. 我尝试使用以下代码在指定的数据范围上运行excel回归分析。 I am getting a com inter-op exception:
我得到一个com互操作异常:
Cannot run the macro 'C:\\Program Files\\Microsoft Office\\Office14\\Library\\Analysis\\ATPVBAEN.XLAM!Regress'
无法运行宏'C:\\ Program Files \\ Microsoft Office \\ Office14 \\ Library \\ Analysis \\ ATPVBAEN.XLAM!回归'
The macro may not be available in this workbook or all macros may be disabled. 宏可能在此工作簿中不可用,或者可能禁用所有宏。
I am not sure how to programmatically enable the add in. This is my solution : 我不知道如何以编程方式启用添加。这是我的解决方案:
xlApp1 = new Microsoft.Office.Interop.Excel.Application();
xlApp1.AddIns.get_Item("Analysis ToolPak").Installed = true;
xlApp1.Run(@"C:\Program Files\Microsoft Office\Office14\Library\Analysis\ATPVBAEN.XLAM!Regress", yValues, xValues, false, false, Type.Missing, output, false, false, false, false, Type.Missing, false, 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);
I think your code is just setting the value of installed = true rather than adding the xlam to the workbook application. 我认为您的代码只是设置installed = true的值而不是将xlam添加到工作簿应用程序。 I gathered this while searching for the answer:
我在寻找答案时收集了这个:
var excel = new Application();
var workbook = excel.workbooks.Add(Type.Missing);
excel.RegisterXLL(pathToXll);
excel.ShowExcel();
How to load an Excel Addin using Interop 如何使用Interop加载Excel Addin
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.