1

I'm working with GemBox (version 3.5) for the first time and have one problem. When opening a generated XLSX file, it is always scrolled to the bottom of the worksheet. I (or, rather, my customer) want it to start out at the top left position.

Is there any way to programmatically set the top visible cell before saving, i.e a "scroll into view" or "scroll to top" function? I haven't found anything in the GemBox documentation or on the interwebs that addresses this issue.

peter3
  • 1,074
  • 13
  • 22
  • Isn't that an excel feature? The last active cell is saved. If you can set cell A1 in worksheet 1 as active and save the workbook should open on that cell. – rene Jan 09 '14 at 15:23
  • There is no "set active" functionality AFAICS, but I tried setting the value of the top left cell as the last thing before saving. Still scrolled to the bottom when opening, though... – peter3 Jan 09 '14 at 16:14
  • Hmmm, it was worth a try... – rene Jan 09 '14 at 16:17

2 Answers2

2

To set an active cell with GemBox.Spreadsheet 3.5 you can use ExcelViewOptions.SelectedCells .

// Create new excel file.
ExcelFile ef = new ExcelFile();
// Create new excel sheet.
ExcelWorksheet ws = ef.Worksheets.Add("Sample");

// Add some sample content.
foreach (var i in Enumerable.Range(0, 5000))
    ws.Rows[i].Cells[0].Value = "Sample";

// Set SelectedCells to "A1" cell.
ws.ViewOptions.SelectedCells = ws.Cells.GetSubrange("A1", "A1");

// Save as XLSX file.
ef.SaveXlsx("Sample.xlsx");

EDIT 2017-07-17:
In newer version, GemBox.Spreadsheet 4.1, you can specify one or more cell ranges to be selected with ExcelWorksheet.SelectedRanges, like the following:

// Set "A1" as selected range.
ws.SelectedRanges.Add(ws.Cells.GetSubrange("A1"));

ef.Save("Sample.xlsx");
GemBox Dev Team
  • 669
  • 5
  • 18
2

After some digging I found another way of doing it with ViewOptions on Worksheet ('ws' in this example):

ws.ViewOptions.FirstVisibleColumn = 0;
ws.ViewOptions.FirstVisibleRow = 0;
Mario Z
  • 4,328
  • 2
  • 24
  • 38
peter3
  • 1,074
  • 13
  • 22