I am using a script task to delete particular rows in an Excel in SSIS. Previously it was working fine, then when I try to implement everything again I am getting error in the .Delete() codes. Find my code below,
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
var dir = new System.IO.DirectoryInfo(@"D:\Data_Processing\Input");
var fullFilePath = dir.GetFiles("*.xlsx").Select(f => f.FullName).FirstOrDefault();
if (fullFilePath != null)
{
Microsoft.Office.Interop.Excel.Workbook workBook = excelApp.Workbooks.Open(fullFilePath);
foreach (Worksheet sheet in workBook.Worksheets)
{
sheet.Rows[8].Delete();
sheet.Rows[7].Delete();
sheet.Rows[6].Delete();
sheet.Rows[5].Delete();
sheet.Rows[4].Delete();
sheet.Rows[3].Delete();
sheet.Rows[2].Delete();
sheet.Rows[1].Delete();
}
workBook.Save();
workBook.Close(false);
excelApp.Application.Quit();
System.IO.File.Move(fullFilePath, @"D:\HC_Report.xlsx");
Dts.Variables["User::FileExistsFlg"].Value = 1;
}
else
{
Dts.Variables["User::FileExistsFlg"].Value = 0;
}
Dts.TaskResult = (int)ScriptResults.Success;
And when I try to add Microsoft.Office.Interop.Excel in the References it is coming with a different icon as below
Can anyone please help with this?
Thanks,
I have manually added the.dll file from this location C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll and then the error disappeared.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.