Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6982617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:18:43+00:00 2026-05-27T18:18:43+00:00

I have a complex object(tree structure) which I am flattening it out into a

  • 0

I have a complex object(tree structure) which I am flattening it out into a datatable to display it on an excel sheet. Datatable is huge and has around 20000 rows and 10000 columns.

Writing the data onto an excel cell one at a time took forever. So, I am converting the complex object into a datatable and then writing it to the excel sheet using the code below.

Is it possible to write 20K rows x 10K columns data to an excel sheet fairly quickly in less than a minute or < 5 minutes? What is the best technique to complete this task fast.

Environment: Visual studio 2010, VSTO excel workbook project, .net framework 4.0, excel 2010/2007

EDIT:

Original source of data is a rest service response in json format. I am then deserializing json response into c# objects and finally flattening it into a datatable.

Using this Code to write datatable to an excel sheet:

Excel.Range oRange;
                var oSheet = Globals.Sheet3;
                int rowCount = 1;
                foreach (DataRow dr in resultsDataTable.Rows)
                {
                    rowCount += 1;
                    for (int i = 1; i < resultsDataTable.Columns.Count + 1; i++)
                    {
                        // Add the header the first time through 
                        if (rowCount == 2)
                        {
                            oSheet.Cells[1, i] = resultsDataTable.Columns[i - 1].ColumnName;
                        }
                        oSheet.Cells[rowCount, i] = dr[i - 1].ToString();
                    }
                }

                // Resize the columns 
                oRange = oSheet.get_Range(oSheet.Cells[1, 1],
                                oSheet.Cells[rowCount, resultsDataTable.Columns.Count]);
                oRange.EntireColumn.AutoFit();

Final Solution:
Used a 2D Object array instead of datatable and wrote it to the range.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:18:43+00:00Added an answer on May 27, 2026 at 6:18 pm

    In addition to freezing Excel’s animation, you can, given the data source this is coming from, save yourself the looping through the Excel.Range object, which is bound to be a bottleneck, by instead of writing to a Datatable, write to a string[,], which Excel can use to write to a Range at once. Looping through a string[,] is much faster than looping through Excel cells.

    string[,] importString = new string[yourJsonSource.Rows.Count, yourJsonSource.Columns.Count];
    //populate the string[,] however you can
    for (int r = 0; r < yourJsonSource.Rows.Count; r++)
    {
        for (int c = 0; c < yourJsonSource.Columns.Count; c++)
        {
            importString[r, c] = yourJsonSource[r][c].ToString();
        }
    }
    
    var oSheet = Globals.Sheet3;
    Excel.Range oRange = oSheet.get_Range(oSheet.Cells[1, 1],
                oSheet.Cells[yourJsonSource.Rows.Count, yourJsonSource.Columns.Count]);
    oRange.Value = importString;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex object graph which is just a set of stubs ie
I have a RuleTree data structure which represents a tree of rules that are
I have a node tree built out of Node objects. They are more complex
If i have a complex object, what is the best practice pattern to write
I have a pretty complex object graph G with an object o1 in G
What is the format for databinding to a complex object? I have a linq
I have a List of a complex type - an object with a few
I am using WCF and REST, and I have complex types, which are working
I have a fairly complex nested object, for example: A = {b : {c
I have a question for which I suspect the answer is a bit complex.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.