简体   繁体   English

Excel 2007 OLEDB连接:文件包含超链接时出错

[英]Excel 2007 OLEDB connection: error when file contains hyperlink

Before everyone here closes this question for being a duplicate, I should say that I have looked at the other ones, and tried the answers with no luck. 在这里每个人都回答重复这个问题之前,我应该说我已经看过其他问题,并且没有运气就尝试了答案。

Here's the connection string I'm using 这是我正在使用的连接字符串

strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FilePathBox.Text + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\"";

I've searched high and low about the 2007 connection string and I've tried every single one I've seen and many combinations there of. 我搜索了2007连接字符串的高低部分,并尝试了所见过的每个连接字符串以及其中的许多组合。 But no matter what I get an exception saying External table is not in the expected format . 但是无论我说什么异常, External table is not in the expected format

I have Excel 2007 installed and I tried installing the correct drivers seperately. 我已经安装了Excel 2007,并尝试单独安装正确的驱动程序。

Edit 编辑

Ok so weird thing: It only happens with the file I'm trying to convert. 好吧,这很奇怪:它仅在我尝试转换的文件中发生。 I made a new xlsx file, and it worked fine. 我做了一个新的xlsx文件,它工作正常。 Just happens to be this particular file. 恰好是这个特定的文件。

EDIT 2 编辑2

The file I was trying to conver had email addresses in it. 我尝试转换的文件中包含电子邮件地址。 When the email address is typed in, excel automatically makes it a hyperlink. 输入电子邮件地址后,Excel会自动将其设置为超链接。 This is the problem. 这就是问题。 If I remove the hyperlink from the text, the conversion works fine. 如果我从文本中删除了超链接,则转换工作正常。 Is there something special i have to do when connecting if the file contains hyperlinks? 如果文件包含超链接,在连接时我需要做些特别的事情吗?

Here is one that works for me for XLSX files: 这是一个适用于我的XLSX文件的文件:

strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dataSource + ";Extended Properties=\\"EXCEL 12.0 XML;HDR=YES;IMEX=1\\";Persist Security Info=True;Jet OLEDB:Database Password=admin"; strConn = @“ Provider = Microsoft.ACE.OLEDB.12.0; Data Source =” + dataSource +“;扩展属性= \\” EXCEL 12.0 XML; HDR = YES; IMEX = 1 \\“;持久安全信息= True; Jet OLEDB :Database Password = admin“;

For xlsm I use: 对于xlsm,我使用:

strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + dataSource + ";Extended Properties=\\"EXCEL 12.0 Macro;HDR=YES;IMEX=1\\";Persist Security Info=True;Jet OLEDB:Database Password=admin"; strConn = @“ Provider = Microsoft.ACE.OLEDB.12.0; Data Source =” + dataSource +“;扩展属性= \\” EXCEL 12.0宏; HDR = YES; IMEX = 1 \\“;持久安全信息= True; Jet OLEDB :Database Password = admin“;

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

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