I'm reading in an excel file with the following code:
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
Cells longer than 255 chars are getting truncated, and I'm not sure if there is a way to stop it easily?
Update: The truncation only seems to happen if I select Distinct. If I leave the Distinct off it shows the full cell.
My method's a bit different - opening excel files via OleDbAdapter, but I've solved your issue before using it. It's C# but should be easily transposed to vb.net. Try this OleDBAdapter Excel QA I posted via stack overflow.
I have a worksheet cell (Rows[0][4]) w/ 445 characters and it worked fine... Add this to the end of the code for the output
Memo-type fields (columns) will be truncated if you do anything that changes them to text-type fields with the Jet driver. It may be possible to use a sub-query to get distinct records and avoid Distinct.
This reference is for Access, but it is still Jet, so nearly everything applies: Truncation of Memo fields