有关 excel 文件的 OleDB 连接字符串的帮助

发布于 2024-10-09 05:19:23 字数 599 浏览 4 评论 0原文

我遇到的问题是数据适配器仅查看每列中的第一行来确定数据类型。就我而言,第一列“SKU”是前 500 行的数字,然后我碰巧拥有混合数字和字母的 SKU。因此,最终发生的情况是 SKU 列中的行留空,但我仍然获得每个列行的其他信息。

我相信是连接字符串控制了它,并且根据我当前的设置,它应该可以工作,但事实并非如此。

连接字符串:

conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nick\Desktop\Pricing2.xlsx" + @";Extended Properties=""Excel 12.0 Xml;HDR=Yes;IMEX=1;ImportMixedTypes=Text;TypeGuessRows=0""";


ImportMixedTypes=Text;TypeGuessRows=0

应该是重要的关键字,查看 0 行并仅使用文本作为所有内容的值类型。

我对此施加的“创可贴”是使电子表格中的第一行由字母和数字混合而成,并在我的查询中专门将该行排除在外。

The problem i'm having is that the data adapter is looking at only the first row in each column to determine the data type. In my case the first column "SKU" is numbers for the first 500 rows then I happen to have SKU's which are mixed numbers and letters. So what ends up happening is rows in the SKU column are left blank, but I still get the other information for each column row.

I believe it is the connection string that controls that and with my current settings it should work, however it is not.

Connection String:

conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nick\Desktop\Pricing2.xlsx" + @";Extended Properties=""Excel 12.0 Xml;HDR=Yes;IMEX=1;ImportMixedTypes=Text;TypeGuessRows=0""";

ImportMixedTypes=Text;TypeGuessRows=0

Should be the important keywords, look at 0 rows and just use text as the value types for everything.

The "bandaid" I have put on this is to make the first row in the spreadsheet a mixture of letters and numbers and specifically leave that row out in my query.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉薄对峙 2024-10-16 05:19:23

遗憾的是,您无法从连接字符串中设置 ImportMixedTypesTypeGuessRows,因为这些设置是在注册表中定义的。对于 ACE OleDb 驱动程序,它们存储

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Access Connectivity Engine\Engines\Excel

在注册表中。因此,您可以将连接字符串简化为:

conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nick\Desktop\Pricing2.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=Yes;IMEX=1;""";

TypeGuessRows 设置为 0 并将 ImportMixedTypes 设置为 Text注册表,您应该得到您期望的行为。但是,如果您发现导入性能不太理想,则可以考虑使用适当大的数字(例如 1000)而不是零。

Unfortunately, you can't set ImportMixedTypes or TypeGuessRows from the connection string since those settings are defined in the registry. For the ACE OleDb driver, they're stored at

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\14.0\Access Connectivity Engine\Engines\Excel

in the registry. So, you can simplify your connection string to:

conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nick\Desktop\Pricing2.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=Yes;IMEX=1;""";

Once you set TypeGuessRows to 0 and ImportMixedTypes to Text in the registry, you should get the behavior you are expecting. You might, however, consider using a suitably large number like 1000 instead of zero if you find import performance to be less than ideal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文