以下是使用VB.net的SSIS脚本任务
我已经读过这个错误,看来这行有问题: worksheet = CType(workbook.Sheets(4),Excel.Worksheet)
我的代码如下。我认为这对经验丰富的人来说很简单。
文本:
Public Sub Main()
Dim excel As New Excel.Application
Dim filename As String = "S:\UK\Clients\Direct\xxxxxxx.xls"
excel.Visible = True
excel.DisplayAlerts = False
Dim workbook As Excel.Workbook
workbook = excel.Workbooks.Open(filename, , False) 'True = ReadOnly
Dim worksheet As Excel.Worksheet
worksheet = CType(workbook.Sheets(4), Excel.Worksheet)
worksheet.Rows(1).delete()
Dts.TaskResult = ScriptResults.Success
End Sub
答案 0 :(得分:2)
在代码顶部添加Option Strict Off
,这将允许后期绑定。
要了解早期与晚期绑定,请参阅 here
您可以替换此声明
worksheet.Rows(1).delete()
带
Dim rw As Excel.Range
rw = CType(worksheet.Rows(1), Excel.Range)
rw.Delete()
并在顶部设置Option Strict On
您的所有代码都将提前绑定。希望这有帮助