altandogan
altandogan

Reputation: 1285

Excel sheets select first row with c#

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

Upvotes: 6

Views: 21703

Answers (3)

Pranesh Janarthanan
Pranesh Janarthanan

Reputation: 1194

This works for me. To select the first row of excel sheet and apply style bold

 xlWorkSheet.Cells[1, 1].EntireRow.Font.Bold = true; 

Upvotes: 0

CloudyMarble
CloudyMarble

Reputation: 37576

Try:

xlWorkSheet.Range("A1", "A1").EntireRow.Value;

Upvotes: 9

Anatolii Gabuza
Anatolii Gabuza

Reputation: 6260

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

var firstRow = range.Rows[1];

Upvotes: 8

Related Questions