ADO is truncating Excel data

前端 未结 2 857
名媛妹妹
名媛妹妹 2021-01-13 12:54

I have a function that gets an ADODB recordset from the contents of a worksheet using ADO, as follows:

Function WorksheetRecordset(workbookPath As String, sh         


        
相关标签:
2条回答
  • 2021-01-13 13:29

    try the below for your objRecordset features and query (tested in MS Query with Excel):

    With objrecordset
        .CursorLocation = adUseClient
        .LockType = adLockOptimistic
        .CursorType = adOpenStatic
        .ActiveConnection = objconnection
        .Open "Select format(`" & sheetName & "$`.value,'0.00') as [value], something FROM [" & sheetName & "$]"
    End With
    

    so, here the JET SQL format Function is forcing ADO's SQL Parser to output a string formatted as 0.00

    ALso, I have set the CursorTLocation property to adUseClient so you won't need to use MoveLast and MoveFirst

    let us know how you get on

    Philip

    0 讨论(0)
  • 2021-01-13 13:30

    Unfortuately I had the same problem once before and the reason is that the ACE driver only looks at the first value in a column to decide the data type for that entire column. So, you can try to sort the data with the numeric values on top.

    The "Gold Standard" way to create joined tables in Excel is with vLookup. I would suggest doing this even though it may seem a bit "amateur."

    Also, it appears that setting IMEX to 1 basically forces ACE to return the text representations so that alpha-numeric values in a numeric column are not returned as null.

    0 讨论(0)
提交回复
热议问题