我有一个CSV文件,格式如下:
Dates,Open,High,Low,Close,Volume
#2010-01-03 15:01:00#,1.1648,1.1648,1.1622,1.1646,8
#2010-01-03 15:02:00#,1.1648,1.1648,1.1648,1.1648,1
#2010-01-03 15:03:00#,1.1648,1.1648,1.1648,1.1648,2
编辑:明确地说,这是YYYY-MM-DD
。
当我使用以下脚本(它在D:\Data\Processed
中)将其导入Access 2010时:
Dim strFolderPath As String
strFolderPath = "D:\Data\Processed\"
Dim StrFile As String
StrFile = Dir(strFolderPath & "*.txt")
Do While Len(StrFile) > 0
'MsgBox (objF1.Name)
DoCmd.TransferText acImportDelim, , StrFile & "draft", strFolderPath & StrFile, True
'DoCmd.TransferText acImportDelim, strFolderPath & objF1.Name, False
'DoCmd.TransferText acImportDelim, "TextImportSpecs", "tblImportedFiles", strFolderPath & objF1.Name, False
'DoCmd.TransferText _
'TransferType:=intImportType, _
'SpecificationName:=strSpecification, _
'TableName:=strTable, _
'FileName:=strPath & strFile, _
'HasFieldNames:=blnHasFieldNames
'strFile = Dir
Name strFolderPath & StrFile As "D:\Data\Done\" & StrFile 'Move the files to the archive folder
StrFile = Dir
Loop
它将第一个字段导入为字符串,而不是日期。我希望更改文本文件的格式(首选)或更改脚本以适应作为日期/时间对象导入。
发布于 2013-05-11 15:31:57
试着去掉井号字符('#‘--你是这么叫它们的吗?)从你的数据文件。
我想您知道,当通过DoCmd.TransferText
方法导入CSV数据来创建表时,Access (Jet)会根据它在扫描导入数据的第一行时找到的数据来分配列数据类型。如果列包含数字数据,Jet会为该列分配Number
数据类型、日期格式化数据get DateTime
列等。
在您的示例中,Jet无法确定'Dates‘列的数据类型,因为有'#’字符,因此为该列分配了(相当通用的) Text
数据类型。
https://stackoverflow.com/questions/16494179
复制相似问题