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

Rename Excel Tab

$
0
0

Hi Guys,

Need urgent help. 

I am working on project in SSIS. Simple SSIS Package, read file from Excel and do some transformation and insert the data into SQL table (Very simple). Problem is Every time excel file has different tab. So What I am doing, I am using Script task (VB 2008) to rename Excel tab to "Sheet1", working fine on my local without any problem. Here is my VB Code. In my Local machine Microsoft Office are installed. Now I have to move this package to Dev Inv. Unfortunately my Dev and Prod server doesn't have MS Office installed. I am having a problem to run or rename excel sheet. 
Two questions
1) Is there other way to rename or read dynamic excel tab from Excel source?
2) Is there a way we can Open Excel file/rename and save Excel file in VB without MS Office installed?

I am using SQL Server 2008 R2.

Please advise.

Thank You.


Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.Office.Interop.Excel
Imports System.IO
Imports System.Text


<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum



Public Sub Main()
Dts.VariableDispenser.LockForRead("User::FileName") ' File Name Variable

Dim variablesList As Variables

Dts.VariableDispenser.GetVariables(variablesList)

' Dim SFileName As String

'SFileName = variablesList("User::Filename").Value.ToString


' Dim vars As Variables 'New Added For Variable
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

'Dts.VariableDispenser.LockForRead("Filename") 'New Added For Variable



'Start For Variable
'Dim File As String 'New Added For Variable

'File = CType(vars("Filename").Value, String) 'New Added For Variable

Dim lapath As String = variablesList("User::FileName").Value.ToString 'New Added For Variable


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 = "data"
xlBook.Save()
xl.Application.Workbooks.Close()

Dts.TaskResult = ScriptResults.Success
End Sub

End Class


Viewing all articles
Browse latest Browse all 24688

Trending Articles



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