15

我正在使用 OleDbConnection 类从 Excel 2000/2003 工作簿中检索数据:

string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                          "Data Source=" + filename + ";" +
                          "Extended Properties=\"Excel 8.0;IMEX=1\";";

OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();

// code to get table name from schema omitted

var dataAdapter = new OleDbDataAdapter(string.Format("SELECT * FROM [{0}]", name),connection);
var myDataSet = new DataSet();
dataAdapter.Fill(myDataSet, "ExcelInfo");

现在事实证明,工作表中长度大于 255 个字符的单元格将被截断。这是 Microsoft.Jet.OLEDB 提供程序的限制,还是我可以做些什么?

任何人?

4

2 回答 2

20
于 2009-05-22T15:47:53.050 回答
2

试试我通过堆栈溢出发布的这个OleDBAdapter Excel QA 。

我填充了一个包含 445 个字符的工作表单元格 (Rows[0][4]),它运行良好...将其添加到输出代码的末尾

// DataSet:          
Object row0Col3 = ds.Tables["xlsImport"].Rows[0][2];
Object row0Col4 = ds.Tables["xlsImport"].Rows[0][4];

string rowZeroColumn3 = row0Col3.ToString();
string rowZeroColumn4 = row0Col4.ToString();

Console.WriteLine("Row 0, Col 4 string length: {0} " + Environment.NewLine + "Excel content: {1}", rowZeroColumn4.Length, rowZeroColumn4);           
于 2011-05-03T20:01:27.517 回答