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 977947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:59:06+00:00 2026-05-16T03:59:06+00:00

I have data that I’m taking from an Excel sheet with the ultimate goal

  • 0

I have data that I’m taking from an Excel sheet with the ultimate goal of displaying in a DataGridView.

Currently I am just going over the UsedRange of excel data and plugging it into a datagridview. This works fine, but can get bogged down when there 100+ rows of data.

I have also toyed with going from excel into a dataset (using the same wasteful method), and as expected it takes about the same time to load the data.

I was wondering if anyone had any information for a better way? Maybe use the XML from the Excel file?

EDIT:

Some Additional Information:

This is a WinForms application and the user will be picking and loading the excel file at run-time.

EDIT

The Return of Some Additional Information:

The Excel file is located on the user’s pc. The general assumption is that they will be loading different files each time they use the application. [not sure if this helps, but might be good to know :)]

  • 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-16T03:59:07+00:00Added an answer on May 16, 2026 at 3:59 am

    I faced this same problem recently…I wasn’t able to really find an out-of-the-box solution that would do this for me, so I ended up writing some code by hand.

    I actually have two different solutions in my code library: one uses OLEDB and the other uses Excel Interop. From your question, I’m guessing you’ve been attempting to use an interop solution, and it’s too slow. If all you want to do is read tables directly from Excel, where there is one table per worksheet, the OLEDB solution is probably cleaner and faster. If you ever get to the point where you need to write to an Excel file, though, you may find that OLEDB is just too limited. That was my experience for one project.

    Anyway, I’ll post a few bits and pieces from my OLEDB solution that will hopefully get you started:

        public void FillDataTables(DataSet dataSet)
        {
            var worksheetNames = GetWorksheetNames();
            foreach (DataTable table in dataSet.Tables)
            {
                if (!worksheetNames.Contains(table.TableName + "$")) continue;
                FillDataTable(table);
            }
        }
    
        public void FillDataTable(DataTable table)
        {
            using (var connection = ConnectionProvider.GetNew())
            {
                var adapter = GetNewDataAdapter(table, connection);
                adapter.Fill(table);
            }
        }
    
        private IEnumerable<string> GetWorksheetNames()
        {
            return GetSchemaTable()
                .AsEnumerable()
                .Select(dr => dr.Field<string>("TABLE_NAME"));
        }
    
        public DataTable GetSchemaTable()
        {
            using (var connection = (OleDbConnection)ConnectionProvider.GetNew())
            {
                connection.Open();
                return connection.GetSchema("Tables");
            }
        }
    

    Here is the code for the ExcelConnectionProvider:

    public class ExcelConnectionProvider : IConnectionProvider
    {
        private readonly string _connectionString;
        private readonly string _workbookPath;
    
        public string ConnectionString
        {
            get { return _connectionString; }
        }
    
        public string WorkbookPath
        {
            get { return _workbookPath; }
        }
    
        public ExcelConnectionProvider(string workbookPath)
        {
            _workbookPath = workbookPath;
            _connectionString = GetConnectionString();
        }
    
        private string GetConnectionString()
        {
            var builder = new OleDbConnectionStringBuilder { Provider = "Microsoft.ACE.OLEDB.12.0", DataSource = _workbookPath };
            builder.Add("Extended Properties", "Excel 12.0 Xml;HDR=Yes");
            return builder.ConnectionString;
        }
    
        public DbConnection GetNew()
        {
            return new OleDbConnection(_connectionString);
        }
    }
    

    If you run into any problems with this compiling, try including the “System.Data.DataSetExtensions” assembly in your project.

    EDIT: : IConnectionProvider is not needed — it’s an interface I added to my library because I have other connection providers besides Excel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data that's currently stored in an Excel workbook. It makes sense
I have data that looks like CUSTOMER, CUSTOMER_ID, PRODUCT ABC INC 1 XYX ABC
I have data that needs to be executed on a certain background thread. I
I have data that looks like this: entities id name 1 Apple 2 Orange
I have SQL data that looks like this: events id name capacity 1 Cooking
I have YAML data that looks sort of like this, but ~150k of it:
I have some data that I want to store somewhere in my Rails app
Let's say I have data structures that're something like this: Public Class AttendenceRecord Public
For whatever reason, I have a lot of clients that have existing data that's
We have some input data that sometimes appears with &nbsp characters on the end.

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.