gpt4 book ai didi

c# - 是否需要一直打开一个excel文件,同时导入数据到数据表,C#

转载 作者:行者123 更新时间:2023-12-04 00:26:20 24 4
gpt4 key购买 nike

我的连接字符串是:

String excelConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("abc.xls") + ";Extended Properties='Excel 8.0; HDR=YES;IMEX=1'";

OleDbConnection conn = new OleDbConnection(excelConn);
Conn.Open();

如果我的 Excel 文件 (abc.xls) 在我的客户端 PC 中关闭,它会给出一个错误,例如“无法解密文件。”。但是当我的 excel 文件打开时就可以了。

最佳答案

您不能使用 OleDbConnection 连接到受密码保护的 excel 文件,它不会按设计工作。

在这里查看:Open a password-protected Excel workbook

If you try to open a password-protected Excel workbook from Access, you get an error message “Could not decrypt file”. Adding a Password= value to your connection string won’t work either. You could open it as an Excel application, but then you’d have to learn about the Excel object model and all you want to do is read it row-by-row as you would any unprotected Excel file.

To get around this problem, first open the Excel workbook using GetObject() and then open it using the connection / recordset approach that you want to use. The GetObject() open prompts your user for the password, and then you are free to open the file using your preferred approach.

关于c# - 是否需要一直打开一个excel文件,同时导入数据到数据表,C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7660306/

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