Other API Samples

Live SpreadsheetGear API Samples

Worksheet Samples Display Options

Modify options such as freeze panes, set gridline visibility and color, show and hide headings, zoom, current range selection and more.

// Create a new workbook and references to the worksheet, cells and window info.
SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
SpreadsheetGear.IWorksheet worksheet = workbook.ActiveWorksheet;
SpreadsheetGear.IRange cells = worksheet.Cells;
SpreadsheetGear.IWorksheetWindowInfo windowInfo = worksheet.WindowInfo;

// Add a formula to a cell.
cells["I7"].Formula = "=PI()";

// Set the zoom to 75%.  Available range is 10% - 400%.
windowInfo.Zoom = 75;

// Place a horizontal split so that 1 row is displayed above the split.
windowInfo.SplitRows = 1;

// Scroll the worksheet horizontally so that Column D is the first visible column.
windowInfo.ScrollColumn = 3;

// Place a vertical split so that 2 columns are displayed to the left of the split.
// Note that the split is positioned relative to the first visible column (Column D
// in this case) and not Column A, which effectively hides Columns A:B.
windowInfo.SplitColumns = 2;

// The vertical and horizontal splits we just created could be moved in Excel unless
// you enable FreezePanes.  Unfrozen panes also allows for the top and left panes to
// be scrollable.
windowInfo.FreezePanes = true;

// Enable or disable gridlines (enabled by default).
windowInfo.DisplayGridlines = true;

// Set gridline color.
windowInfo.GridlineColor = SpreadsheetGear.Colors.LightSkyBlue;

// Show or hide the row and column headers.
windowInfo.DisplayHeadings = false;

// Toggle showing either the calculated values of formulas or the formulas 
// themselves.
windowInfo.DisplayFormulas = true;

// Make a more complex range selection with multiple areas, and specify a specific
// cell within the second area of the range selection to be the active cell.
windowInfo.SetSelection(cells["F2:H4,H6:J8,I10:K12"], cells["I7"], 1);
Run This Sample
Download File

Download an Excel Open XML Workbook (*.xlsx) file with the results of this sample.