首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CSV导入错误-涉及的日期/时间

CSV导入错误-涉及的日期/时间
EN

Stack Overflow用户
提问于 2013-05-11 13:43:04
回答 1查看 641关注 0票数 0

我有一个CSV文件,格式如下:

代码语言:javascript
运行
复制
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时:

代码语言:javascript
运行
复制
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

它将第一个字段导入为字符串,而不是日期。我希望更改文本文件的格式(首选)或更改脚本以适应作为日期/时间对象导入。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-11 15:31:57

试着去掉井号字符('#‘--你是这么叫它们的吗?)从你的数据文件。

我想您知道,当通过DoCmd.TransferText方法导入CSV数据来创建表时,Access (Jet)会根据它在扫描导入数据的第一行时找到的数据来分配列数据类型。如果列包含数字数据,Jet会为该列分配Number数据类型、日期格式化数据get DateTime列等。

在您的示例中,Jet无法确定'Dates‘列的数据类型,因为有'#’字符,因此为该列分配了(相当通用的) Text数据类型。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16494179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档