excel oledb字段截断为255

我正在用下面的代码读取一个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个字符的单元格被截断,我不确定是否有办法轻松地停止它?

更新:如果我selectDistinct截断似乎只会发生。 如果我离开不同,它显示完整的单元格。

备注types字段(列)将被截断如果您执行任何更改为Jet驱动程序的文本types字段的任何内容。 有可能使用子查询来获得不同的logging并避免Distinct。

这个引用是用于Access的,但它仍然是Jet,所以几乎所有的东西都适用: Memo字段的截断

我的方法有点不同 – 通过OleDbAdapter打开excel文件,但是在使用之前我已经解决了你的问题。 这是C#,但应该很容易调换到vb.net。 试试这个通过堆栈溢出发布的OleDBAdapter Excel QA 。

我有一个工作表单元格(行[0] [4])瓦特/ 445个字符,它工作得很好…添加到输出的代码的末尾

 // DataSet cell debug/output: Object row0Col3 = ds.Tables["xlsImport"].Rows[0][2]; Object row0Col4 = ds.Tables["xlsImport"].Rows[0][4]; string rowZeroColumn3 = row0Col3.ToString(); string rowZeroColumn4 = row0Col4.ToString(); Console.WriteLine("Row 0, Col 4 string length: {0} " + Environment.NewLine + "Excel content: {1}", rowZeroColumn4.Length, rowZeroColumn4);