.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Excel Values to Multi Dimensioanl Array

Posted By:Suderson Sarathy       Posted Date: November 22, 2010    Points: 50    Category: C#    URL: http://www.dotnetspark.com  

This Articles explains on how to pass the Excel Values to an Multi-Dimensional Object Array

book = app.Workbooks.Open(uploadpathforfpl2);
sheet = (Microsoft.Office.Interop.Excel.Worksheet)book.Sheets[1];
Range rg;
rg = sheet.UsedRange.Columns;
strValue = rg.Text.ToString();
string lastcolumn = Convert.ToChar(64 + sheet.UsedRange.Columns.Count).ToString();
Range rng = (Range)sheet.get_Range("A1", lastcolumn + sheet.UsedRange.Rows.Count);
Object[,] values = rng.get_Value(XlRangeValueDataType.xlRangeValueDefault) as Object[,];

// This loop is to find the column index of the status column in the excel sheet
 for (int colnameindex = 1; colnameindex <= values.GetUpperBound(1); colnameindex++)
  if (values[1, colnameindex].ToString() == "Status")
     StatusColumnIndex = colnameindex;
else if (values[1, colnameindex].ToString() == "Email")
     EmailColumnIndex = colnameindex;
Here the above code open an Excel Sheet using Interop Services of Excel.

Specify the range in the excel sheet. As per the abve Ex, the range is from A1 to the last column in the specified Excel Sheet,

Now using the XLRangeDefault property, copying the values from the Excel Sheet to the Multi-dimensional Object.

Upperbound is the highest value of the dimension in the index.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend