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

Using Script Task to rename an excel sheet.

$
0
0

I'm trying to use an SSIS Script Task to rename an excel sheet.

I've found several code samples on the net but most don't compile correctly and my knowledge of VB.net or C# isin't strong enough to fix the issues. I suspect they work but not for SSIS 2012 possibly.

Found the sample below which shows no errors at design time, but fails with an Invocation error so I'm unable to even trap what the error is to help in resolving the issue.

Does anyone have any sample code that they KNOW WORKS in SSIS 2012 or can see what the problem is ?

Dim oMissing As Object = System.Reflection.Missing.Value
        Dim xl As New Microsoft.Office.Interop.Excel.ApplicationClass()
        Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
        Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
        Dim laPath As String = "C:\Test.xlsx"

        Try
            xlBook = DirectCast(xl.Workbooks.Open(laPath, oMissing, oMissing, oMissing, oMissing, oMissing, _
            oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, _
            oMissing, oMissing, oMissing), Workbook)

            xlSheet = DirectCast(xlBook.Worksheets.Item(1), Worksheet)
            xlSheet.Name = "Sheet1"
            xlBook.Save()
            xl.Application.Workbooks.Close()

            Dts.TaskResult = ScriptResults.Success

        Catch ex As Exception

            MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK)
            Dts.Events.FireError(1, ex.TargetSite.ToString(), ex.Message.ToString(), "", 0)
            Dts.TaskResult = ScriptResults.Failure

        End Try

Thanks.


Viewing all articles
Browse latest Browse all 24688

Trending Articles



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