How to read single Excel cell value

0 votes

I need to read a value from row 2 and column 10 in an excel file with sheet 1. This is my code.

Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
string currentSheet = "Sheet1";
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
var cell = (Excel.Range)excelWorksheet.Cells[10, 2];

I'm unable to read the contents of a cell after obtaining an Excel.Range cell object. I tried turning it into an array, looping through it, turning it into a string array, etc. It is undoubtedly pretty easy. Is there a straightforward way to retrieve a single string value from a cell?

Nov 19, 2022 in Others by Kithuzzz
• 38,010 points
408 views

1 answer to this question.

0 votes

You need to cast it to a string (not an array of strings) since it's a single value.

var cellValue = (string)(excelWorksheet.Cells[10, 2] as Excel.Range).Value;
answered Nov 19, 2022 by narikkadan
• 63,420 points

Related Questions In Others

0 votes
1 answer
0 votes
1 answer

How to express absolute cell references in Excel R1C1-style formulas?

If the formulas are in Column K ...READ MORE

answered Oct 15, 2022 in Others by narikkadan
• 63,420 points
581 views
0 votes
1 answer

How to stick an embedded document in a specific cell of an excel

Solution Select the documents (you can use the ...READ MORE

answered Oct 18, 2022 in Others by narikkadan
• 63,420 points
397 views
0 votes
1 answer

How to find out how many rows and columns to read from an Excel file with PHPExcel?

Solution: $file_name = htmlentities($_POST['file_name']); $sheet_name = htmlentities($_POST['sheet_name']); $number_of_columns = htmlentities($_POST['number_of_columns']); $number_of_rows ...READ MORE

answered Oct 23, 2022 in Others by narikkadan
• 63,420 points
6,652 views
0 votes
1 answer

Generate a flat list of all excel cell formulas

Hello, you'll have to follow certain steps ...READ MORE

answered Feb 18, 2022 in Others by gaurav
• 23,260 points
347 views
0 votes
1 answer

Convert a number to a letter in C# for use in Microsoft Excel [duplicate]

If you are familiar with using formulas ...READ MORE

answered Feb 23, 2022 in Database by gaurav
• 23,260 points
571 views
0 votes
1 answer

Deleting duplicate rows in Excel using Epplus

You need to re-think this… the while ...READ MORE

answered Feb 23, 2022 in Database by gaurav
• 23,260 points
1,034 views
0 votes
1 answer

Export DataTable to Excel File

Add Interop References. First we need to ...READ MORE

answered Jun 9, 2022 in JQuery by gaurav
• 23,260 points
550 views
0 votes
1 answer

How to access entire row by cell address or value in excel?

You may accomplish all of this by ...READ MORE

answered Dec 28, 2022 in Others by narikkadan
• 63,420 points
994 views
0 votes
1 answer

Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

You misunderstand the purpose of the function ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,420 points
3,047 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP