Hi,
I'm using Visual Studio 15 with SQL Server Data Tools.
I want to extract values from an excel file with a Script Task using Excel Interop.
In order to do so, I added a reference to Microsoft.Office.Interop.Excel in my Script Task underlying C# project and I added the following code to the Main.
(Reference from GAC : C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll ... version v2.0.50727)
public void Main()
{
string filename = @"C:\temp\test.xlsx";
Microsoft.Office.Interop.Excel.Application excelApplicaiton = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook excelWorkbook =
excelApplicaiton.Workbooks.Open(Filename: filename);
Microsoft.Office.Interop.Excel.Worksheet excelWorksheet = excelWorkbook.ActiveSheet; // line causing the error
Dts.TaskResult = (int)ScriptResults.Success;
}
For an unknown reason, the last line causes the script to fail compiling when closing the Script Task solution and pressing "OK" in the Script Task Editor Window. The code compiles perfectly in a regular C# project (outside a SSIS/Script Task)
Any help would be appreciated.
Thanks, Simon