gpt4 book ai didi

c# - 为什么 OleDB 忽略 Excel 单元格?

转载 作者:太空宇宙 更新时间:2023-11-03 14:12:27 27 4
gpt4 key购买 nike

这是设置:

我有一个包含非常简单页面的 Excel 电子表格。看起来像这样: Image redacted, of course

我使用以下连接字符串访问此文件:

string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=NO\";", fn)

我访问文件的函数如下所示:

try
{
string select = string.Format("SELECT * FROM [{0}$]", tab.PageName);
OleDbDataAdapter adapter = new OleDbDataAdapter(select, con);
DataSet ds = new DataSet();

adapter.Fill(ds, tab.PageName);


// DEBUG: Let's just see what it is getting...
for (int x = 0; x < 13; x++)
{
for (int y = 0; y < 3; y++)
{
Console.Write(ds.Tables[0].Rows[x][y].ToString() + "\t");
}
Console.WriteLine("");
}
}
catch
{ ... }

问题

为什么代码不能读取某些单元格?请注意,C5 处有文本“Profit”。我可以将 B5 读作“收入”。我可以将 C6 作为整数值读取。但是利润似乎消失了。

对于头信息来说这不是什么大问题,但是整 block 真实数据都拒绝读取。相反,它返回 DBNull,即使单元格包含真实、有效、可用的数据。可以读取的单元格和返回 DBNull 的单元格之间的单元格格式完全相同。

我真的很难过!!!

有什么想法吗?

最佳答案

 new OleDbConnection("...TypeGuessRows=0;ImportMixedTypes=Text");

我有预感你可能正在经历 a problem that I had previously .

尝试将这些参数添加到您的连接字符串中。

关于c# - 为什么 OleDB 忽略 Excel 单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7423742/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com