Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel sheets select first row with c#

Tags:

c#

excel

linq

I want to select excel sheets first row using interop object. How can i do ?

xlWorkBook = xlApp.Workbooks.Open(directory, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
var List<string> tempList= range[1,*].Value.ToList();

I want to write similar as abow. How can I write this situation

like image 307
altandogan Avatar asked Jan 14 '14 12:01

altandogan


2 Answers

There is Rows property using which you can access first row of particular range:

var firstRow = range.Rows[1];
like image 193
Anatolii Gabuza Avatar answered Oct 08 '22 22:10

Anatolii Gabuza


Try:

xlWorkSheet.Range("A1", "A1").EntireRow.Value;
like image 37
CloudyMarble Avatar answered Oct 08 '22 22:10

CloudyMarble