locked
Using threading in C# to create an excel report RRS feed

  • Question

  • Hi,

    I hope this is the correct forum.

    I have a C# app that creats an excel doc using Interop.Excel. There 10 worksheetse excel doc and currently the app populates each tab seperatly. It does a sql call and reads through the returned data set and creates the report. The report tales about 5 - 10 minutes to create depend on amount of data to report.

    I wanted to know if it's possible to have one single instance of excel running and somehow use threading to have all the worksheets populated at the same time? If not does anyone know a better way to populate a worksheet from a sql data set faster other than read though the data set and populate one row at a time.

    Thanks in advance

    Dan1104


    Dan1104

    Thursday, March 22, 2012 5:52 PM

Answers

  • Using threading will not neccesarily speed up the code.  Threading offers you the advantage of executing time consuming tasks so that your UI remains responsive and not appear to freeze up.  If your desired result is a single report, then threading may not gain you much improvement in performance.  You could only try it and see.  Since we do not know any details of your scenario, it is near impossible to present any code that is specific to your scenario.

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Saturday, March 24, 2012 8:48 PM
    Moderator

All replies

  • Can you give a little clarity?  You want to write to several Excel worksheets using C# or using SQL Server?

    Take a look at this:

    http://csharp.net-informations.com/excel/csharp-excel-tutorial.htm

    Does that help?  Can you find a solution to your problem there?

    What about this?

    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926

    Also, you can consider this:

    http://www.ozgrid.com/forum/showthread.php?t=57192

    Also, you can fire off a stored procedure in SQL Server, controlled with VBA, to get the data you want:

    http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/f599f280-b786-43f4-9357-77f19a107c3f/

    This DOES write one row at a time, so it will be slower . . .

    http://blog.ninethsense.com/vba-connect-sql-server-from-excel/

    Saturday, March 24, 2012 3:48 AM
  • Using threading will not neccesarily speed up the code.  Threading offers you the advantage of executing time consuming tasks so that your UI remains responsive and not appear to freeze up.  If your desired result is a single report, then threading may not gain you much improvement in performance.  You could only try it and see.  Since we do not know any details of your scenario, it is near impossible to present any code that is specific to your scenario.

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Saturday, March 24, 2012 8:48 PM
    Moderator