2013-05-11 78 views
0

我有以下格式的CSV文件: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

當我將其導入到Access 2010中使用以下腳本(它在D:\Data\Processed):

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 

它進口的第一個字段作爲一個字符串,而不是一個日期。我會很感激改變文本文件格式(首選)或改變腳本以適應作爲日期/時間對象導入。

回答

1

嘗試從您的數據文件中刪除英鎊字符('#' - 是你稱之爲?)。

我想你知道當通過DoCmd.TransferText方法導入CSV數據創建表時,Access(Jet)會根據掃描導入數據的第一行時發現的數據來分配列數據類型。如果列數字數據,李連杰分配該列中的數據Number類型,日期格式的數據得到DateTime柱等

你的情況,噴氣無法確定,因爲你的「日期」一欄的數據類型「 #'字符,因此將該列指定爲(相當通用)Text數據類型。

+0

我會嘗試並儘快報告。 – 2013-05-11 16:05:29

+0

工作就像一個魅力。謝謝! – 2013-05-11 16:27:52

+0

@HameerAbbasi很高興能幫到你! – 2013-05-12 05:19:20