我正在使用以下代码读取一个 excel 文件:
Function Read_Excel(ByVal sFile As String) As ADODB.Recordset
On Error GoTo fix_err
Dim rs As ADODB.Recordset
rs = New ADODB.Recordset
Dim sconn As String
rs.CursorLocation = ADODB.CursorLocationEnum.adUseServer
rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic
rs.LockType = ADODB.LockTypeEnum.adLockReadOnly
sconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sFile & ";Extended Properties=""Excel 12.0;HDR=YES;IMEX=1"";"
rs.Open("SELECT CStr([RPOCode]), Description FROM [sheet1$]", sconn)
tot += rs.RecordCount
rs.Close()
rs.Open("SELECT Distinct RPOCode, Description FROM [sheet1$] ORDER BY RPOCode", sconn)
Read_Excel = rs
rs = Nothing
Exit Function
fix_err:
Debug.Print(Err.Description + " " + _
Err.Source, vbCritical, "Import")
Err.Clear()
End Function
超过 255 个字符的单元格被截断,我不确定是否有办法轻松阻止它?
更新:截断似乎只有在我选择 Distinct 时才会发生。如果我关闭 Distinct,它会显示完整的单元格。
最佳答案
如果您使用 Jet 驱动程序将备注类型字段(列)更改为文本类型字段,则会截断它们。可以使用子查询来获取不同的记录并避免 Distinct。
此引用适用于 Access,但它仍然是 Jet,因此几乎所有内容都适用:Truncation of Memo fields
关于vb.net - excel oledb 字段在 255 处截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4971519/