[英]How do I find the right syntax for VB.Net in SSIS 2013 using Microsoft.Office.Interop.Excel?
I am using SSIS to load data from Excel 2013 to SQL Server 2014. One column has data that exceeds 255 char. 我正在使用SSIS将数据从Excel 2013加载到SQL Server 2014.一列的数据超过255个字符。 Using the source Excel task will only read the first 255 char truncating the rest.
使用源Excel任务只会读取前255个字符,截断其余部分。
I wrote a .vb script to open the file and save it as a csv while also keeping all of the char past 255, however i have not found how to make a specified sheet active before saving it as a csv file. 我写了一个.vb脚本来打开文件并将其保存为csv,同时保持所有char超过255,但是我还没有找到如何在将其保存为csv文件之前激活指定的工作表。
I decided to convert the code to VB.Net using Microsoft.Office.Interop.Excel to access the file, however I still have a problem getting the right syntax. 我决定使用Microsoft.Office.Interop.Excel将代码转换为VB.Net来访问该文件,但是我仍然无法获得正确的语法。 I cannot find anything for VB.Net using Microsoft.Office.Interop.Excel.
我使用Microsoft.Office.Interop.Excel找不到VB.Net的任何内容。
Public Sub Main()
Dim FilePath As String = "I:\DSS Clarity\Clarity Technical\METADATA MINING\INPUT_SAP_BO_UNIVERSE_FILES\"
Dim FileName As String = "UNV Universes.xlsx"
Dim excel As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application
excel.DisplayAlerts = False
' Open Excel spreadsheet.
Dim wb As Workbook
wb = excel.Workbooks.Open(FilePath & FileName)
'wb.Worksheets.Select("Tables") <-- need to make the Tables sheet active - how do i do that?
wb.SaveAs(FilePath & Left(FileName, InStrRev(FileName, ".")) & "csv", 24)
wb.Close()
Dts.TaskResult = ScriptResults.Success
End Sub
I am expecting to see all of the data for a specified sheet saved in csv format, not just the excel constraint of max 255 char for one field. 我希望看到以csv格式保存的指定工作表的所有数据,而不仅仅是一个字段的max 255 char的excel约束。
I made the following edits to your code: 我对您的代码进行了以下编辑:
SaveAs()
function parameters SaveAs()
函数参数 excel.Quit()
command at the end of the script excel.Quit()
命令关闭应用程序 Public Sub Main()
Dim FilePath As String = "I:\DSS Clarity\Clarity Technical\METADATA MINING\INPUT_SAP_BO_UNIVERSE_FILES\"
Dim FileName As String = "UNV Universes.xlsx"
Dim excel As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application
excel.DisplayAlerts = False
' Open Excel spreadsheet.
Dim wb As Workbook
wb = excel.Workbooks.Open(FilePath & FileName)
wb.Worksheets(0).Select(Type.Missing) 'Or try wb.Worksheets(0).Select()
wb.SaveAs(FilePath & Left(FileName, InStrRev(FileName, ".")) & "csv", Excel.XlFileFormat.xlCSV,Excel.XlSaveAsAccessMode.xlNoChange)
wb.Close(false)
excel.Quit()
Dts.TaskResult = ScriptResults.Success
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.