VARCHAR size limit in Excel spreadsheets

試著忘記壹切 提交于 2019-12-02 01:02:02

问题


I'm trying to read some data from an SQL Server 2008 database into an Excel 2007 spreadsheet with C#, using this connection string:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=foo.xlsx;Extended Properties='Excel 12.0 XML;HDR=YES'

One of the columns in the database is a VARCHAR(1000). When I try recreating the schema in the spreadsheet, it seems like Excel's VARCHAR only supports up to 255. This page suggests that the "Total number of characters that a cell can contain" is around 32K, so in principle, it should be possible to get a longer string in.

Is there a simple way to work around the 255 char limit?


回答1:


Although XLOPER12 will now support a string up to 32,767 Unicode characters long, xlfEvaluate (and other) excel C-Api function continues to be limited to 255 characters long in Excel 2010. It will return xltypeErr if it is passed an XLOPER12 with a string longer than 255.

All strings the user sees in Excel have for many versions now been stored internally as Unicode strings. Unicode worksheet strings can be up to 32,767 (215 - 1) characters in length and can contain any valid Unicode character.

When the C API was first introduced, worksheet strings were byte strings limited in length to 255 characters, and the C API reflected these limitations. With Excel 2007, the C API is updated to handle Excel long Unicode strings. This means that DLL functions registered in the right way can accept Unicode arguments and return Unicode strings.

Note: Byte strings are still fully supported in the C API for backward compatibility, however they still have the same 255-character limit. No easy solution other than to truncate the string, or divide the string into multiple cells.



来源:https://stackoverflow.com/questions/9711489/varchar-size-limit-in-excel-spreadsheets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!