Search
Views

JSpreadsheet provides two controls that can display and modify Worksheet and Workbook objects respectively.

Worksheet View

The WorksheetView control can be used to display Worksheet objects on a Windows form. The view displays the cells and objects of the worksheet and provides the users the ability to:

  • scroll the worksheet using the scrollbars, the keyboard or the mouse;
  • modify cell data by pressing F2 while the cell is active or by typing directly;
  • perform auto-fills by dragging the bottom right corner of the current selection;
  • select cells by using the keyboard or by dragging with the mouse;
  • cut, copy and paste cell data;
  • modify interactive objects (such as pictures and charts) by dragging them with the mouse;
  • resize and hide headers, and more.

The worksheet is associated with the view through the Worksheet property. The currently active cell can be get or set through the ActiveCell property. The cell and object selection can be manipulated through the Selection property. The ScrollX and ScrollY properties can be used to get or set the position of the scrollbars. The scrollbars can be hidden through the ShowHorizontalScrollBar and ShowVerticalScrollBar properties. The worksheet headers can be hidden through the ShowHeaders property. The grid lines can be toggled through the ShowGridLines property. The cursors displayed during various user interactions can be customized through a set of properties: PointerCursor, AutoFillCursor, DiagonalResizeCursor, CounterDiagonalResizeCursor, HorizontalResizeCursor, VerticalResizeCursor, MoveCursor, DisallowCursor, HorizontalSplitCursor, and VerticalSplitCursor.

The view provides many events that can be used to track, validate and respond to user activities in the view. Some of the more interesting ones are listed below:

  • cellClicked raised when the user clicks a cell with the mouse.
  • hyperlinkClicked raised when the user clicks a cell containing a Hyperlink.
  • inplaceEditStarting raised when the user is about to in-place edit a cell and can be used to prevent cells from being in-place edited.
  • propertyChanged raised when a property of the view has changed. This event can be useful to track when the user scrolls the view or changes the active cell.

For a complete list of the view events, see WorksheetViewListener.

Workbook View

The WorkbookView control can be used to display Workbook objects on a Windows form. It extends the WorksheetView by adding tabs and a formula bar. The tabs represent the worksheets in the workbook. Selecting a tab results in activating its associated worksheet in the control. The formula bar displays the data of the currently active cell. The following image illustrates the WorkbookView control:

The workbook is associated with the view through the Workbook property. Similarly to the WorksheetView, the WorkbookView provides properties for manipulating the active cell and selection, for scrolling the view, for hiding the scrollbars and the worksheet headers, and so on.

The currently active worksheet can be get or set through the ActiveWorksheet property. The tabs representing the worksheets in the workbook can be customized through several properties. The alignment of the tabs is set through the TabAlignment property. The ShowTabs, ShowTabCloseButtons, ShowTabNavigationButtons, and ShowCreateNewTab properties can be used to show or hide the tab panel, the close buttons inside the individual tabs, the navigation buttons, and the button that can be used to create new worksheets respectively. The AllowTabReorder property specifies whether the tabs can be reordered interactively by dragging them with the mouse. Finally, the AllowTabEdit property indicates whether worksheets can be renamed in-place by double clicking on their respective tab.

The view provides various events, including worksheetAdded, worksheetRenamed, and activeWorksheetChanged. For the complete list of events, check WorkbookViewListener.

The view also provides several methods that can be used to auto-size rows and columns based on the cell content, namely, resizeColumnToFit, resizeColumnsToFit, resizeRowToFit, and resizeRowsToFit.