Class Spreadsheet

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.spreadsheet.Spreadsheet
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, Action.Container, Serializable

@Tag("vaadin-spreadsheet") @JsModule("./vaadin-spreadsheet/vaadin-spreadsheet.js") @Uses(com.vaadin.flow.component.charts.Chart.class) public class Spreadsheet extends com.vaadin.flow.component.Component implements com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, Action.Container
Vaadin Spreadsheet is a component which allows displaying and interacting with the contents of an Excel file. The Spreadsheet can be used in any Vaadin application for enabling users to view and manipulate Excel files in their web browsers.
Author:
Vaadin Ltd.
See Also:
  • Field Details

    • cellStyleToCSSStyle

      protected HashMap<Integer,String> cellStyleToCSSStyle
    • HIDE_FUNCTION_BAR_STYLE

      public static final String HIDE_FUNCTION_BAR_STYLE
      This is a style which hides the top (address and formula) bar.
      See Also:
    • HIDE_TABSHEET_STYLE

      public static final String HIDE_TABSHEET_STYLE
      This is a style which hides the bottom (sheet selection) bar.
      See Also:
    • mergedRegionCounter

      protected int mergedRegionCounter
    • initialSheetSelection

      protected String initialSheetSelection
    • mergedRegionContainer

      protected final MergedRegionUtil.MergedRegionContainer mergedRegionContainer
      Container for merged regions for the currently active sheet.
  • Constructor Details

    • Spreadsheet

      public Spreadsheet()
      Creates a new Spreadsheet component using the newer Excel version format XSSFWorkbook. Also creates one sheet using the default row SpreadsheetFactory.DEFAULT_ROWS and column SpreadsheetFactory.DEFAULT_COLUMNS counts.
    • Spreadsheet

      public Spreadsheet(int defaultRowCount, int defaultColumnCount)
      Creates a new Spreadsheet component using the newer Excel version format XSSFWorkbook. Also creates one sheet using the given row and column counts. These counts will also be set as default for any new sheets created later.
      Parameters:
      defaultRowCount - Default row count for new sheets
      defaultColumnCount - Default column count for new sheets
    • Spreadsheet

      public Spreadsheet(org.apache.poi.ss.usermodel.Workbook workbook)
      Creates a new Spreadsheet component and loads the given Workbook.
      Parameters:
      workbook - Workbook to load
    • Spreadsheet

      public Spreadsheet(File file) throws IOException
      Creates a new Spreadsheet component and loads the given Excel file.
      Parameters:
      file - Excel file
      Throws:
      IOException - If file has invalid format or there is no access to the file
    • Spreadsheet

      public Spreadsheet(InputStream inputStream) throws IOException
      Creates a new Spreadsheet component based on the given input stream. The expected format is that of an Excel file.
      Parameters:
      inputStream - Stream that provides Excel-formatted data.
      Throws:
      IOException - If there is an error handling the stream, or if the data is in an invalid format.
  • Method Details

    • getId

      public Optional<String> getId()
      Overrides:
      getId in class com.vaadin.flow.component.Component
    • setId

      public void setId(String id)
      Overrides:
      setId in class com.vaadin.flow.component.Component
    • setSpreadsheetHandler

      public void setSpreadsheetHandler(SpreadsheetHandlerImpl spreadsheetHandler)
      Register a Spreadsheet handler to listen to Spreadsheet Events. Removes the default / previously set spreadsheet handler.
      Parameters:
      spreadsheetHandler -
    • createDefaultHandler

      protected SpreadsheetHandlerImpl createDefaultHandler()
      Create the default Spreadsheet handler.
      Returns:
      SpreadsheetHandlerImpl
    • createCellValueManager

      protected CellValueManager createCellValueManager()
      Override if there are desired changes or temporary bug fixes, but be careful - this class should cache values for performance.
      Returns:
      CellValueManager
    • customInit

      protected void customInit()
      Implement this to perform custom initialization in subclasses. Called before loading any workbook, at the end of the required init() actions.
    • addActionHandler

      public void addActionHandler(Action.Handler actionHandler)
      Adds an action handler to the spreadsheet that handles the event produced by the context menu (right click) on cells and row and column headers. The action handler is component, not workbook, specific.

      The parameters on the Action.Handler.handleAction(Action, Object, Object) and Action.Handler.getActions(Object, Object) depend on the actual target of the right click.

      The second parameter (sender) on Action.Handler.getActions(Object, Object) is always the spreadsheet component. In case of a cell, the first parameter (target) on contains the latest Spreadsheet.SelectionChangeEvent for the spreadsheet. In case of a row or a column header, the first parameter (target) is a CellRangeAddress. To distinct between column / row header, you can use CellRangeAddressBase.isFullColumnRange() and CellRangeAddressBase.isFullRowRange().

      Similarly for Action.Handler.handleAction(Action, Object, Object) the second parameter (sender) is always the spreadsheet component. The third parameter (target) is the latest Spreadsheet.SelectionChangeEvent for the spreadsheet, or the CellRangeAddress defining the selected row / column header.

      Specified by:
      addActionHandler in interface Action.Container
      Parameters:
      actionHandler - the new handler to be added.
    • removeDefaultActionHandler

      public void removeDefaultActionHandler()
      Removes the spreadsheet's SpreadsheetDefaultActionHandler added on init()
    • removeActionHandler

      public void removeActionHandler(Action.Handler actionHandler)
      Description copied from interface: Action.Container
      Removes a previously registered action handler for the contents of this container.
      Specified by:
      removeActionHandler in interface Action.Container
      Parameters:
      actionHandler - the handler to be removed.
    • setCellValueHandler

      public void setCellValueHandler(Spreadsheet.CellValueHandler customCellValueHandler)
      Sets the Spreadsheet.CellValueHandler for this component (not workbook/sheet specific). It is called when a cell's value has been updated by the user by using the spreadsheet component's default editor (text input).
      Parameters:
      customCellValueHandler - New handler or null if none should be used
    • getCellValueHandler

      public Spreadsheet.CellValueHandler getCellValueHandler()
      Returns:
      the current Spreadsheet.CellValueHandler for this component or null if none has been set
    • setCellDeletionHandler

      public void setCellDeletionHandler(Spreadsheet.CellDeletionHandler customCellDeletionHandler)
      Sets the Spreadsheet.CellDeletionHandler for this component (not workbook/sheet specific). It is called when a cell has been deleted by the user.
      Parameters:
      customCellDeletionHandler - New handler or null if none should be used
    • getCellDeletionHandler

      public Spreadsheet.CellDeletionHandler getCellDeletionHandler()
      Returns:
      the current Spreadsheet.CellDeletionHandler for this component or null if none has been set
    • setHyperlinkCellClickHandler

      public void setHyperlinkCellClickHandler(Spreadsheet.HyperlinkCellClickHandler handler)
      Sets the Spreadsheet.HyperlinkCellClickHandler for this component (not workbook/sheet specific). Called when the user clicks a cell that is a hyperlink or uses the hyperlink function.
      Parameters:
      handler - new handler or null if none should be used
      See Also:
    • getHyperlinkCellClickHandler

      public Spreadsheet.HyperlinkCellClickHandler getHyperlinkCellClickHandler()
      Returns:
      the current Spreadsheet.HyperlinkCellClickHandler for this component or null if none has been set
    • getContextMenuManager

      public ContextMenuManager getContextMenuManager()
      Gets the ContextMenuManager for this Spreadsheet. This is component (not workbook/sheet) specific.
      Returns:
      The ContextMenuManager
    • getCellSelectionManager

      public CellSelectionManager getCellSelectionManager()
      Gets the CellSelectionManager for this Spreadsheet. This is component (not workbook/sheet) specific.
      Returns:
      The CellSelectionManager
    • getCellValueManager

      public CellValueManager getCellValueManager()
      Gets the CellValueManager for this Spreadsheet. This is component (not workbook/sheet) specific.
      Returns:
      The CellValueManager
    • getCellShifter

      protected CellSelectionShifter getCellShifter()
      Gets the CellShifter for this Spreadsheet. This is component (not workbook/sheet) specific.
      Returns:
      The CellShifter
    • getSpreadsheetHistoryManager

      public SpreadsheetHistoryManager getSpreadsheetHistoryManager()
      Gets the SpreadsheetHistoryManager for this Spreadsheet. This is component (not workbook/sheet) specific.
      Returns:
      The SpreadsheetHistoryManager
    • getMergedRegionContainer

      protected MergedRegionUtil.MergedRegionContainer getMergedRegionContainer()
      Gets the MergedRegionContainer for this Spreadsheet. This is component (not workbook/sheet) specific.
      Returns:
      The MergedRegionContainer
    • getFirstColumn

      public int getFirstColumn()
      Returns the first visible column in the main scroll area (NOT freeze pane)
      Returns:
      Index of first visible column, 1-based
    • getLastColumn

      public int getLastColumn()
      Returns the last visible column in the main scroll area (NOT freeze pane)
      Returns:
      Index of last visible column, 1-based
    • getFirstRow

      public int getFirstRow()
      Returns the first visible row in the scroll area (not freeze pane)
      Returns:
      Index of first visible row, 1-based
    • getLastRow

      public int getLastRow()
      Returns the last visible row in the main scroll area (NOT freeze pane)
      Returns:
      Index of last visible row, 1-based
    • getLastFrozenRow

      public int getLastFrozenRow()
      Returns the index the last frozen row (last row in top freeze pane).
      Returns:
      Last frozen row or 0 if none
    • getLastFrozenColumn

      public int getLastFrozenColumn()
      Returns the index the last frozen column (last column in left freeze pane).
      Returns:
      Last frozen column or 0 if none
    • isChartsEnabled

      public boolean isChartsEnabled()
      Returns true if embedded charts are displayed
      Returns:
      See Also:
    • setChartsEnabled

      public void setChartsEnabled(boolean chartsEnabled)
      Use this method to define whether embedded charts should be displayed in the spreadsheet or not.
      Parameters:
      chartsEnabled -
    • isRerenderPending

      public boolean isRerenderPending()
      Returns true if the component is being fully re-rendered after this round-trip (sheet change etc.)
      Returns:
      true if re-render will happen, false otherwise
    • setShowCustomEditorOnFocus

      public void setShowCustomEditorOnFocus(boolean showCustomEditorOnFocus)
      Sets the visibility of the custom editor. By default, if a custom editor is defined for a cell, then it is displayed on that cell. This behavior can be changed by setting this property to true, which makes the custom editor visible when the cell is focused.
      Parameters:
      showCustomEditorOnFocus - a boolean indicating whether the custom editor should be visible on focus (true) or not (false)
    • isShowCustomEditorOnFocus

      public boolean isShowCustomEditorOnFocus()
      Returns whether the custom editor is shown on focus or not.
      Returns:
      a boolean indicating whether the custom editor is visible on focus (true) or not (false)
    • fireEvent

      protected void fireEvent(com.vaadin.flow.component.ComponentEvent event)
      Overrides:
      fireEvent in class com.vaadin.flow.component.Component
    • onSheetScroll

      protected void onSheetScroll(int firstRow, int firstColumn, int lastRow, int lastColumn)
      This method is called when the sheet is scrolled. It takes care of sending newly revealed data to the client side.
      Parameters:
      firstRow - Index of first visible row after the scroll, 1-based
      firstColumn - Index of first visible column after the scroll, 1-based
      lastRow - Index of last visible row after the scroll, 1-based
      lastColumn - Index of first visible column after the scroll, 1-based
    • isRangeEditable

      protected boolean isRangeEditable(org.apache.poi.ss.util.CellRangeAddress cellRangeAddress)
      Tells whether the given cell range is editable or not.
      Parameters:
      cellRangeAddress - Cell range to test
      Returns:
      True if range is editable, false otherwise.
    • isRangeEditable

      protected boolean isRangeEditable(int row1, int col1, int row2, int col2)
      Determines if the given cell range is editable or not.
      Parameters:
      row1 - Index of starting row, 0-based
      col1 - Index of starting column, 0-based
      row2 - Index of ending row, 0-based
      col2 - Index of ending column, 0-based
      Returns:
      True if the whole range is editable, false otherwise.
    • createCorrectCellRangeAddress

      protected org.apache.poi.ss.util.CellRangeAddress createCorrectCellRangeAddress(String addressString)
      Creates a CellRangeAddress from the given cell address string. Also checks that the range is valid within the currently active sheet. If it is not, the resulting range will be truncated to fit the active sheet.
      Parameters:
      addressString - Cell address string, e.g. "B3:C5"
      Returns:
      A CellRangeAddress based on the given coordinates.
    • createCorrectCellRangeAddress

      protected org.apache.poi.ss.util.CellRangeAddress createCorrectCellRangeAddress(int row1, int col1, int row2, int col2)
      Creates a CellRangeAddress from the given start and end coordinates. Also checks that the range is valid within the currently active sheet. If it is not, the resulting range will be truncated to fit the active sheet.
      Parameters:
      row1 - Index of the starting row, 1-based
      col1 - Index of the starting column, 1-based
      row2 - Index of the ending row, 1-based
      col2 - Index of the ending column, 1-based
      Returns:
      A CellRangeAddress based on the given coordinates.
    • setLocale

      public void setLocale(Locale locale)
      Set the Locale for the Spreadsheet. The locale is used for formatting cell values.
      Parameters:
      locale - the locale set to the spreadsheet, cannot be null
    • getLocale

      public Locale getLocale()
      Gets the Locale for this spreadsheet
      Overrides:
      getLocale in class com.vaadin.flow.component.Component
      Returns:
      the locale used for spreadsheet
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component
    • setSheetHidden

      public void setSheetHidden(int sheetPOIIndex, org.apache.poi.ss.usermodel.SheetVisibility visibility) throws IllegalArgumentException
      See Workbook.setSheetHidden(int, boolean).

      Gets the Workbook with getWorkbook() and uses its API to access status on currently visible/hidden/very hidden sheets. If the currently active sheet is set hidden, another sheet is set as active sheet automatically. At least one sheet should be always visible.

      Parameters:
      sheetPOIIndex - Index of the target sheet within the POI model, 0-based
      visibility - Visibility state to set: visible, hidden, very hidden.
      Throws:
      IllegalArgumentException - If the index or state is invalid, or if trying to hide the only visible sheet.
    • getVisibleSheetNames

      public String[] getVisibleSheetNames()
      Returns an array containing the names of the currently visible sheets. Does not contain the names of hidden or very hidden sheets.

      To get all of the current Workbook's sheet names, you should access the POI API with getWorkbook().

      Returns:
      Names of the currently visible sheets.
    • setSheetName

      public void setSheetName(int sheetIndex, String sheetName) throws IllegalArgumentException
      Sets a name for the sheet at the given visible sheet index.
      Parameters:
      sheetIndex - Index of the target sheet among the visible sheets, 0-based
      sheetName - New sheet name. Not null, empty nor longer than 31 characters. Must be unique within the Workbook.
      Throws:
      IllegalArgumentException - If the index is invalid, or if the sheet name is invalid. See WorkbookUtil.validateSheetName(String).
    • setSheetNameWithPOIIndex

      public void setSheetNameWithPOIIndex(int sheetIndex, String sheetName) throws IllegalArgumentException
      Sets a name for the sheet at the given POI model index.
      Parameters:
      sheetIndex - Index of the target sheet within the POI model, 0-based
      sheetName - New sheet name. Not null, empty nor longer than 31 characters. Must be unique within the Workbook.
      Throws:
      IllegalArgumentException - If the index is invalid, or if the sheet name is invalid. See WorkbookUtil.validateSheetName(String).
    • setSheetProtected

      public void setSheetProtected(int sheetPOIIndex, String password)
      Sets the protection enabled with the given password for the sheet at the given index. null password removes the protection.
      Parameters:
      sheetPOIIndex - Index of the target sheet within the POI model, 0-based
      password - The password to set for the protection. Pass null to remove the protection.
    • setActiveSheetProtected

      public void setActiveSheetProtected(String password)
      Sets the protection enabled with the given password for the currently active sheet. null password removes the protection.
      Parameters:
      password - The password to set for the protection. Pass null to remove the protection.
    • createNewSheet

      public void createNewSheet(String sheetName, int rows, int columns) throws IllegalArgumentException
      Creates a new sheet as the last sheet and sets it as the active sheet. If the sheetName given is null, then the sheet name is automatically generated by Apache POI in Workbook.createSheet().
      Parameters:
      sheetName - Can be null, but not empty nor longer than 31 characters. Must be unique within the Workbook.
      rows - Number of rows the sheet should have
      columns - Number of columns the sheet should have
      Throws:
      IllegalArgumentException - If the sheet name is empty or over 31 characters long or not unique.
    • deleteSheetWithPOIIndex

      public void deleteSheetWithPOIIndex(int poiSheetIndex) throws IllegalArgumentException
      Deletes the sheet with the given POI model index. Note: A workbook must contain at least one visible sheet.
      Parameters:
      poiSheetIndex - POI model index of the sheet to delete, 0-based, max value Workbook.getNumberOfSheets() -1.
      Throws:
      IllegalArgumentException - In case there is only one visible sheet, or if the index is invalid.
    • deleteSheet

      public void deleteSheet(int sheetIndex) throws IllegalArgumentException
      Deletes the sheet at the given index. Note: A workbook must contain at least one visible sheet.
      Parameters:
      sheetIndex - Index of the sheet to delete among the visible sheets, 0-based, maximum value getNumberOfVisibleSheets() -1.
      Throws:
      IllegalArgumentException - In case there is only one visible sheet, or if the given index is invalid.
    • getNumberOfVisibleSheets

      public int getNumberOfVisibleSheets()
      Returns the number of currently visible sheets in the component. Doesn't include the hidden or very hidden sheets in the POI model.
      Returns:
      Number of visible sheets.
    • getNumberOfSheets

      public int getNumberOfSheets()
      Returns the total number of sheets in the workbook (includes hidden and very hidden sheets).
      Returns:
      Total number of sheets in the workbook
    • getActiveSheetIndex

      public int getActiveSheetIndex()
      Returns the index of the currently active sheet among the visible sheets ( hidden or very hidden sheets not included).
      Returns:
      Index of the active sheet, 0-based
    • getActiveSheetPOIIndex

      public int getActiveSheetPOIIndex()
      Returns the POI model index of the currently active sheet (index among all sheets including hidden and very hidden sheets).
      Returns:
      POI model index of the active sheet, 0-based
    • setActiveSheetIndex

      public void setActiveSheetIndex(int sheetIndex) throws IllegalArgumentException
      Sets the currently active sheet within the sheets that are visible.
      Parameters:
      sheetIndex - Index of the target sheet (among the visible sheets), 0-based
      Throws:
      IllegalArgumentException - If the index is invalid
    • setActiveSheetWithPOIIndex

      public void setActiveSheetWithPOIIndex(int sheetIndex) throws IllegalArgumentException
      Sets the currently active sheet. The sheet at the given index should be visible (not hidden or very hidden).
      Parameters:
      sheetIndex - Index of sheet in the POI model (contains all sheets), 0-based
      Throws:
      IllegalArgumentException - If the index is invalid, or if the sheet at the given index is hidden or very hidden.
    • onSheetSelected

      protected void onSheetSelected(int tabIndex, int scrollLeft, int scrollTop)
      This method will be called when a selected sheet change is requested.
      Parameters:
      tabIndex - Index of the sheet to select.
      scrollLeft - Current horizontal scroll position
      scrollTop - Current vertical scroll position
    • onNewSheetCreated

      protected void onNewSheetCreated(int scrollLeft, int scrollTop)
      This method is called when the creation of a new sheet has been requested.
      Parameters:
      scrollLeft - Current horizontal scroll position
      scrollTop - Current vertical scroll position
    • onSheetRename

      protected void onSheetRename(int sheetIndex, String sheetName)
      This method is called when a request to rename a sheet has been made.
      Parameters:
      sheetIndex - Index of the sheet to rename (among visible sheets).
      sheetName - New name for the sheet.
    • getColumns

      public int getColumns()
      Get the number of columns in the currently active sheet, or if setMaxColumns(int) has been used, the current number of columns the component shows (not the amount of columns in the actual sheet in the POI model).
      Returns:
      Number of visible columns.
    • getRows

      public int getRows()
      Get the number of rows in the currently active sheet, or if setMaxRows(int) has been used, the current number of rows the component shows (not the amount of rows in the actual sheet in the POI model).
      Returns:
      Number of visible rows.
    • getDataFormatter

      public org.apache.poi.ss.usermodel.DataFormatter getDataFormatter()
      Gets the current DataFormatter.
      Returns:
      The data formatter for this Spreadsheet.
    • getCell

      public org.apache.poi.ss.usermodel.Cell getCell(String cellAddress)
      Returns the Cell at the given address. If the cell is updated in outside code, call refreshCells(Cell...) AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".
      Parameters:
      cellAddress - Address of the Cell to return, e.g. "A3"
      Returns:
      The cell at the given address, or null if not defined
    • getCell

      public org.apache.poi.ss.usermodel.Cell getCell(int row, int col)
      Returns the Cell at the given coordinates. If the cell is updated in outside code, call refreshCells(Cell...) AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".
      Parameters:
      row - Row index of the cell to return, 0-based
      col - Column index of the cell to return, 0-based
      Returns:
      The cell at the given coordinates, or null if not defined
    • getCell

      public org.apache.poi.ss.usermodel.Cell getCell(int row, int col, org.apache.poi.ss.usermodel.Sheet sheet)
      Returns the Cell at the given coordinates. If the cell is updated in outside code, call refreshCells(Cell...) AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".
      Parameters:
      row - Row index of the cell to return, 0-based
      col - Column index of the cell to return, 0-based
      sheet - Sheet of the cell
      Returns:
      The cell at the given coordinates, or null if not defined
    • getCell

      public org.apache.poi.ss.usermodel.Cell getCell(org.apache.poi.ss.util.CellReference cellReference)
      Returns the Cell corresponding to the given reference. If the cell is updated in outside code, call refreshCells(Cell...) AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".
      Parameters:
      cellReference - Reference to the cell to return
      Returns:
      The cell corresponding to the given reference, or null if not defined
    • getCell

      public org.apache.poi.ss.usermodel.Cell getCell(String sheetName, int row, int column)
      Returns the Cell at the given coordinates. If the cell is updated in outside code, call refreshCells(Cell...) AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".
      Parameters:
      sheetName - Name of the sheet the cell is on, or current sheet if null
      row - Row index of the cell to return, 0-based
      column - Column index of the cell to return, 0-based
      Returns:
      The cell at the given coordinates, or null if not defined
    • getCell

      public org.apache.poi.ss.usermodel.Cell getCell(org.apache.poi.ss.util.CellReference cellReference, org.apache.poi.ss.usermodel.Sheet sheet)
      Returns the Cell corresponding to the given reference. If the cell is updated in outside code, call refreshCells(Cell...) AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".
      Parameters:
      cellReference - Reference to the cell to return
      sheet - Sheet of the cell
      Returns:
      The cell corresponding to the given reference, or null if not defined
    • deleteCell

      public void deleteCell(int row, int col)
      Deletes the cell from the sheet and the underlying POI model as well. This really deletes the cell, instead of just making it's value blank.
      Parameters:
      row - Row index of the cell to delete, 0-based
      col - Column index of the cell to delete, 0-based
    • refreshCells

      public void refreshCells(org.apache.poi.ss.usermodel.Cell... cells)
      Refreshes the given cell(s). Should be called when the cell value/formatting/style/etc. updating is done. NOTE: For optimal performance temporarily collect your updated cells and call this method only once per update cycle. Calling this method repeatedly for individual cells is not a good idea.
      Parameters:
      cells - Cell(s) to update
    • refreshCells

      public void refreshCells(Collection<org.apache.poi.ss.usermodel.Cell> cells)
      Refreshes the given cell(s). Should be called when the cell value/formatting/style/etc. updating is done. NOTE: For optimal performance temporarily collect your updated cells and call this method only once per update cycle. Calling this method repeatedly for individual cells is not a good idea.
      Parameters:
      cells - A Collection of Cells to update
    • markCellAsDeleted

      public void markCellAsDeleted(org.apache.poi.ss.usermodel.Cell cell, boolean cellStyleUpdated)
      Marks the cell as deleted. This method should be called after removing a cell from the Workbook using POI API.
      Parameters:
      cell - The cell that has been deleted.
      cellStyleUpdated - True if the cell style has changed
    • createFormulaCell

      public org.apache.poi.ss.usermodel.Cell createFormulaCell(int row, int col, String formula) throws IllegalArgumentException
      Creates a new Formula type cell with the given formula. After all editing is done, call refreshCells(Cell...) or refreshAllCellValues() to make sure client side is updated.
      Parameters:
      row - Row index of the new cell, 0-based
      col - Column index of the new cell, 0-based
      formula - The formula to set to the new cell (should NOT start with "=" nor "+")
      Returns:
      The newly created cell
      Throws:
      IllegalArgumentException - If columnIndex < 0 or greater than the maximum number of supported columns (255 for *.xls, 1048576 for *.xlsx)
    • createCell

      public org.apache.poi.ss.usermodel.Cell createCell(int row, int col, Object value) throws IllegalArgumentException
      Create a new cell (or replace existing) with the given value, the type of the value parameter will define the type of the cell. The value may be of the following types: Boolean, Calendar, Date, Double or String. The default type will be String, value of (Object.toString() will be given as the cell value. For formula cells, use createFormulaCell(int, int, String). After all editing is done, call refreshCells(Cell...) or refreshAllCellValues() to make sure the client side is updated.
      Parameters:
      row - Row index of the new cell, 0-based
      col - Column index of the new cell, 0-based
      value - Object representing the type and value of the Cell
      Returns:
      The newly created cell
      Throws:
      IllegalArgumentException - If columnIndex < 0 or greater than the maximum number of supported columns (255 for *.xls, 1048576 for *.xlsx)
    • refreshAllCellValues

      public void refreshAllCellValues()
      Forces recalculation and update to the client side for values of all of the sheet's cells. Note: DOES NOT UPDATE STYLES; use refreshCells(Cell...) when cell styles change.
    • setMaxColumns

      public void setMaxColumns(int cols)
      Set the number of columns shown for the current sheet. Any null cells are left empty. Any cells outside the given columns are hidden. Does not update the actual POI-based model! The default value will be the actual size of the sheet from the POI model.
      Parameters:
      cols - New maximum column count.
    • setMaxRows

      public void setMaxRows(int rows)
      Set the number of rows shown for the current sheet. Any null cells are left empty. Any cells outside the given rows are hidden. Does not update the actual POI-based model! The default value will be the actual size of the sheet from the POI model.
      Parameters:
      rows - New maximum row count.
    • setSheetMaxSize

      public void setSheetMaxSize(int rows, int cols)
      Does setMaxColumns(int) and setMaxRows(int) in one method.
      Parameters:
      rows - Maximum row count
      cols - Maximum column count
    • getDefaultColumnWidth

      public int getDefaultColumnWidth()
      Gets the default column width for the currently active sheet. This is derived from the active sheet's (getActiveSheet()) default column width (Sheet getDefaultColumnWidth()).
      Returns:
      The default column width in PX
    • setDefaultColumnWidth

      public void setDefaultColumnWidth(int widthPX)
      Sets the default column width in pixels that the component uses, this doesn't change the default column width of the underlying sheet, returned by getActiveSheet() and Sheet.getDefaultColumnWidth().
      Parameters:
      widthPX - The default column width in pixels
    • getDefaultRowHeight

      public float getDefaultRowHeight()
      Gets the default row height in points. By default it should be the same as Sheet.getDefaultRowHeightInPoints() for the currently active sheet getActiveSheet().
      Returns:
      Default row height for the currently active sheet, in points.
    • setDefaultRowHeight

      public void setDefaultRowHeight(float heightPT)
      Sets the default row height in points for this Spreadsheet and the currently active sheet, returned by getActiveSheet().
      Parameters:
      heightPT - New default row height in points.
    • onColumnAutofit

      protected void onColumnAutofit(int columnIndex)
      This method is called when column auto-fit has been initiated from the browser by double-clicking the border of the target column header.
      Parameters:
      columnIndex - Index of the target column, 0-based
    • autofitColumn

      public void autofitColumn(int columnIndex)
      Sets the column to automatically adjust the column width to fit the largest cell content within the column. This is a POI feature, and is meant to be called after all the data for the target column has been written. See Sheet.autoSizeColumn(int).

      This does not take into account cells that have custom Vaadin components inside them.

      Parameters:
      columnIndex - Index of the target column, 0-based
    • shiftRows

      public void shiftRows(int startRow, int endRow, int n)
      Shifts rows between startRow and endRow n number of rows. If you use a negative number for n, the rows will be shifted upwards. This method ensures that rows can't wrap around.

      If you are adding / deleting rows, you might want to change the number of visible rows rendered getRows() with setMaxRows(int).

      See Sheet.shiftRows(int, int, int).

      Parameters:
      startRow - The first row to shift, 0-based
      endRow - The last row to shift, 0-based
      n - Number of rows to shift, positive numbers shift down, negative numbers shift up.
    • shiftRows

      public void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight)
      Shifts rows between startRow and endRow n number of rows. If you use a negative number for n, the rows will be shifted upwards. This method ensures that rows can't wrap around.

      If you are adding / deleting rows, you might want to change the number of visible rows rendered getRows() with setMaxRows(int).

      See Sheet.shiftRows(int, int, int, boolean, boolean).

      Parameters:
      startRow - The first row to shift, 0-based
      endRow - The last row to shift, 0-based
      n - Number of rows to shift, positive numbers shift down, negative numbers shift up.
      copyRowHeight - True to copy the row height during the shift
      resetOriginalRowHeight - True to set the original row's height to the default
    • getFormulaEvaluator

      public org.apache.poi.ss.usermodel.FormulaEvaluator getFormulaEvaluator()
      Returns:
      the common FormulaEvaluator instance.
    • getConditionalFormattingEvaluator

      public org.apache.poi.ss.formula.ConditionalFormattingEvaluator getConditionalFormattingEvaluator()
      POI, as of 4.0.0, now accepts this as an argument to formula evaluation. Some conditional formats can modify the display text of a cell.
      Returns:
      the common ConditionalFormattingEvaluator instance.
    • deleteRows

      public void deleteRows(int startRow, int endRow)
      Deletes rows. See Sheet.removeRow(Row). Removes all row content, deletes cells and resets the sheet size. Does not shift rows up (!) - use shiftRows(int, int, int, boolean, boolean) for that.
      Parameters:
      startRow - Index of the starting row, 0-based
      endRow - Index of the ending row, 0-based
    • addMergedRegion

      public void addMergedRegion(String selectionRange)
      Merges cells. See Sheet.addMergedRegion(CellRangeAddress).
      Parameters:
      selectionRange - The cell range to merge, e.g. "B3:C5"
    • addMergedRegion

      public void addMergedRegion(int row1, int col1, int row2, int col2)
      Merge cells. See Sheet.addMergedRegion(CellRangeAddress).
      Parameters:
      row1 - Index of the starting row of the merged region, 0-based
      col1 - Index of the starting column of the merged region, 0-based
      row2 - Index of the ending row of the merged region, 0-based
      col2 - Index of the ending column of the merged region, 0-based
    • addMergedRegion

      public void addMergedRegion(org.apache.poi.ss.util.CellRangeAddress region) throws IllegalArgumentException
      Merges the given cells. See Sheet.addMergedRegion(CellRangeAddress).

      If another existing merged region is completely inside the given range, it is removed. If another existing region either encloses or overlaps the given range, an error is thrown. See CellRangeUtil.intersect(CellRangeAddress, CellRangeAddress).

      Note: POI doesn't seem to update the cells that are "removed" due to the merge - the values for those cells still exist and continue being used in possible formulas. If you need to make sure those values are removed, just delete the cells before creating the merged region.

      If the added region affects the currently selected cell, a new Spreadsheet.SelectionChangeEvent is fired.

      Parameters:
      region - The range of cells to merge
      Throws:
      IllegalArgumentException - If the given region overlaps with or encloses another existing region within the sheet.
    • removeMergedRegion

      public void removeMergedRegion(int index)
      Removes a merged region with the given index. Current merged regions can be inspected within the currently active sheet with getActiveSheet() and Sheet.getMergedRegion(int) and Sheet.getNumMergedRegions().

      Note that in POI after removing a merged region at index n, all regions added after the removed region will get a new index (index-1).

      If the removed region affects the currently selected cell, a new Spreadsheet.SelectionChangeEvent is fired.

      Parameters:
      index - Position of the target merged region in the POI merged region array, 0-based
    • reloadAllMergedRegions

      public void reloadAllMergedRegions()
      Discards all current merged regions for the sheet and reloads them from the POI model.

      This can be used if you want to add / remove multiple merged regions directly from the POI model and need to update the component. Note that you must also make sure that possible styles for the merged regions are updated, if those were modified, by calling reloadActiveSheetStyles().

    • reloadActiveSheetStyles

      public void reloadActiveSheetStyles()
      Reloads all the styles for the currently active sheet.
    • setColumnHidden

      public void setColumnHidden(int columnIndex, boolean hidden)
      Hides or shows the given column, see Sheet.setColumnHidden(int, boolean).
      Parameters:
      columnIndex - Index of the target column, 0-based
      hidden - True to hide the target column, false to show it.
    • isColumnHidden

      public boolean isColumnHidden(int columnIndex)
      Gets the visibility state of the given column. See Sheet.isColumnHidden(int).
      Parameters:
      columnIndex - Index of the target column, 0-based
      Returns:
      true if the target column is hidden, false if it is visible.
    • setRowHidden

      public void setRowHidden(int rowIndex, boolean hidden)
      Hides or shows the given row, see Row.setZeroHeight(boolean).
      Parameters:
      rowIndex - Index of the target row, 0-based
      hidden - True to hide the target row, false to show it.
    • isRowHidden

      public boolean isRowHidden(int rowIndex)
      Gets the visibility state of the given row. A row is hidden when it has zero height, see Row.getZeroHeight().
      Parameters:
      rowIndex - Index of the target row, 0-based
      Returns:
      true if the target row is hidden, false if it is visible.
    • read

      public void read(File file) throws IOException
      Reinitializes the component from the given Excel file.
      Parameters:
      file - Data source file. Excel format is expected.
      Throws:
      IOException - If the file can't be read, or the file is of an invalid format.
    • read

      public void read(InputStream inputStream) throws IOException
      Reinitializes the component from the given input stream. The expected format is that of an Excel file.
      Parameters:
      inputStream - Data source input stream. Excel format is expected.
      Throws:
      IOException - If handling the stream fails, or the data is in an invalid format.
    • write

      public File write(String fileName) throws FileNotFoundException, IOException
      Exports current spreadsheet into a File with the given name.
      Parameters:
      fileName - The full name of the file. If the name doesn't end with '.xls' or '.xlsx', the approriate one will be appended.
      Returns:
      A File with the content of the current Workbook, In the file format of the original Workbook.
      Throws:
      FileNotFoundException - If file name was invalid
      IOException - If the file can't be written to for any reason
    • write

      public void write(OutputStream outputStream) throws IOException
      Exports current spreadsheet as an output stream.
      Parameters:
      outputStream - The target stream
      Throws:
      IOException - If writing to the stream fails
    • getRowBufferSize

      public int getRowBufferSize()
      The row buffer size determines the amount of content rendered outside the top and bottom edges of the visible cell area, for smoother scrolling.

      Size is in pixels, the default is 200.

      Returns:
      The current row buffer size
    • setRowBufferSize

      public void setRowBufferSize(int rowBufferInPixels)
      Sets the row buffer size. Comes into effect the next time sheet is scrolled or reloaded.

      The row buffer size determines the amount of content rendered outside the top and bottom edges of the visible cell area, for smoother scrolling.

      Parameters:
      rowBufferInPixels - The amount of extra content rendered outside the top and bottom edges of the visible area.
    • getColBufferSize

      public int getColBufferSize()
      The column buffer size determines the amount of content rendered outside the left and right edges of the visible cell area, for smoother scrolling.

      Size is in pixels, the default is 200.

      Returns:
      The current column buffer size
    • setColBufferSize

      public void setColBufferSize(int colBufferInPixels)
      Sets the column buffer size. Comes into effect the next time sheet is scrolled or reloaded.

      The column buffer size determines the amount of content rendered outside the left and right edges of the visible cell area, for smoother scrolling.

      Parameters:
      colBufferInPixels - The amount of extra content rendered outside the left and right edges of the visible area.
    • getDefaultRowCount

      public int getDefaultRowCount()
      Gets the default row count for new sheets.
      Returns:
      The default row count for new sheets.
    • setDefaultRowCount

      public void setDefaultRowCount(int defaultRowCount)
      Sets the default row count for new sheets.
      Parameters:
      defaultRowCount - The number of rows to give sheets that are created with the '+' button on the client side.
    • getDefaultColumnCount

      public int getDefaultColumnCount()
      Gets the default column count for new sheets.
      Returns:
      The default column count for new sheets.
    • setDefaultColumnCount

      public void setDefaultColumnCount(int defaultColumnCount)
      Sets the default column count for new sheets.
      Parameters:
      defaultColumnCount - The number of columns to give sheets that are created with the '+' button on the client side.
    • reloadVisibleCellContents

      public void reloadVisibleCellContents()
      Call this to force the spreadsheet to reload the currently viewed cell contents. This forces reload of all: custom components (always visible and editors) from SpreadsheetComponentFactory, hyperlinks, cells' comments and cells' contents. Also updates styles for the visible area.
    • setResource

      protected void setResource(String key, com.vaadin.flow.server.streams.DownloadHandler resource)
    • createConditionalFormatter

      protected ConditionalFormatter createConditionalFormatter()
      Override this method to provide your own ConditionalFormatter implementation. This method is called each time we open a workbook.
      Returns:
      A ConditionalFormatter that is tied to this spreadsheet.
    • createSpreadsheetStyleFactory

      protected SpreadsheetStyleFactory createSpreadsheetStyleFactory()
      Override this method to provide your own SpreadsheetStyleFactory implementation. This method is called each time we open a workbook.
      Returns:
      A SpreadsheetStyleFactory that is tied to this Spreadsheet.
    • reloadActiveSheetData

      protected void reloadActiveSheetData()
      Clears and reloads all data related to the currently active sheet.
    • loadCustomEditorOnSelectedCell

      protected void loadCustomEditorOnSelectedCell()
      This method should be always called when the selected cell has changed so proper actions can be triggered for possible custom component inside the cell.
    • getVisibleSheetPOIIndex

      public int getVisibleSheetPOIIndex(int visibleSheetIndex)
      Returns POI model based index for the given Spreadsheet sheet index.
      Parameters:
      visibleSheetIndex - Index of the sheet within this Spreadsheet, 0-based
      Returns:
      Index of the sheet within the POI model, or -1 if something went wrong. 0-based.
    • isSheetProtected

      public boolean isSheetProtected(int poiSheetIndex)
      Gets the protection state of the sheet at the given POI index.
      Parameters:
      poiSheetIndex - Index of the target sheet within the POI model, 0-based
      Returns:
      true if the target Sheet is protected, false otherwise.
    • isActiveSheetProtected

      public boolean isActiveSheetProtected()
      Gets the protection state of the current sheet.
      Returns:
      true if the current Sheet is protected, false otherwise.
    • isCellHidden

      public boolean isCellHidden(org.apache.poi.ss.usermodel.Cell cell)
      Gets the visibility state of the given cell.
      Parameters:
      cell - The cell to check
      Returns:
      true if the cell is hidden, false otherwise
    • isCellLocked

      public boolean isCellLocked(org.apache.poi.ss.util.CellAddress cellAddress)
      Returns whether or not the cell at the given address in the active sheet is locked.
      Parameters:
      cellAddress - The address of the cell to check
      Returns:
      true if the cell is locked, false otherwise
    • getRpcProxy

      protected SpreadsheetClientRpc getRpcProxy()
      Gets the RPC proxy for communication to the client side.
      Returns:
      Client RPC proxy instance
    • getSpreadsheetStyleFactory

      public SpreadsheetStyleFactory getSpreadsheetStyleFactory()
      Gets the currently used style factory for this Spreadsheet.
      Returns:
      The current style factory.
    • getWorkbook

      public org.apache.poi.ss.usermodel.Workbook getWorkbook()
      Note that modifications done directly with the POI Workbook API will not get automatically updated into the Spreadsheet component.

      Use markCellAsDeleted(Cell, boolean), markCellAsUpdated(Cell, boolean), or reloadVisibleCellContents() to update content.

      Returns:
      The currently presented workbook
    • setWorkbook

      public void setWorkbook(org.apache.poi.ss.usermodel.Workbook workbook)
      Reloads the component with the given Workbook.
      Parameters:
      workbook - New workbook to load
    • getActiveSheet

      public org.apache.poi.ss.usermodel.Sheet getActiveSheet()
      Note that modifications done directly with the POI Sheet API will not get automatically updated into the Spreadsheet component.

      Use markCellAsDeleted(Cell, boolean), markCellAsUpdated(Cell, boolean), or reloadVisibleCellContents() to update content.

      Returns:
      The currently active (= visible) sheet
    • loadCells

      protected void loadCells(int firstRow, int firstColumn, int lastRow, int lastColumn)
      Sends data of the given cell area to client side. Data is only sent once, unless there are changes. Cells with custom components are skipped.
      Parameters:
      firstRow - Index of the starting row, 1-based
      firstColumn - Index of the starting column, 1-based
      lastRow - Index of the ending row, 1-based
      lastColumn - Index of the ending column, 1-based
    • setRowHeight

      public void setRowHeight(int index, float height)
      Sets the row height for currently active sheet. Updates both POI model and the visible sheet.
      Parameters:
      index - Index of target row, 0-based
      height - New row height in points
    • setColumnWidth

      public void setColumnWidth(int index, int width)
      Sets the column width in pixels (using conversion) for the currently active sheet. Updates both POI model and the visible sheet.
      Parameters:
      index - Index of target column, 0-based
      width - New column width in pixels
    • setSpreadsheetComponentFactory

      public void setSpreadsheetComponentFactory(SpreadsheetComponentFactory customComponentFactory)
      Set a new component factory for this Spreadsheet. If a Workbook has been set, all components will be reloaded.
      Parameters:
      customComponentFactory - The new component factory to use.
    • setPopup

      public void setPopup(String cellAddress, PopupButton popupButton)
      Sets a pop-up button to the given cell in the currently active sheet. If there is already a pop-up button in the given cell, it will be replaced.

      Note that if the active sheet is changed, all pop-up buttons are removed from the spreadsheet.

      Parameters:
      cellAddress - address to the target cell, e.g. "C3"
      popupButton - PopupButton to set for the target cell. Passing null here removes the pop-up button for the target cell.
    • setPopup

      public void setPopup(int row, int col, PopupButton popupButton)
      Sets a pop-up button to the given cell in the currently active sheet. If there is already a pop-up button in the given cell, it will be replaced.

      Note that if the active sheet is changed, all pop-up buttons are removed from the spreadsheet.

      Parameters:
      row - Row index of target cell, 0-based
      col - Column index of target cell, 0-based
      popupButton - PopupButton to set for the target cell. Passing null here removes the pop-up button for the target cell.
    • setPopup

      public void setPopup(org.apache.poi.ss.util.CellReference cellReference, PopupButton popupButton)
      Sets a pop-up button to the given cell in the currently active sheet. If there is already a pop-up button in the given cell, it will be replaced.

      Note that if the active sheet is changed, all pop-up buttons are removed from the spreadsheet.

      Parameters:
      cellReference - Reference to the target cell
      popupButton - PopupButton to set for the target cell. Passing null here removes the pop-up button for the target cell.
    • registerTable

      public void registerTable(SpreadsheetTable table)
      Registers the given table to this Spreadsheet, meaning that this table will be reloaded when the active sheet changes to the sheet containing the table.

      Populating the table content (pop-up button and other content) is the responsibility of the table, with SpreadsheetTable.reload().

      When the sheet is changed to a different sheet than the one that the table belongs to, the table contents are cleared with SpreadsheetTable.clear(). If the table is a filtering table, the filters are NOT cleared (can be done with SpreadsheetFilterTable.clearAllFilters().

      The pop-up buttons are always removed by the spreadsheet when the sheet changes.

      Parameters:
      table - The table to register
    • unregisterTable

      public void unregisterTable(SpreadsheetTable table)
      Unregisters the given table from this Spreadsheet - it will no longer get reloaded when the sheet is changed back to the sheet containing the table. This does not delete any table content, use deleteTable(SpreadsheetTable) to completely remove the table.

      See registerTable(SpreadsheetTable).

      Parameters:
      table - The table to unregister
    • deleteTable

      public void deleteTable(SpreadsheetTable table)
      Deletes the given table: removes it from "memory" (see registerTable(SpreadsheetTable)), clears and removes all possible filters (if table is a SpreadsheetFilterTable), and clears all table pop-up buttons and content.
      Parameters:
      table - The table to delete
    • getTables

      public HashSet<SpreadsheetTable> getTables()
      Gets all the tables that have been registered to this Spreadsheet. See registerTable(SpreadsheetTable).
      Returns:
      All tables for this spreadsheet
    • getTablesForActiveSheet

      public List<SpreadsheetTable> getTablesForActiveSheet()
      Gets the tables that belong to the currently active sheet ( getActiveSheet()). See registerTable(SpreadsheetTable).
      Returns:
      All tables for the currently active sheet
    • getCellValue

      public final String getCellValue(org.apache.poi.ss.usermodel.Cell cell)
      Returns the formatted value for the given cell, using the DataFormatter with the current locale. See DataFormatter.formatCellValue(Cell, FormulaEvaluator, ConditionalFormattingEvaluator).
      Parameters:
      cell - Cell to get the value from
      Returns:
      Formatted value
    • isGridlinesVisible

      public boolean isGridlinesVisible()
      Gets grid line visibility for the currently active sheet.
      Returns:
      True if grid lines are visible, false if they are hidden
    • setGridlinesVisible

      public void setGridlinesVisible(boolean visible)
      Sets grid line visibility for the currently active sheet.
      Parameters:
      visible - True to show grid lines, false to hide them
    • isRowColHeadingsVisible

      public boolean isRowColHeadingsVisible()
      Gets row and column heading visibility for the currently active sheet.
      Returns:
      true if headings are visible, false if they are hidden
    • setRowColHeadingsVisible

      public void setRowColHeadingsVisible(boolean visible)
      Sets row and column heading visibility for the currently active sheet.
      Parameters:
      visible - true to show headings, false to hide them
    • addSelectionChangeListener

      public com.vaadin.flow.shared.Registration addSelectionChangeListener(Spreadsheet.SelectionChangeListener listener)
      Adds the given SelectionChangeListener to this Spreadsheet.
      Parameters:
      listener - Listener to add.
      Returns:
      a Registration for removing the event listener
    • addCellValueChangeListener

      public com.vaadin.flow.shared.Registration addCellValueChangeListener(Spreadsheet.CellValueChangeListener listener)
      Adds the given CellValueChangeListener to this Spreadsheet.
      Parameters:
      listener - Listener to add.
      Returns:
      a Registration for removing the event listener
    • addFormulaValueChangeListener

      public com.vaadin.flow.shared.Registration addFormulaValueChangeListener(Spreadsheet.FormulaValueChangeListener listener)
      Adds the given FormulaValueChangeListener to this Spreadsheet.
      Parameters:
      listener - Listener to add.
      Returns:
      a Registration for removing the event listener
    • addProtectedEditListener

      public com.vaadin.flow.shared.Registration addProtectedEditListener(Spreadsheet.ProtectedEditListener listener)
      Add listener for when an attempt to modify a locked cell has been made.
      Parameters:
      listener - The listener to add.
      Returns:
      a Registration for removing the event listener
    • createFreezePane

      public void createFreezePane(int rowSplit, int colSplit)
      Creates or removes a freeze pane from the currently active sheet. If both colSplit and rowSplit are zero then the existing freeze pane is removed.
      Parameters:
      rowSplit - Vertical position of the split, 1-based row index
      colSplit - Horizontal position of the split, 1-based column index
    • removeFreezePane

      public void removeFreezePane()
      Removes the freeze pane from the currently active sheet if one is present.
    • getSelectedCellReference

      public org.apache.poi.ss.util.CellReference getSelectedCellReference()
      Gets a reference to the current single selected cell.
      Returns:
      Reference to the currently selected single cell.

      NOTE: other cells might also be selected: use addSelectionChangeListener(SelectionChangeListener) to get notified for all selection changes or call getSelectedCellReferences().

    • getSelectedCellReferences

      public Set<org.apache.poi.ss.util.CellReference> getSelectedCellReferences()
      Gets all the currently selected cells.
      Returns:
      References to all currently selected cells.
    • addSheetChangeListener

      public com.vaadin.flow.shared.Registration addSheetChangeListener(Spreadsheet.SheetChangeListener listener)
      Adds the given SheetChangeListener to this Spreadsheet.
      Parameters:
      listener - Listener to add
      Returns:
      a Registration for removing the event listener
    • onConnectorInit

      protected void onConnectorInit()
      This is called when the client-side connector has been initialized.
    • reload

      public void reload()
      Reloads all data from the current spreadsheet and performs a full re-render.

      Functionally same as calling setWorkbook(Workbook) with getWorkbook() parameter.

    • setStatusLabelValue

      public void setStatusLabelValue(String value)
      Sets the content of the status label.
      Parameters:
      value - The new content. Can not be HTML.
    • getStatusLabelValue

      public String getStatusLabelValue()
      Gets the content of the status label
      Returns:
      Current content of the status label.
    • setSelection

      public void setSelection(int row, int col)
      Selects the cell at the given coordinates
      Parameters:
      row - Row index, 0-based
      col - Column index, 0-based
    • setSelectionRange

      public void setSelectionRange(int row1, int col1, int row2, int col2)
      Selects the given range, using the cell at row1 and col1 as an anchor.
      Parameters:
      row1 - Index of the first row of the area, 0-based
      col1 - Index of the first column of the area, 0-based
      row2 - Index of the last row of the area, 0-based
      col2 - Index of the last column of the area, 0-based
    • setSelection

      public void setSelection(String selectionRange)
      Selects the cell(s) at the given coordinates Coordinates can be simple "A1" style addresses or ranges, named ranges, or a formula. Note that scatter charts, if present, use formulas that may contain named ranges.
      Parameters:
      selectionRange - The wanted range, e.g. "A3" or "B3:C5"
    • getConditionalFormatter

      public ConditionalFormatter getConditionalFormatter()
      Gets the ConditionalFormatter
      Returns:
      the ConditionalFormatter used by this Spreadsheet
    • reset

      public void reset()
      Disposes the current Workbook, if any, and loads a new empty XSLX Workbook. Note: Discards all data. Be sure to write out the old Workbook if needed.
    • getDefaultPercentageFormat

      public String getDefaultPercentageFormat()
      Returns the formatting string that is used when a user enters percentages into the Spreadsheet.

      Default is "0.00%".

      Returns:
      The formatting applied to percentage values when entered by the user
    • setDefaultPercentageFormat

      public void setDefaultPercentageFormat(String defaultPercentageFormat)
      Sets the formatting string that is used when a user enters percentages into the Spreadsheet.

      Default is "0.00%".

    • setCommentAuthorProvider

      public void setCommentAuthorProvider(Spreadsheet.CommentAuthorProvider commentAuthorProvider)
      Sets the given CommentAuthorProvider to this Spreadsheet.
      Parameters:
      commentAuthorProvider - New provider
    • getCommentAuthorProvider

      public Spreadsheet.CommentAuthorProvider getCommentAuthorProvider()
      Gets the CommentAuthorProvider currently set to this Spreadsheet.
      Returns:
      Current provider or null if not set.
    • editCellComment

      public void editCellComment(org.apache.poi.ss.util.CellReference cr)
      Triggers editing of the cell comment in the given cell reference. Note that the cell must have a previously set cell comment in order to be able to edit it.
      Parameters:
      cr - Reference to the cell containing the comment to edit
    • setFunctionBarVisible

      public void setFunctionBarVisible(boolean functionBarVisible)
      Sets the visibility of the top function bar. By default the bar is visible.
      Parameters:
      functionBarVisible - True to show the top bar, false to hide it.
    • isFunctionBarVisible

      public boolean isFunctionBarVisible()
      Gets the visibility of the top function bar. By default the bar is visible.
      Returns:
      True if the function bar is visible, false otherwise.
    • setSheetSelectionBarVisible

      public void setSheetSelectionBarVisible(boolean sheetSelectionBarVisible)
      Sets the visibility of the bottom sheet selection bar. By default the bar is visible.
      Parameters:
      sheetSelectionBarVisible - True to show the sheet selection bar, false to hide it.
    • isSheetSelectionBarVisible

      public boolean isSheetSelectionBarVisible()
      Gets the visibility of the bottom sheet selection bar. By default the bar is visible.
      Returns:
      True if the sheet selection bar is visible, false otherwise.
    • setReportStyle

      public void setReportStyle(boolean reportStyle)
      Enables or disables the report style. When enabled, the top and bottom bars of Spreadsheet will be hidden.
      Parameters:
      reportStyle - True to hide both toolbars, false to show them.
    • isReportStyle

      public boolean isReportStyle()
      Gets the state of the report style.
      Returns:
      True if report style is enabled, false otherwise.
    • setInvalidFormulaErrorMessage

      public void setInvalidFormulaErrorMessage(String invalidFormulaErrorMessage)
    • setGroupingCollapsed

      protected void setGroupingCollapsed(boolean isCols, int index, boolean collapsed)
      Controls if a column group is collapsed or not.
      Parameters:
      isCols - true when collapsing columns, false when collapsing rows
      index - A column that is part of the group, 0-based
      collapsed - If the group should be collapsed or not
    • levelHeaderClicked

      protected void levelHeaderClicked(boolean isCols, int level)
      Called when a grouping level header is clicked
      Parameters:
      isCols - true if the user clicked on cols, false for row level headers
      level - which level the user clicked
    • addSheetOverlay

      public void addSheetOverlay(SheetOverlayWrapper image)
    • getMinimumRowHeightForComponents

      public int getMinimumRowHeightForComponents()
      Get the minimum row heigth in points for the rows that contain custom components
      Returns:
      the minimum row heigths in points
    • setMinimumRowHeightForComponents

      public void setMinimumRowHeightForComponents(int minimumRowHeightForComponents)
      Set the minimum row heigth in points for the rows that contain custom components. If set to a small value, it might cause some components like checkboxes to be cut off
      Parameters:
      minimumRowHeightForComponents - the minimum row height in points
    • onRowHeaderDoubleClick

      protected void onRowHeaderDoubleClick(int rowIndex)
      This method is called when rowIndex auto-fit has been initiated from the browser by double-clicking the border of the target rowIndex header.
      Parameters:
      rowIndex - Index of the target rowIndex, 0-based
    • addRowHeaderDoubleClickListener

      public com.vaadin.flow.shared.Registration addRowHeaderDoubleClickListener(Spreadsheet.RowHeaderDoubleClickListener listener)
      Parameters:
      listener - The listener to add
      Returns:
      a Registration for removing the event listener
    • setTheme

      public void setTheme(Spreadsheet.SpreadsheetTheme theme)
      Define the theme of the Spreadsheet.
      Parameters:
      theme - SpreadsheetTheme