简体   繁体   English

使用ADO.NET创建Excel工作表(OleDb) - >支持哪些数据类型?

[英]Creating an Excel Sheet with ADO.NET (OleDb) --> What DataTypes are Supported?

I try to create an Excel (2003) Sheet with ADO.NET (OleDb). 我尝试使用ADO.NET(OleDb)创建Excel(2003)工作表。

I was able to create the Sheet with an OleDbCommand: 我能够使用OleDbCommand创建Sheet:

var cnnString = "Provider=Microsoft.Jet.OLEDB.4.0;...";
var cnn = new OleDbConnection(cnnString);
var cmd = cnn.CreateCommand();
cnn.Open();
cmd.CommandText = "CREATE TABLE MySheet (ID char(255), Field1 char(255))";
cmd.ExecuteNonQuery();

That works as expected. 这按预期工作。

Here my Question: What DataTypes (like char(255)) are Supported by Excel within the CREATE TABLE command? 这里我的问题:在CREATE TABLE命令中Excel支持哪些DataTypes(如char(255))? I did google but didn't find any documentation or hints. 我做谷歌但没有找到任何文件或提示。

Thanks for your help. 谢谢你的帮助。

Excel recognizes only a limited set of data types . Excel仅识别有限的一组数据类型 For example: 例如:

  • All numeric columns are doubles 所有数字列都是双精度数
  • All string columns (other than memo columns) are 255-character Unicode strings 所有字符串列(备注列除外)都是255个字符的Unicode字符串

Numbers 数字

All versions of Excel: 所有版本的Excel:

  • 8-byte double 8字节双
  • [signed] short [int] – used for Boolean values and also integers [signed] short [int] - 用于布尔值和整数
  • unsigned short [int] unsigned short [int]
  • [signed long] int [签名长] int

Strings 字符串

All versions of Excel: 所有版本的Excel:

  • [signed] char * – null-terminated byte strings of up to 255 characters [signed] char * - 以null结尾的字节字符串,最多255个字符
  • unsigned char * – length-counted byte strings of up to 255 characters unsigned char * - 长度计数的字节字符串,最多255个字符

Excel 2007+ only: 仅限Excel 2007+:

  • unsigned short * – Unicode strings of up to 32,767 characters, which can be null-terminated or length-counted unsigned short * - 最多32,767个字符的Unicode字符串,可以是空终止或长度计数

You will always get better results using the Excel object model directly, and there isn't much more code required. 您将始终直接使用Excel对象模型获得更好的结果,并且不需要更多代码。 See example on SO 参见SO上的示例

or if you wanted to get really keen you could try the Open XML SDK 2.0 for Microsoft Office 或者如果您想真正热衷于此,可以尝试使用适用于Microsoft Office的Open XML SDK 2.0

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

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