使用 vb.net 将 excel 文件值写入记事本。在我的代码中,我使用 oledb 提供程序打开 excel 文件。但是在打开 excel 文件时出现错误。该文件名为“phone data.xlsx”。存储在我的系统桌面中。使用文件上传控制来获取该文件。
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.