Read opened excel problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Read opened excel problem

  1. #1
    Join Date
    Aug 2011
    Posts
    2

    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();
                }

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,239

    Re: Read opened excel problem

    Do you have a question?

  3. #3
    Join Date
    Aug 2011
    Posts
    2

    Re: Read opened excel problem

    Does anybody know a workaround or something?

    It is not the intention that the user sees these documents.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,239

    Re: Read opened excel problem

    Quote Originally Posted by tiebird View Post
    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?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center