使用vb.net将excel文件值写入记事本。在我的代码中使用oledb提供程序打开excel文件。但是在打开excel文件时出错。该文件名为“phone data.xlsx”。存储在我的系统desktop.using文件上传控件,以获取该文件。
my code
-------
Dim pathToCheck As String = filename
If System.IO.File.Exists(pathToCheck) = "True" Then
IO.File.Delete(filename)
End If
Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("D:\modellog.txt", True, System.Text.Encoding.UTF8)
If FileUpload2.HasFile Then
TextBox1.Text = FileUpload2.FileName
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim Ds As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Try
MyConnection = New System.Data.OleDb.OleDbConnection(("provider=Microsoft.ACE.OLEDB.12.0; " + ("data source=" _
+ (TextBox1.Text + ("; " + "Extended Properties=Excel 12.0;")))))
MyCommand = New System.Data.OleDb.OleDbDataAdapter _
("select * from [Sheet1$]", MyConnection)
Ds = New System.Data.DataSet
MyCommand.Fill(Ds)
error
-----
The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data.
答案 0 :(得分:1)
看起来像权限问题。您是否尝试过将文件复制到其他位置,例如C:\ temp?你有没有试过至少暂时授予文件中每个人的完全控制权?如果它在那之后工作,你知道这是一个权限问题,然后你只需要弄清楚适当的权限级别(不想让它完全控制每个人)。