Select / Focus a cell

Mar 14, 2012 at 1:56 PM

Hi all!

I am trying to select a cell so that it is focused when the workbook is opened. 

I have this:

var ws = ..//my Worksheet
ws.Select("A2");

However, this only *selects* the cell. I have many columns and when the workbook is opened, the A2 cell is selected but it is not focused, i.e. it's not shown in the visible area of Excel.

If somebody can help, that'd be awesome :)

Cheers!

Jan 21, 2013 at 9:39 PM

when you save the .xlsx, make sure the selected cell is "A2", I guess that's the one you want to be selected/focused. It work perfectly for me! :)

Jan 21, 2013 at 10:15 PM

Thanks for answering :)

That was not the problem. A2 is selected. But, I have many columns .. like it goes all the way to AB or something like that, so when the worksheet is opened, A2 is selected, but you cannot see it, because the visible columns are e.g. F-A2. :)

Jan 28, 2013 at 3:13 PM

This is a late reply to an old post, but I'm having the same problem.  I do some calculations in the worksheet, then save it, but when reopened, the focus is at the bottom, whether I 'select' cells at the top or not.  I want to be able to set the focus to the top row of the sheet so that when opened, the sheet is scrolled to the top.  I've googled high and low and cannot find a way to do this.  Is it possible?

Jan 28, 2013 at 4:16 PM
Edited Jan 28, 2013 at 7:33 PM

I tried to find a epplus method to do this but I could not find anything.  Doing a compare of spreadsheets using the Microsoft Open XML SDK 2.5 Productivity Tool I found that the extra xml needed to set visable focus to a cell is only in one xml file within the Excel xml package.  But I don't know how to modify say .WorkbookXML to add the extra xml:-

Differences in /xl/worksheets/sheet1.xml between a spreadsheet that has no viewable cell focused beyond its default of A1 and a spreadsheet that has its visible focus set to A86:-

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
 <dimension ref="A1"/>
 <sheetViews>
  <sheetView tabSelected="1" workbookViewId="0">
   
  </sheetView>
 </sheetViews>
 <sheetFormatPr defaultRowHeight="15"/>
 <sheetData/>
 <pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>
</worksheet>

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
 <dimension ref="A1"/>
 <sheetViews>
  <sheetView tabSelected="1" topLeftCell="A64" workbookViewId="0">
   <selection activeCell="A86" sqref="A86"/>
  </sheetView>
 </sheetViews>
 <sheetFormatPr defaultRowHeight="15"/>
 <sheetData/>
 <pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>
</worksheet>

Jan 28, 2013 at 4:41 PM

Thanks, xav2075.  Laura