当前位置: 动力学知识库 > 问答 > 编程问答 >

How to keep csv file dateformat in excel

问题描述:

dateformat of csv file is "yyyy-mm-dd" when open in excel it shows dd/mm/yyyy

I want to show the original format in excel

thanks

网友答案:

Starting with data like:

Try running a macro like:

Sub GetDatesFromCSV()

    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Users\JamesRavenswood\Desktop\temp.csv", Destination:=Range("$A$1"))
        .Name = "temp"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(5)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With

    Range("A:A").NumberFormat = "yyy-mm-dd"
End Sub
分享给朋友:
您可能感兴趣的文章:
随机阅读: