Document Solutions for Excel, Java Edition | Document Solutions
Features / Workbook / Workbook Views
In This Topic
    Workbook Views
    In This Topic

    DsExcel Java enables users to customize the workbook appearance based on specific preferences.

    You can use the getBookView method of the IWorkbook interface in order to set the workbook display as per your choice.

    The IWorkbookView interface provides the following methods to allow users to further customize essential display settings in the workbook:

    Methods Descriptions

    getDisplayHorizontalScrollBar setDisplayHorizontalScrollBar

    Used to get or set the display of the horizontal scrollbar.            




    Used to get or set the display of the vertical scrollbar.




    Used to get or set the display of the workbook tabs.



    Used to get or set the ratio of the width of the tab area (of the workbook) to the width of the horizontal scroll bar (of the worksheet). The value of TabRatio can be any number between 0 and 1. By default, if the TabRatio is not set, the value is 0.6.

    In order to set the workbook view and customize other display settings, refer to the following code snippet.

    Copy Code
    // Create a new workbook
    Workbook workbook = new Workbook();
    // Configure Workbook View Settings
    IWorkbookView bookView = workbook.getBookView();
    bookView.setDisplayWorkbookTabs = true;
    // Save to an excel file

    Custom Views

    DsExcel Java 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.getCustomViews method. 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 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
    // Create a new workbook
    Workbook workbook = new Workbook();
    IWorksheet worksheet1 = workbook.getActiveSheet();
    IWorksheet worksheet2 = workbook.getWorksheets().add();
    // Add the normal view.
    workbook.getCustomViews().add("Normal", true, true);
    // Add a new view which saves the current page settings of all worksheets.
    workbook.getCustomViews().add("PrintSetting", true, false);
    // Add a new view which saves the current hidden rows/columns, filter settings of all worksheets.
    workbook.getCustomViews().add("HiddenRows", false, true);
    // Apply PrintSetting custom view 
    // In the exported file, the user can switch between custom views."CustomViewAdd.xlsx");