用OLEDB读取EXCEL时,单元格内容长度超过255被截断

时间:2023-03-10 05:24:25
用OLEDB读取EXCEL时,单元格内容长度超过255被截断

https://support.microsoft.com/zh-cn/help/189897/data-truncated-to-255-characters-with-excel-odbc-driver

Microsoft.ACE.OLEDB.12.0 驱动读取excel,会读取前8行来判定每列的数据类型,假如没有超过255个字符,那么会被设置为nvarchar(255),从第9行开始,超过255字符会被自动截断!

推荐使用第三方库:https://github.com/ExcelDataReader/ExcelDataReader

----------------------------------
附连接字符串
Microsoft ACE OLEDB 12.0
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;
Extended Properties="Excel 12.0 Xml;HDR=YES";

驱动下载Microsoft Access Database Engine 2016 Redistributable

https://www.microsoft.com/en-us/download/details.aspx?id=54920