I am working on a SSIS project that scans a directory and loops through each excel files that will then be loaded into MSSQL. Currently, I am having an issue with 2966171
being represented as 2.966171e+006
. Here is what I have:
1) The Excel Connection String is passing IMEX=1; (Import Export Mode)
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\UNC\PATH\TO\Excel.xls;Extended Properties="EXCEL 8.0;HDR=NO;IMEX=1";
2) The has confirmed the data type for this field is DT_WSTR of length 255.
Things I have tried:
1) Changing the datatype in Excel to Text
2) Creating a script component that explicitly converts a string to a decimal back to a string. (Terrible Approach)
3) Casting in a derived column component.
EDIT: I must keep this column a DT_WSTR type, some other rows contain alphanumeric values.
答案 0 :(得分:0)
使用For-each循环控件循环遍历excel文件 并将文件路径映射到变量(例如:@ [User :: strExcelFile])
在foreach容器中,您必须使用2个数据流任务; 第一个包含一个excel源和一个脚本组件作为目标,第二个DataFlowTask是你的任务
如果excel文件具有相同的结构,则必须按照以下步骤操作:
首先添加Microsoft.Office.Interop.Excel.dll作为参考
使用以下代码从变量中读取ExcelFile路径:
Imports Microsoft.Office.Interop.Excel
Dim strExcelFiles As String = String.Empty
Public Overrides Sub PreExecute()
MyBase.PreExecute()
strExcelFiles = Variables.strExcelFile
End Sub
第三,在Main Sub write中创建一个Excel.application,将Visible属性设置为false 打开ExcelFile并将EntireColumnType更改为Number并保存Excel文件并使用以下代码关闭应用程序:
Dim ColIdx As Integer = 0 'Number Column index
Dim appExcel As New Excel.Application
appExcel.Visible = False
Dim wrkbExcel As New Excel.Workbook
wrkbExcel = appExcel.Workbooks.Open(strExcelFile)
Dim wrkshExcel As Excel.Worksheet = wrkbExcel.Worksheets(0)
wrkshExcel.Cells(1, ColIdx).EntireColumn.NumberFormat = "0"
'this will change the EntireColumn Type to Number and eliminate scientific character E+
wrkbExcel.Close(True)
appExcel.Quit()
简介,每个Excel文件在导入数据之前都必须进行编辑,因为当数字存储在数据类型与数字不同的单元格中时会出现科学符号