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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:59:22+00:00 2026-05-28T19:59:22+00:00

I started writing a small wrapper class to take care of my excel operations:

  • 0

I started writing a small wrapper class to take care of my excel operations:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection; 

namespace CSVReader
{
    class ExcelManager
    {
        // Holds instance of application.
        public Excel.Application application;

        /**
         * Class Constructor.
         */
        public ExcelManager()
        {
            // Create a new application instance.
            application = new Excel.Application();
        }

        /**
         * Helper to open workbooks.
         */
        public void Open(string filename) {
           application.Workbooks.Open(filename, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                Type.Missing, Type.Missing);
        }

        /**
         */
        public Excel.Range Find(string search)
        {
            Excel.Workbooks books = application.Workbooks;

            Excel.Range currentFind = null;
            Excel.Range firstFind = null;

            // Search all workbooks.
            foreach(Excel.Workbook book in books)
            {
                // Get first sheet.
                Excel.Worksheet sheet = book.Worksheets.get_Item(1);

                // Get all data for sheet.
                Excel.Range firstCell = sheet.Range["A1", Type.Missing];
                Excel.Range lastCell  = sheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
                Excel.Range sheetData = sheet.Range[firstCell, lastCell];

                currentFind = sheetData.Find(search, Type.Missing, 
                    Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart,
                    Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false,
                    Type.Missing, Type.Missing);

                while (currentFind != null)
                {
                    // Keep track of the first range you find. 
                    if (firstFind == null)
                    {
                        firstFind = currentFind;
                    }

                    // If you didn't move to a new range, you are done.
                    else if (currentFind.get_Address(Type.Missing, Type.Missing, Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing)
                          == firstFind.get_Address(Type.Missing, Type.Missing, Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing))
                    {
                        break;
                    }

                    currentFind = sheetData.FindNext(currentFind);
                }
            }

            return currentFind;
        }
    }
}

I instantiate the class and tell it to load two workbooks and search for a string:

ExcelManager manager = new ExcelManager(); 

manager.Open(@"c:\test\test1.xls");
manager.Open(@"c:\test\test2.XLS");

Excel.Range result = manager.Find('test cell');
if (result != null)
{
    // Do something funky.
}
else
{
    // Use a log file instead.
    Console.WriteLine("item was not found found in the current sheet.");
}

The problem is when i run this code it is incredibly slow, even with small sized workbooks. My C# knowledge is minimal so I’ve been following tutorials the whole day. Is this a good way to go about searching multiple sheets? would using OLE be any faster? The purpose of this app is simply to run a check to summarize values that don’t appear in any of the sheets in my open workbooks.

  • 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-28T19:59:23+00:00Added an answer on May 28, 2026 at 7:59 pm

    My first response would be that interop uses your Excel installation to gather the information. Any initialization logic from the Excel installation will be run and will make for a very slow loading time of the code.

    What you can do to test if this is the case:
    Benchmark which of the function calls make the searching slow. The find function or the loading of your ExcelManager class / the open function.

    If it turns out the speed loss is not caused by the find function you might consider a library that parses the file itself instead of using interop.

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

Sidebar

Related Questions

I have started learning Python by writing a small application using Python 3.1 and
I just started writing a small application in C++ using Visual Studio C++ 2008
In order to get started with bindings, I'm writing a small application that converts
Right now, I am trying to learn Scala . I've started small, writing some
I downloaded Flash Builder from here : Download I recently started writing some small
I'm fairly new to C and have started out writing a small library with
In my free time I started writing a small multiplayer game with a database
I started creating a small game engine for an independent project. When writing the
I started writing functional tests for my rails app today. I use the RESTful
I have started writing a Macro in Visual Studio 2005 like this: Public Sub

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.