Regression Analysis Automation Surpasses C #

I tried using the following code to run excel regression analysis on a specified data range. I get inter-op exception com:

Cannot start macro 'C: \ Program Files \ Microsoft Office \ Office14 \ Library \ Analysis \ ATPVBAEN.XLAM! Regress'

A macro may not be available in this book, or all macros may be disabled.

I am not sure how to programmatically enable the add. This is my decision:

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);
+3
source share
1 answer

I think your code just sets the value set = true, and does not add xlam to the workbook application. I gathered it looking for the answer:

var excel = new Application();
var workbook = excel.workbooks.Add(Type.Missing);
excel.RegisterXLL(pathToXll);
excel.ShowExcel();

How to download Excel Addin using Interop

+1

Source: https://habr.com/ru/post/1774636/


All Articles