经测试是你后缀名.TXT和判断.txt的差异,下面的代码可以正常导入数据,添加列标题。但是,涨跌列要你自己倒入数据以后再用代码分析填入。
Dim dlg As New FolderBrowserDialog
If dlg.ShowDialog = DialogResult.Ok Then
For Each file As String In FileSys.GetFiles(dlg.SelectedPath)
If file.ToLower.EndsWith(".txt") Then
Dim strs As String = FileSys.ReadAllText(file)
Dim title As String = "时间,开盘价,最高价,最低价,收盘价,成交量,金额" & vbCrLf
If strs.StartsWith(title) = False Then
strs = strs.Replace(" ", ",")
strs = title + strs
FileSys.WriteAllText(file, strs, False, Encoding.Default)
End If
Dim name = FileSys.GetName(file.SubString(0, file.length - 4))
If DataTables.Contains(name) = False Then
Dim ip As New Importer
ip.SourcePath = dlg.SelectedPath
ip.SourceTableName = name
ip.NewTableName = name '导入后的表名
ip.Format = "Delimited" '指定导入格式
ip.Import()
Else
msgbox(name & "表已经存在")
End If
End If
Next
End If