I'm using a script task to open and change file format of an excel XML Spreadsheet 2003 file to a Excel Workbook.
The package runs fine on development machine on VS 2015, but fails with a vague error message on server.
'Script Task: Error: Exception has been thrown by the target of an invocation.'
The package also runs fine on the server after I manually open the file and change the file format from XML Spreadsheet 2003 to Excel Workbook.
I've narrowed it down to the open command of my Office Interface Excel Workbook.
Here's my script main
public void Main(){
// TODO: Add your code here
var format = (Microsoft.Office.Interop.Excel.XlFileFormat)XlFileFormat.xlWorkbookNormal;
FileInfo file = new FileInfo(@"C:\Temp\EmailAttachments\New folder\Open_PO_Lines_03Feb2017_0915AM.xls");
object misValue = System.Reflection.Missing.Value;
var excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.Visible = false;
excelApp.DisplayAlerts = false;
Microsoft.Office.Interop.Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(file.FullName);
excelWorkbook.SaveAs(file.FullName, format);
excelWorkbook.Close();
excelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
excelApp = null;
Dts.TaskResult = (int)ScriptResults.Success;
}