Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Unable to delete sheet from Excel using SSIS

$
0
0

I am creating a ssis package. This package splits a table's data and export it across multiple tabs in a excel file based on the column value in the table. . The excel file generated dynamically during the run-time. the output excel is having an additional tab which I need to delete. I tried Script task  and Execute sql task using Excel as the Connection Manager. But it gives error.

I wrote below code in Script taks (c#)

public void Main()
  {
   // TODO: Add your code here

 
              Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
              xlApp.DisplayAlerts = false;
              string filename = "@"+ Dts.Variables["User::filename"].Value.ToString();
            xlApp.DisplayAlerts = false;
            Excel.Workbook xlWorkBook = xlApp.Workbooks.Open(filename, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
    
            Excel.Sheets worksheets = xlWorkBook.Worksheets;

              worksheets[1].Delete();

             xlWorkBook.Save();

            xlWorkBook.Close();

            Marshal.ReleaseComObject(worksheets);
            xlApp.Quit();

            Dts.TaskResult = (int)ScriptResults.Success;
  }

Please help me solve the issue


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>