Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# Excel and Threading

C# Excel and Threading

Scheduled Pinned Locked Moved C#
csharpcomdesignhelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StyleGuide
    wrote on last edited by
    #1

    Hi There, I have a background worker thread on my Form. In 'DoWork' A call is made from the thread to pump data out to Excel. The visible property of my Excel Application is set to false until 'RunWorkerCompleted' (there may be a lot of data and the users don't want to see it being churned out) when visible is set to true, I also use the .Activate method :

    excelApplication.Visible = true;
    ((Microsoft.Office.Interop.Excel._Workbook)excelWorkbook).Activate();

    Everything works fine except the Excel appears behind my form - not the front.. annoying .. in addition its only happening on my tester's machine (typical!) and not mine. It is the last code that executes.

    excelApplication

    and

    excelWorkbook

    are in a different class which I suspect is the root of the issue, also it needs to be inside the thread so the UI is not affected when the form is moved around and such like. Any ideas? Thanks very much Jon

    M F 2 Replies Last reply
    0
    • S StyleGuide

      Hi There, I have a background worker thread on my Form. In 'DoWork' A call is made from the thread to pump data out to Excel. The visible property of my Excel Application is set to false until 'RunWorkerCompleted' (there may be a lot of data and the users don't want to see it being churned out) when visible is set to true, I also use the .Activate method :

      excelApplication.Visible = true;
      ((Microsoft.Office.Interop.Excel._Workbook)excelWorkbook).Activate();

      Everything works fine except the Excel appears behind my form - not the front.. annoying .. in addition its only happening on my tester's machine (typical!) and not mine. It is the last code that executes.

      excelApplication

      and

      excelWorkbook

      are in a different class which I suspect is the root of the issue, also it needs to be inside the thread so the UI is not affected when the form is moved around and such like. Any ideas? Thanks very much Jon

      M Offline
      M Offline
      MarkB777
      wrote on last edited by
      #2

      Hi there, I don't see why you need the below call, just setting visibility to true works fine for me:

      ((Microsoft.Office.Interop.Excel._Workbook)excelWorkbook).Activate();

      You are right that you should not have the application and workbook objects in different classes. I doubt that is causing the sheet to appear behind your form though. Have you tried a simple send to back call on the form after you make the sheet visible? Cheers,

      Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

      S 1 Reply Last reply
      0
      • M MarkB777

        Hi there, I don't see why you need the below call, just setting visibility to true works fine for me:

        ((Microsoft.Office.Interop.Excel._Workbook)excelWorkbook).Activate();

        You are right that you should not have the application and workbook objects in different classes. I doubt that is causing the sheet to appear behind your form though. Have you tried a simple send to back call on the form after you make the sheet visible? Cheers,

        Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen

        S Offline
        S Offline
        StyleGuide
        wrote on last edited by
        #3

        Thanks Mark, I will try the back call. Sorry, was a rather vague there, my Application and Workbook objects are in the same class (Excel class) which is not in the Form class (obviously). Thanks very much for the help, Jon

        1 Reply Last reply
        0
        • S StyleGuide

          Hi There, I have a background worker thread on my Form. In 'DoWork' A call is made from the thread to pump data out to Excel. The visible property of my Excel Application is set to false until 'RunWorkerCompleted' (there may be a lot of data and the users don't want to see it being churned out) when visible is set to true, I also use the .Activate method :

          excelApplication.Visible = true;
          ((Microsoft.Office.Interop.Excel._Workbook)excelWorkbook).Activate();

          Everything works fine except the Excel appears behind my form - not the front.. annoying .. in addition its only happening on my tester's machine (typical!) and not mine. It is the last code that executes.

          excelApplication

          and

          excelWorkbook

          are in a different class which I suspect is the root of the issue, also it needs to be inside the thread so the UI is not affected when the form is moved around and such like. Any ideas? Thanks very much Jon

          F Offline
          F Offline
          FilipKrnjic
          wrote on last edited by
          #4

          You can try with GemBox spreadsheet component. It's much better way to read and write Excel file then Excel Automation.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups