Read opened excel problem
The other day I wrote a little program to read Excel files through the Jet engine.
I must admit it is fairly simply to accomplish this but I have already stumbled upon an issue.
The Excel files are being used by other people, the program can read these files that are open so that's correct. The issue is that if you have an Excel file open on your computer and you use the software, it will automatically read the locked files and will try to open these Excel files when the user who is using this closes them.
So the locked files are put in a waiting list to be opened and the user is notified that the file is closed and asks if you want to open it.
When the user that is operates the software closes his Excel before executing, the program works fine without opening the locked files...
Code:
string connectionString = "Provider=Microsoft.Jet.OleDb.4.0; data source=" + path + "; Extended Properties=Excel 8.0;";
string selectString = "SELECT * FROM [Debiteuren$]";
OleDbConnection con = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(selectString, con);
try
{
con.Open();
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = cmd;
DataSet ds = new DataSet();
objAdapter1.Fill(ds);
DataTable dt = ds.Tables[0];
dt = prepareDatatable(dt);
tableToItems(dt, path);
}
catch (Exception ex)
{
}
finally
{
con.Dispose();
}
Re: Read opened excel problem
Re: Read opened excel problem
Does anybody know a workaround or something?
It is not the intention that the user sees these documents.
Re: Read opened excel problem
Quote:
Originally Posted by
tiebird
Does anybody know a workaround or something?
It is not the intention that the user sees these documents.
I'm afraid you aren't explaining your problem well enough.
Can you clearly explain what problem you are having?