简体   繁体   English

针对Excel工作簿运行的SQL查询返回截断的文本字段

[英]SQL Query Run Against Excel Workbook Returns Truncated Text Field

I'm running a SQL SELECT query through an ADO connection to an Excel 2007 workbook with the following code (using a custom version of VBScript) 我正在通过使用以下代码的ADO连接到Excel 2007工作簿来运行SQL SELECT查询(使用VBScript的自定义版本)

dim ado, rs
set ado = CreateObject("ADODB.Connection")
ado.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=workbook.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1"";"
ado.open()
set rs = ado.execute("SELECT * FROM [sheet1$]")

which is straighforward. 这很简单。 The problem is that any cell that has text longer than 255 characters is truncated; 问题是,任何文本长度超过255个字符的单元格都会被截断。 is there any way around this? 有没有办法解决? Is there a property in the connection string that will support this or is it an option I need to change in the excel document itself? 连接字符串中是否有支持此的属性,还是我需要在excel文档本身中更改的选项? I have tried MSSQL's CAST() function but this just causes an error when executed. 我已经尝试过MSSQL的CAST()函数,但这在执行时只会导致错误。

Any help would be greatly appreciated. 任何帮助将不胜感激。

I think you're running into a variant of a long-standing limitation in Excel's data access provider. 我认为您在Excel的数据访问提供程序中遇到了一个长期存在的限制。 See http://support.microsoft.com/default.aspx?scid=kb;EN-US;189897 for an example or google for thousands more. 有关示例,请参见http://support.microsoft.com/default.aspx?scid=kb;EN-US;189897;有关其他示例,请参见google。

而不是尝试使用CAST(),您是否尝试过使用CONVERT()函数?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM