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

    GcExcel allows users to personalize the display of the workbook. You can use the BookView property of the IWorkbook interface to set the view of the workbook as per your preferences. You can also customize display settings of the workbook by using the properties such as DisplayHorizontalScrollBarDisplayHorizontalScrollBarDisplayWorkbookTabs and TabRatio of the IWorkbookView interface.

    Copy Code
    //Set workbook view
    IWorkbook workbook = new Workbook();
    var bookView = workbook.BookView;
    bookView.DisplayHorizontalScrollBar = true;
    bookView.DisplayVerticalScrollBar = true;
    bookView.DisplayWorkbookTabs = true;
    bookView.TabRatio = 0.8;

    Custom Views

    GcExcel.NET also lets you save the views created by customizing properties or methods as custom views. Collection of custom views stored in a workbook is represented by IWorkbook.CustomViews. Each custom view in the collection is represented by ICustomView object and stores the view state of all worksheets in the current workbook. You can set Name, RowColSettings and PrintSettings properties for each custom view. To add a new custom view to a workbook, you can use the Add method. If a custom view name already exists in the collection, the new view overwrites the existing custom view. To apply a custom view to the workbook, you can use ICustomView.Show method. Similarly, you can delete custom views from the collection by calling ICustomView.Delete method.

    Note: The Add method does not allow addition of custom view and throws an exception in following cases:

    • When workbook contains a table or pivot table
    • When name of the custom view is null or whitespace


    Copy Code
    IWorkbook workbook = new Workbook();
    IWorksheet worksheet1 = workbook.ActiveSheet;
    IWorksheet worksheet2 = workbook.Worksheets.Add();
    worksheet1.Range["J12"].Value = 1;
    worksheet2.Range["J12"].Value = 2;
    // Add the normal view.
    workbook.CustomViews.Add("Normal", true, true);
    worksheet1.PageSetup.PrintArea = "$C$4:$J$12";
    worksheet2.PageSetup.PaperSize = PaperSize.A4;
    // Add a new view which saves the current page settings of all worksheets.
    workbook.CustomViews.Add("PrintSetting", true, false);
    worksheet1.Range["5:6"].Hidden = true;
    worksheet2.Range["5:6"].Hidden = true;
    // Add a new view which saves the current hidden rows/columns, filter settings of all worksheets.
    workbook.CustomViews.Add("HiddenRows", false, true);
    // Apply PrintSetting custom view 
    // In the exported file, the user can switch between custom views.