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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:03:42+00:00 2026-05-28T03:03:42+00:00

I am writing a program that will allow me to open excel spreadsheets and

  • 0

I am writing a program that will allow me to open excel spreadsheets and get some specific information off of them. Each sheet contains the same information that I need, but the information is not always in the same location.

I am trying to find a way to search for specific text in an Excel sheet and have the address of the cell that text is in.

For example:
If I was looking for the text “apples”, the function will find the cell that contains apples and return its address (i.e., A5).

For accessing the Excel spreadsheet I am using Excel = Microsoft.Office.Interop.Excel.
I have been looking all weekend for an efficient way to to do this and have been horribly unsuccessful so far. Any help I can get would be greatly appreciated.

Edit:
This is part of a much larger project, but for this particular function, I have the ability to open and close the Excel file. I have yet to start writing the search function yet, because to be perfectly honest, I am not exactly sure on even how to go about doing this. But here is what I have at this point.

public string searchExcel(string findThis)
{
    Excel.Application xlApp;
    Excel.Workbook xlWorkBook;
    Excel.WorkSheet xlWorkSheet;
    object misvalue;

    //This part will open the Excel document.
    misValue = System.Reflection.Missing.Value;
    xlApp = new Excel.ApplicationClass();
    xlWorkBook = xlApp.Workbooks.Open("C:\\temp2\\excelDocument.xlsm", 
    0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, 
    "\t", false, false, 0, true, 1, 0);


    //Search and get address of cell


    //This part will close the Excel document
    xlWorkBook.Close(true, misValue, misvalue);
    xlApp.Quit();

    releaseObject(xlWorkSheet);
    releaseObject(xlWorkBook);
    releaseObject(xlApp);

    xlWorkSheet = null;
    xlWorkBook = null;
    xlApp = null;
}

private void releaseObject(object obj)
{
    try
    {
        System.Runtime.Interopservices.Marshal.ReleaseComObject(obj);
        obj = null;
    }
    catch(Exception e)
    {
        obj = null;
        MessageBox.Show("Unable to release the object " + e.ToString());
    }
    finally
    {
        GC.Collect();
    }
}
  • 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-28T03:03:43+00:00Added an answer on May 28, 2026 at 3:03 am

    I think something like this should do what you want:

            var app = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
            var wb = app.ActiveWorkbook;
            var ws = wb.Worksheets[1] as Excel.Worksheet;
            var cells = ws.Cells;
            var match = cells.Find("apples", LookAt:=Excel.XlLookAt.xlPart) as Excel.Range;
            var matchAdd = match != null ? match.Address : null;
    

    This will search in the first Worksheet of the current active workbook of a current Excel session.

    Adjusting to fit your code:

            xlWorksheet = xlWorkBook.Worksheets[1] as Excel.Worksheet;
            Excel.Range cells = ws.Cells;
            Excel.Range match = cells.Find("apples", LookAt:=Excel.XlLookAt.xlPart) as Excel.Range;
    
            string matchAdd = match != null ? match.Address : null;
    
            if (match != null) releaseObject(match);
            releaseObject(cells);
    

    One thing, is this assumes .Net 4.0 as I use missing arguments for the find call. If you are using a previous version you will need to pass in misValue for any parameter not used.

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

Sidebar

Related Questions

I am contemplating writing a program that will move some newly created dirs to
I'm writing a server program in Java that will allow users to submit jobs
Hello All I am writing some software that will allow users to create their
I want to write a program that will allow writing plugins for it. The
I am writing a program that will draw a solid along the curve of
I'm a writing a program that will determine the number of lines, characters, and
I'm writing a simple program that will run entirely client-side. (Desktop programming? do people
I have Virtual PC 2007. I am writing a C# program that will run
I am writing a program in Python that will act as a server and
I'm writing a program in C# that will need to store a few Data

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.