Search code examples
.netexcelepplus

Select doesn't scroll to the focused cell by default


I have been building an .xlsx Excel file using EPPlus and I'm trying to set the default scroll position to a cell on the far right so it can be visible to the user when they open the Excel file for the first time.

I've tried focusing the target cell using EPPlus worksheet.Select(cellAddress), but while the cell is selected, the scroll position still remains at the very left.

Is there a way to set the default scroll position to a cell?


Solution

  • The default scroll position to a cell address is set separately by ExcelWorksheetView.TopLeftCell. (By default its value is an empty string "", which means A1.)

    For example, to make the 50th column of the 1st row be at the top left of the view, use the following:

    worksheet.View.TopLeftCell = ws.Cells[1, 50].Address;
    
    /* Or simply */
    worksheet.View.TopLeftCell = "AX";