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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:15:41+00:00 2026-06-17T11:15:41+00:00

I need someone to create a method that will get me all the cell

  • 0

I need someone to create a method that will get me all the cell values in an excel spreadsheet into a 2D array.

I’m making it using ribbons in C# to work with Excel but i just can’t get it to work.

  private string[,] GetSpreadsheetData () 
  {
        try
        {
            Excel.Application exApp =
            Globals.TSExcelAddIn.Application as Excel.Application;
            Excel.Worksheet ExWorksheet = exApp.ActiveSheet as Excel.Worksheet;
            Excel.Range xlRange = ExWorksheet.get_Range("A1","F188000");

            object[,] values = (object[,])xlRange.Value2;
            string[,] tsReqs = new string[xlRange.Rows.Count, 7];
            char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();

            for (int i = 0; i < tsReqs.GetLength(0); i++)
            {
                for (int z = 0; z < tsReqs.GetLength(1); z++)
                {
                    if(values[i+1,z+1] != null)
                        tsReqs[i, z] = values[i + 1, z + 1].ToString();
                }
            }
            return tsReqs;
        }

        catch
        {
            MessageBox.Show
                ("Excel has encountered an error. \nSaving work and exitting");
            return null;
        }
    }

Also if anyone has a more efficient way of doing this I would greatly appreciate it.

            Excel.Range xlRange = ExWorksheet.get_Range("A1","F188000");

Reads all the way till F188000 cell from A1, I just want it to keep reading until it reaches a row with absolutely no data.

   -        Caught: "Index was outside the bounds of the array." (System.IndexOutOfRangeException)  Exception Message = "Index was outside the bounds of the array.", Exception Type = "System.IndexOutOfRangeException"    
  • 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-06-17T11:15:43+00:00Added an answer on June 17, 2026 at 11:15 am

    You could consider using ExWorksheet.UsedRange instead of ExWorksheet.get_Range("A1","F188000")

    EDIT: Also, I think if you use the .Text field of a Range, the value is automatically casted to a string, so no need to use .Value2 here

    Excel.Range rng = ExWorksheet.UsedRange;
    int rowCount = rng.Rows.Count;
    int colCount = rng.Columns.Count;
    
    string[,] tsReqs = new string[rowCount, colCount];
    
    for (int i = 1; i <= rowCount; i++)
    {
        for (int j = 1; j <= colCount; j++)
        {
            string str = rng.Cells[i, j].Text;
            tsReqs[i - 1, j - 1] = str;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a script where someone will post an opening for a
could someone please tell me what I need to do in order to create
I need to create a view or a table valued function that returns one
i need to get the string from on php file someone know how can
I want create a rest method(http put) that takes a list of string as
I am trying to create view or a function that will build a HTML
I have a number of gpx files that my app creates and will need
I need someone help. When I open https://developers.facebook.com/docs/reference/api/ and clicked https://graph.facebook.com/me/likes?access_token=blablabla , I got
I need someone to lead/guide me where have I code wrongly because I can't
Please need someone's expertise on my link; http://360webmedia.com/Store/development/index.html In my my menu_left.jpg is displaying

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.