Documents for Excel .NET Edition | GCDocuments
Features / Worksheet / Worksheet Views
In This Topic
    Worksheet Views
    In This Topic

    GcExcel offers various options to customize display settings that are applied to a worksheet. You can either choose from pre-defined views or customize the view settings to get the preferred display. You can also save customized views in a workbook and apply them later.

    Pre-defined Views

    GcExcel.NET, similar to MS Excel, provides pre-defined views to make it easier for users to preview the page layout and page breaks before printing the document.

    These pre-defined views can be set using ViewType property of the IWorksheetView interface.

    C#
    Copy Code
    IWorkbook workbook = new Workbook();
    IWorksheet worksheet = workbook.ActiveSheet;
    
    worksheet.Range["J12"].Value = 1;
    
    //Set the view mode of the worksheet to PageBreakPreview.
    worksheet.SheetView.ViewType = ViewType.PageBreakPreview;
    
    //Modify the zoom of the PageBreakPreview to 80%.
    worksheet.SheetView.Zoom = 80;
    
    workbook.Save("PageBreak.xlsx");

    View Settings

    In order to view a worksheet as per their own preferences, users can use the properties and methods of the IWorksheet interface, IPane interface and IWorksheetView interface.

    The following code snippet shows how to set custom view for a worksheet using different properties of the IWorksheet interface.

    C#
    Copy Code
    //Set worksheet view
    
    IWorkbook workbook = new Workbook();
    IWorksheet worksheet = workbook.Worksheets[0];
    var custom_view = worksheet.SheetView;
    custom_view.Zoom = 200;
    custom_view.GridlineColor = Color.Red;
    custom_view.ScrollColumn = 10;
    var scrollRow = custom_view.ScrollRow;
    
    

    The following code snippet shows how to use the SplitPanes() method to split the worksheet into panes.

    C#
    Copy Code
    //Split worksheet using SplitPanes() method
    
    Workbook workbook = new Workbook();
    IWorksheet worksheet = workbook.Worksheets[0];
    worksheet.SplitPanes(worksheet.Range["A5"].Row, worksheet.Range["A5"].Column);
    
    var splitRow = worksheet.SplitRow;
    var splitColumn = worksheet.SplitColumn;
    

    The following code snippet shows how to use the DisplayVerticalGridlines and DisplayHorizontalGridlines properties to display the vertical and horizontal gridlines of a worksheet. These gridlines are only visible while interacting with SpreadJS by doing JSON I/O and are not visible in Excel or PDF.

    C#
    Copy Code
    //create a new workbook
    var workbook = new Workbook();
    
    IWorksheet worksheet = workbook.Worksheets[0];
    
    worksheet.Range["A10"].Value = 10;
    
    //Set to not show horizontal gridlines
     worksheet.SheetView.DisplayHorizontalGridlines = false;
    
    //Set to show vertical gridlines
    worksheet.SheetView.DisplayVerticalGridlines = true;
    
    //Export workbook to json string and save to ssjson
    System.IO.File.WriteAllText("gridlines.ssjson", workbook.ToJson());
    Note: If the value of DisplayGridlines is set, DisplayVerticalGridlines and DisplayHorizontalGridlines are also set to the same value.

    GcExcel.NET also lets you save custom views in the workbook. To learn more about custom views, see Custom Views.