GemBox - scroll into view functionality missing?

319 views Asked by At

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.

2

There are 2 answers

0
peter3 On BEST ANSWER

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;
1
GemBox Dev Team On

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");