Class 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
- Author:
- Vaadin Ltd.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn interface for handling cell deletion from user input.static classThis event is fired when cell value changes.static interfaceUsed for knowing when a user has changed the cell value in Spreadsheet UI.static interfaceAn interface for handling the edited cell value from user input.static interfaceThis interface can be implemented to provide the comment author name set to new comments in cells.static classThis event is fired when the value of a cell referenced by a formula cell changes making the formula value changestatic interfaceUsed for knowing when a cell referenced by a formula cell has changed in the Spreadsheet UI making the formula value changestatic interfaceAn interface for handling clicks on cells that contain a hyperlink.static classAn event that is fired when an attempt to modify a locked cell has been made.static interfaceA listener for when an attempt to modify a locked cell has been made.static classThis event is fired when the border of a row header is double clickedstatic interfaceInterface for listening aSpreadsheet.RowHeaderDoubleClickEventeventstatic classThis event is fired when cell selection changes.static interfaceUsed for knowing when a user has changed the cell selection in any way.static classAn event that is fired to registered listeners when the selected sheet has been changed.static interfaceA listener for when a sheet is selected.static classstatic enumThemes for the Spreadsheet.static classThis is a parent class for a value change events. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThis is a style which hides the top (address and formula) bar.static final StringThis is a style which hides the bottom (sheet selection) bar.protected Stringprotected final MergedRegionUtil.MergedRegionContainerContainer for merged regions for the currently active sheet.protected int -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new Spreadsheet component using the newer Excel version formatXSSFWorkbook.Spreadsheet(int defaultRowCount, int defaultColumnCount) Creates a new Spreadsheet component using the newer Excel version formatXSSFWorkbook.Spreadsheet(File file) Creates a new Spreadsheet component and loads the given Excel file.Spreadsheet(InputStream inputStream) Creates a new Spreadsheet component based on the given input stream.Spreadsheet(org.apache.poi.ss.usermodel.Workbook workbook) Creates a new Spreadsheet component and loads the given Workbook. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddActionHandler(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.com.vaadin.flow.shared.RegistrationAdds the given CellValueChangeListener to this Spreadsheet.com.vaadin.flow.shared.RegistrationAdds the given FormulaValueChangeListener to this Spreadsheet.voidaddMergedRegion(int row1, int col1, int row2, int col2) Merge cells.voidaddMergedRegion(String selectionRange) Merges cells.voidaddMergedRegion(org.apache.poi.ss.util.CellRangeAddress region) Merges the given cells.com.vaadin.flow.shared.RegistrationAdd listener for when an attempt to modify a locked cell has been made.com.vaadin.flow.shared.Registrationadds aSpreadsheet.RowHeaderDoubleClickListenerto the Spreadsheetcom.vaadin.flow.shared.RegistrationAdds the given SelectionChangeListener to this Spreadsheet.com.vaadin.flow.shared.RegistrationAdds the given SheetChangeListener to this Spreadsheet.voidvoidautofitColumn(int columnIndex) Sets the column to automatically adjust the column width to fit the largest cell content within the column.org.apache.poi.ss.usermodel.CellcreateCell(int row, int col, Object value) Create a new cell (or replace existing) with the given value, the type of the value parameter will define the type of the cell.protected CellValueManagerOverride if there are desired changes or temporary bug fixes, but be careful - this class should cache values for performance.protected ConditionalFormatterOverride this method to provide your ownConditionalFormatterimplementation.protected org.apache.poi.ss.util.CellRangeAddresscreateCorrectCellRangeAddress(int row1, int col1, int row2, int col2) Creates a CellRangeAddress from the given start and end coordinates.protected org.apache.poi.ss.util.CellRangeAddresscreateCorrectCellRangeAddress(String addressString) Creates a CellRangeAddress from the given cell address string.protected SpreadsheetHandlerImplCreate the default Spreadsheet handler.org.apache.poi.ss.usermodel.CellcreateFormulaCell(int row, int col, String formula) Creates a new Formula type cell with the given formula.voidcreateFreezePane(int rowSplit, int colSplit) Creates or removes a freeze pane from the currently active sheet.voidcreateNewSheet(String sheetName, int rows, int columns) Creates a new sheet as the last sheet and sets it as the active sheet.protected SpreadsheetStyleFactoryOverride this method to provide your ownSpreadsheetStyleFactoryimplementation.protected voidImplement this to perform custom initialization in subclasses.voiddeleteCell(int row, int col) Deletes the cell from the sheet and the underlying POI model as well.voiddeleteRows(int startRow, int endRow) Deletes rows.voiddeleteSheet(int sheetIndex) Deletes the sheet at the given index.voiddeleteSheetWithPOIIndex(int poiSheetIndex) Deletes the sheet with the given POI model index.voiddeleteTable(SpreadsheetTable table) Deletes the given table: removes it from "memory" (seeregisterTable(SpreadsheetTable)), clears and removes all possible filters (if table is aSpreadsheetFilterTable), and clears all table pop-up buttons and content.voideditCellComment(org.apache.poi.ss.util.CellReference cr) Triggers editing of the cell comment in the given cell reference.protected voidfireEvent(com.vaadin.flow.component.ComponentEvent event) org.apache.poi.ss.usermodel.SheetNote that modifications done directly with the POISheetAPI will not get automatically updated into the Spreadsheet component.intReturns the index of the currently active sheet among the visible sheets ( hidden or very hidden sheets not included).intReturns the POI model index of the currently active sheet (index among all sheets including hidden and very hidden sheets).org.apache.poi.ss.usermodel.CellgetCell(int row, int col) Returns the Cell at the given coordinates.org.apache.poi.ss.usermodel.CellgetCell(int row, int col, org.apache.poi.ss.usermodel.Sheet sheet) Returns the Cell at the given coordinates.org.apache.poi.ss.usermodel.CellReturns the Cell at the given address.org.apache.poi.ss.usermodel.CellReturns the Cell at the given coordinates.org.apache.poi.ss.usermodel.CellgetCell(org.apache.poi.ss.util.CellReference cellReference) Returns the Cell corresponding to the given reference.org.apache.poi.ss.usermodel.CellgetCell(org.apache.poi.ss.util.CellReference cellReference, org.apache.poi.ss.usermodel.Sheet sheet) Returns the Cell corresponding to the given reference.Gets the CellSelectionManager for this Spreadsheet.protected CellSelectionShifterGets the CellShifter for this Spreadsheet.final StringgetCellValue(org.apache.poi.ss.usermodel.Cell cell) Returns the formatted value for the given cell, using theDataFormatterwith the current locale.Gets the CellValueManager for this Spreadsheet.intThe column buffer size determines the amount of content rendered outside the left and right edges of the visible cell area, for smoother scrolling.intGet the number of columns in the currently active sheet, or ifsetMaxColumns(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).Gets the CommentAuthorProvider currently set to this Spreadsheet.Gets the ConditionalFormatterorg.apache.poi.ss.formula.ConditionalFormattingEvaluatorPOI, as of 4.0.0, now accepts this as an argument to formula evaluation.Gets the ContextMenuManager for this Spreadsheet.org.apache.poi.ss.usermodel.DataFormatterGets the current DataFormatter.intGets the default column count for new sheets.intGets the default column width for the currently active sheet.Returns the formatting string that is used when a user enters percentages into the Spreadsheet.intGets the default row count for new sheets.floatGets the default row height in points.intReturns the first visible column in the main scroll area (NOT freeze pane)intReturns the first visible row in the scroll area (not freeze pane)org.apache.poi.ss.usermodel.FormulaEvaluatorgetId()intReturns the last visible column in the main scroll area (NOT freeze pane)intReturns the index the last frozen column (last column in left freeze pane).intReturns the index the last frozen row (last row in top freeze pane).intReturns the last visible row in the main scroll area (NOT freeze pane)Gets the Locale for this spreadsheetprotected MergedRegionUtil.MergedRegionContainerGets the MergedRegionContainer for this Spreadsheet.intGet the minimum row heigth in points for the rows that contain custom componentsintReturns the total number of sheets in the workbook (includes hidden and very hidden sheets).intReturns the number of currently visible sheets in the component.intThe row buffer size determines the amount of content rendered outside the top and bottom edges of the visible cell area, for smoother scrolling.intgetRows()Get the number of rows in the currently active sheet, or ifsetMaxRows(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).protected SpreadsheetClientRpcGets the RPC proxy for communication to the client side.org.apache.poi.ss.util.CellReferenceGets a reference to the current single selected cell.Set<org.apache.poi.ss.util.CellReference>Gets all the currently selected cells.Gets the SpreadsheetHistoryManager for this Spreadsheet.Gets the currently used style factory for this Spreadsheet.Gets the content of the status labelGets all the tables that have been registered to this Spreadsheet.Gets the tables that belong to the currently active sheet (getActiveSheet()).String[]Returns an array containing the names of the currently visible sheets.intgetVisibleSheetPOIIndex(int visibleSheetIndex) Returns POI model based index for the given Spreadsheet sheet index.org.apache.poi.ss.usermodel.WorkbookNote that modifications done directly with the POIWorkbookAPI will not get automatically updated into the Spreadsheet component.booleanGets the protection state of the current sheet.booleanisCellHidden(org.apache.poi.ss.usermodel.Cell cell) Gets the visibility state of the given cell.booleanisCellLocked(org.apache.poi.ss.util.CellAddress cellAddress) Returns whether or not the cell at the given address in the active sheet is locked.booleanReturns true if embedded charts are displayedbooleanisColumnHidden(int columnIndex) Gets the visibility state of the given column.booleanGets the visibility of the top function bar.booleanGets grid line visibility for the currently active sheet.protected booleanisRangeEditable(int row1, int col1, int row2, int col2) Determines if the given cell range is editable or not.protected booleanisRangeEditable(org.apache.poi.ss.util.CellRangeAddress cellRangeAddress) Tells whether the given cell range is editable or not.booleanGets the state of the report style.booleanReturns true if the component is being fully re-rendered after this round-trip (sheet change etc.)booleanGets row and column heading visibility for the currently active sheet.booleanisRowHidden(int rowIndex) Gets the visibility state of the given row.booleanisSheetProtected(int poiSheetIndex) Gets the protection state of the sheet at the given POI index.booleanGets the visibility of the bottom sheet selection bar.booleanReturns whether the custom editor is shown on focus or not.protected voidlevelHeaderClicked(boolean isCols, int level) Called when a grouping level header is clickedprotected voidloadCells(int firstRow, int firstColumn, int lastRow, int lastColumn) Sends data of the given cell area to client side.protected voidThis method should be always called when the selected cell has changed so proper actions can be triggered for possible custom component inside the cell.voidmarkCellAsDeleted(org.apache.poi.ss.usermodel.Cell cell, boolean cellStyleUpdated) Marks the cell as deleted.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) protected voidonColumnAutofit(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.protected voidThis is called when the client-side connector has been initialized.protected voidonNewSheetCreated(int scrollLeft, int scrollTop) This method is called when the creation of a new sheet has been requested.protected voidonRowHeaderDoubleClick(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.protected voidonSheetRename(int sheetIndex, String sheetName) This method is called when a request to rename a sheet has been made.protected voidonSheetScroll(int firstRow, int firstColumn, int lastRow, int lastColumn) This method is called when the sheet is scrolled.protected voidonSheetSelected(int tabIndex, int scrollLeft, int scrollTop) This method will be called when a selected sheet change is requested.voidReinitializes the component from the given Excel file.voidread(InputStream inputStream) Reinitializes the component from the given input stream.voidForces recalculation and update to the client side for values of all of the sheet's cells.voidrefreshCells(Collection<org.apache.poi.ss.usermodel.Cell> cells) Refreshes the given cell(s).voidrefreshCells(org.apache.poi.ss.usermodel.Cell... cells) Refreshes the given cell(s).voidregisterTable(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.voidreload()Reloads all data from the current spreadsheet and performs a full re-render.protected voidClears and reloads all data related to the currently active sheet.voidReloads all the styles for the currently active sheet.voidDiscards all current merged regions for the sheet and reloads them from the POI model.voidCall this to force the spreadsheet to reload the currently viewed cell contents.voidremoveActionHandler(Action.Handler actionHandler) Removes a previously registered action handler for the contents of this container.voidRemoves the spreadsheet'sSpreadsheetDefaultActionHandleradded oninit()voidRemoves the freeze pane from the currently active sheet if one is present.voidremoveMergedRegion(int index) Removes a merged region with the given index.voidreset()Disposes the currentWorkbook, if any, and loads a new empty XSLX Workbook.voidsetActiveSheetIndex(int sheetIndex) Sets the currently active sheet within the sheets that are visible.voidsetActiveSheetProtected(String password) Sets the protection enabled with the given password for the currently active sheet.voidsetActiveSheetWithPOIIndex(int sheetIndex) Sets the currently active sheet.voidsetCellDeletionHandler(Spreadsheet.CellDeletionHandler customCellDeletionHandler) Sets theSpreadsheet.CellDeletionHandlerfor this component (not workbook/sheet specific).voidsetCellValueHandler(Spreadsheet.CellValueHandler customCellValueHandler) Sets theSpreadsheet.CellValueHandlerfor this component (not workbook/sheet specific).voidsetChartsEnabled(boolean chartsEnabled) Use this method to define whether embedded charts should be displayed in the spreadsheet or not.voidsetColBufferSize(int colBufferInPixels) Sets the column buffer size.voidsetColumnHidden(int columnIndex, boolean hidden) Hides or shows the given column, seeSheet.setColumnHidden(int, boolean).voidsetColumnWidth(int index, int width) Sets the column width in pixels (using conversion) for the currently active sheet.voidsetCommentAuthorProvider(Spreadsheet.CommentAuthorProvider commentAuthorProvider) Sets the given CommentAuthorProvider to this Spreadsheet.voidsetDefaultColumnCount(int defaultColumnCount) Sets the default column count for new sheets.voidsetDefaultColumnWidth(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 bygetActiveSheet()andSheet.getDefaultColumnWidth().voidsetDefaultPercentageFormat(String defaultPercentageFormat) Sets the formatting string that is used when a user enters percentages into the Spreadsheet.voidsetDefaultRowCount(int defaultRowCount) Sets the default row count for new sheets.voidsetDefaultRowHeight(float heightPT) Sets the default row height in points for this Spreadsheet and the currently active sheet, returned bygetActiveSheet().voidsetFunctionBarVisible(boolean functionBarVisible) Sets the visibility of the top function bar.voidsetGridlinesVisible(boolean visible) Sets grid line visibility for the currently active sheet.protected voidsetGroupingCollapsed(boolean isCols, int index, boolean collapsed) Controls if a column group is collapsed or not.voidSets theSpreadsheet.HyperlinkCellClickHandlerfor this component (not workbook/sheet specific).voidvoidsetInvalidFormulaErrorMessage(String invalidFormulaErrorMessage) voidSet the Locale for the Spreadsheet.voidsetMaxColumns(int cols) Set the number of columns shown for the current sheet.voidsetMaxRows(int rows) Set the number of rows shown for the current sheet.voidsetMinimumRowHeightForComponents(int minimumRowHeightForComponents) Set the minimum row heigth in points for the rows that contain custom components.voidsetPopup(int row, int col, PopupButton popupButton) Sets a pop-up button to the given cell in the currently active sheet.voidsetPopup(String cellAddress, PopupButton popupButton) Sets a pop-up button to the given cell in the currently active sheet.voidsetPopup(org.apache.poi.ss.util.CellReference cellReference, PopupButton popupButton) Sets a pop-up button to the given cell in the currently active sheet.voidsetReportStyle(boolean reportStyle) Enables or disables the report style.protected voidsetResource(String key, com.vaadin.flow.server.streams.DownloadHandler resource) voidsetRowBufferSize(int rowBufferInPixels) Sets the row buffer size.voidsetRowColHeadingsVisible(boolean visible) Sets row and column heading visibility for the currently active sheet.voidsetRowHeight(int index, float height) Sets the row height for currently active sheet.voidsetRowHidden(int rowIndex, boolean hidden) Hides or shows the given row, seeRow.setZeroHeight(boolean).voidsetSelection(int row, int col) Selects the cell at the given coordinatesvoidsetSelection(String selectionRange) Selects the cell(s) at the given coordinates Coordinates can be simple "A1" style addresses or ranges, named ranges, or a formula.voidsetSelectionRange(int row1, int col1, int row2, int col2) Selects the given range, using the cell at row1 and col1 as an anchor.voidsetSheetHidden(int sheetPOIIndex, org.apache.poi.ss.usermodel.SheetVisibility visibility) SeeWorkbook.setSheetHidden(int, boolean).voidsetSheetMaxSize(int rows, int cols) DoessetMaxColumns(int)andsetMaxRows(int)in one method.voidsetSheetName(int sheetIndex, String sheetName) Sets a name for the sheet at the given visible sheet index.voidsetSheetNameWithPOIIndex(int sheetIndex, String sheetName) Sets a name for the sheet at the given POI model index.voidsetSheetProtected(int sheetPOIIndex, String password) Sets the protection enabled with the given password for the sheet at the given index.voidsetSheetSelectionBarVisible(boolean sheetSelectionBarVisible) Sets the visibility of the bottom sheet selection bar.voidsetShowCustomEditorOnFocus(boolean showCustomEditorOnFocus) Sets the visibility of the custom editor.voidsetSpreadsheetComponentFactory(SpreadsheetComponentFactory customComponentFactory) Set a new component factory for this Spreadsheet.voidsetSpreadsheetHandler(SpreadsheetHandlerImpl spreadsheetHandler) Register a Spreadsheet handler to listen to Spreadsheet Events.voidsetStatusLabelValue(String value) Sets the content of the status label.voidDefine the theme of the Spreadsheet.voidsetWorkbook(org.apache.poi.ss.usermodel.Workbook workbook) Reloads the component with the given Workbook.voidshiftRows(int startRow, int endRow, int n) Shifts rows between startRow and endRow n number of rows.voidshiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight) Shifts rows between startRow and endRow n number of rows.voidunregisterTable(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.voidwrite(OutputStream outputStream) Exports current spreadsheet as an output stream.Exports current spreadsheet into a File with the given name.Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, from, get, getChildren, getElement, getEventBus, getListeners, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Field Details
-
cellStyleToCSSStyle
-
HIDE_FUNCTION_BAR_STYLE
This is a style which hides the top (address and formula) bar.- See Also:
-
HIDE_TABSHEET_STYLE
This is a style which hides the bottom (sheet selection) bar.- See Also:
-
mergedRegionCounter
protected int mergedRegionCounter -
initialSheetSelection
-
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 formatXSSFWorkbook. Also creates one sheet using the default rowSpreadsheetFactory.DEFAULT_ROWSand columnSpreadsheetFactory.DEFAULT_COLUMNScounts. -
Spreadsheet
public Spreadsheet(int defaultRowCount, int defaultColumnCount) Creates a new Spreadsheet component using the newer Excel version formatXSSFWorkbook. 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 sheetsdefaultColumnCount- 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
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
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
- Overrides:
getIdin classcom.vaadin.flow.component.Component
-
setId
- Overrides:
setIdin classcom.vaadin.flow.component.Component
-
setSpreadsheetHandler
Register a Spreadsheet handler to listen to Spreadsheet Events. Removes the default / previously set spreadsheet handler.- Parameters:
spreadsheetHandler-
-
createDefaultHandler
Create the default Spreadsheet handler.- Returns:
- SpreadsheetHandlerImpl
-
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
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)andAction.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 latestSpreadsheet.SelectionChangeEventfor the spreadsheet. In case of a row or a column header, the first parameter (target) is aCellRangeAddress. To distinct between column / row header, you can useCellRangeAddressBase.isFullColumnRange()andCellRangeAddressBase.isFullRowRange().Similarly for
Action.Handler.handleAction(Action, Object, Object)the second parameter (sender) is always the spreadsheet component. The third parameter (target) is the latestSpreadsheet.SelectionChangeEventfor the spreadsheet, or theCellRangeAddressdefining the selected row / column header.- Specified by:
addActionHandlerin interfaceAction.Container- Parameters:
actionHandler- the new handler to be added.
-
removeDefaultActionHandler
public void removeDefaultActionHandler()Removes the spreadsheet'sSpreadsheetDefaultActionHandleradded oninit() -
removeActionHandler
Description copied from interface:Action.ContainerRemoves a previously registered action handler for the contents of this container.- Specified by:
removeActionHandlerin interfaceAction.Container- Parameters:
actionHandler- the handler to be removed.
-
setCellValueHandler
Sets theSpreadsheet.CellValueHandlerfor 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 ornullif none should be used
-
getCellValueHandler
- Returns:
- the current
Spreadsheet.CellValueHandlerfor this component ornullif none has been set
-
setCellDeletionHandler
Sets theSpreadsheet.CellDeletionHandlerfor this component (not workbook/sheet specific). It is called when a cell has been deleted by the user.- Parameters:
customCellDeletionHandler- New handler ornullif none should be used
-
getCellDeletionHandler
- Returns:
- the current
Spreadsheet.CellDeletionHandlerfor this component ornullif none has been set
-
setHyperlinkCellClickHandler
Sets theSpreadsheet.HyperlinkCellClickHandlerfor 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 ornullif none should be used- See Also:
-
getHyperlinkCellClickHandler
- Returns:
- the current
Spreadsheet.HyperlinkCellClickHandlerfor this component ornullif none has been set
-
getContextMenuManager
Gets the ContextMenuManager for this Spreadsheet. This is component (not workbook/sheet) specific.- Returns:
- The ContextMenuManager
-
getCellSelectionManager
Gets the CellSelectionManager for this Spreadsheet. This is component (not workbook/sheet) specific.- Returns:
- The CellSelectionManager
-
getCellValueManager
Gets the CellValueManager for this Spreadsheet. This is component (not workbook/sheet) specific.- Returns:
- The CellValueManager
-
getCellShifter
Gets the CellShifter for this Spreadsheet. This is component (not workbook/sheet) specific.- Returns:
- The CellShifter
-
getSpreadsheetHistoryManager
Gets the SpreadsheetHistoryManager for this Spreadsheet. This is component (not workbook/sheet) specific.- Returns:
- The SpreadsheetHistoryManager
-
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:
fireEventin classcom.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-basedfirstColumn- Index of first visible column after the scroll, 1-basedlastRow- Index of last visible row after the scroll, 1-basedlastColumn- 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-basedcol1- Index of starting column, 0-basedrow2- Index of ending row, 0-basedcol2- 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-basedcol1- Index of the starting column, 1-basedrow2- Index of the ending row, 1-basedcol2- Index of the ending column, 1-based- Returns:
- A CellRangeAddress based on the given coordinates.
-
setLocale
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
Gets the Locale for this spreadsheet- Overrides:
getLocalein classcom.vaadin.flow.component.Component- Returns:
- the locale used for spreadsheet
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
setSheetHidden
public void setSheetHidden(int sheetPOIIndex, org.apache.poi.ss.usermodel.SheetVisibility visibility) throws IllegalArgumentException SeeWorkbook.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-basedvisibility- 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
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 withgetWorkbook().- Returns:
- Names of the currently visible sheets.
-
setSheetName
Sets a name for the sheet at the given visible sheet index.- Parameters:
sheetIndex- Index of the target sheet among the visible sheets, 0-basedsheetName- 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. SeeWorkbookUtil.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-basedsheetName- 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. SeeWorkbookUtil.validateSheetName(String).
-
setSheetProtected
Sets the protection enabled with the given password for the sheet at the given index.nullpassword removes the protection.- Parameters:
sheetPOIIndex- Index of the target sheet within the POI model, 0-basedpassword- The password to set for the protection. Passnullto remove the protection.
-
setActiveSheetProtected
Sets the protection enabled with the given password for the currently active sheet.nullpassword removes the protection.- Parameters:
password- The password to set for the protection. Passnullto remove the protection.
-
createNewSheet
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 inWorkbook.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 havecolumns- Number of columns the sheet should have- Throws:
IllegalArgumentException- If the sheet name is empty or over 31 characters long or not unique.
-
deleteSheetWithPOIIndex
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 valueWorkbook.getNumberOfSheets()-1.- Throws:
IllegalArgumentException- In case there is only one visible sheet, or if the index is invalid.
-
deleteSheet
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 valuegetNumberOfVisibleSheets()-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
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
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 positionscrollTop- 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 positionscrollTop- Current vertical scroll position
-
onSheetRename
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 ifsetMaxColumns(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 ifsetMaxRows(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
Returns the Cell at the given address. If the cell is updated in outside code, callrefreshCells(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, callrefreshCells(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-basedcol- 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, callrefreshCells(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-basedcol- Column index of the cell to return, 0-basedsheet- 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, callrefreshCells(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
Returns the Cell at the given coordinates. If the cell is updated in outside code, callrefreshCells(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 nullrow- Row index of the cell to return, 0-basedcolumn- 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, callrefreshCells(Cell...)AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".- Parameters:
cellReference- Reference to the cell to returnsheet- 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-basedcol- 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
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 theWorkbookusing POI API.- Parameters:
cellStyleUpdated- True if the cell style has changedcell- The cell that has been deleted.
-
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, callrefreshCells(Cell...)orrefreshAllCellValues()to make sure client side is updated.- Parameters:
row- Row index of the new cell, 0-basedcol- Column index of the new cell, 0-basedformula- 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, usecreateFormulaCell(int, int, String). After all editing is done, callrefreshCells(Cell...)orrefreshAllCellValues()to make sure the client side is updated.- Parameters:
row- Row index of the new cell, 0-basedcol- Column index of the new cell, 0-basedvalue- 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; userefreshCells(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) DoessetMaxColumns(int)andsetMaxRows(int)in one method.- Parameters:
rows- Maximum row countcols- 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 (SheetgetDefaultColumnWidth()).- 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 bygetActiveSheet()andSheet.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 asSheet.getDefaultRowHeightInPoints()for the currently active sheetgetActiveSheet().- 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 bygetActiveSheet().- 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. SeeSheet.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()withsetMaxRows(int).See
Sheet.shiftRows(int, int, int).- Parameters:
startRow- The first row to shift, 0-basedendRow- The last row to shift, 0-basedn- 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()withsetMaxRows(int).See
Sheet.shiftRows(int, int, int, boolean, boolean).- Parameters:
startRow- The first row to shift, 0-basedendRow- The last row to shift, 0-basedn- Number of rows to shift, positive numbers shift down, negative numbers shift up.copyRowHeight- True to copy the row height during the shiftresetOriginalRowHeight- True to set the original row's height to the default
-
getFormulaEvaluator
public org.apache.poi.ss.usermodel.FormulaEvaluator getFormulaEvaluator()- Returns:
- the common
FormulaEvaluatorinstance.
-
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
ConditionalFormattingEvaluatorinstance.
-
deleteRows
public void deleteRows(int startRow, int endRow) Deletes rows. SeeSheet.removeRow(Row). Removes all row content, deletes cells and resets the sheet size. Does not shift rows up (!) - useshiftRows(int, int, int, boolean, boolean)for that.- Parameters:
startRow- Index of the starting row, 0-basedendRow- Index of the ending row, 0-based
-
addMergedRegion
Merges cells. SeeSheet.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. SeeSheet.addMergedRegion(CellRangeAddress).- Parameters:
row1- Index of the starting row of the merged region, 0-basedcol1- Index of the starting column of the merged region, 0-basedrow2- Index of the ending row of the merged region, 0-basedcol2- 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. SeeSheet.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.SelectionChangeEventis 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 withgetActiveSheet()andSheet.getMergedRegion(int)andSheet.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.SelectionChangeEventis 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, seeSheet.setColumnHidden(int, boolean).- Parameters:
columnIndex- Index of the target column, 0-basedhidden- True to hide the target column, false to show it.
-
isColumnHidden
public boolean isColumnHidden(int columnIndex) Gets the visibility state of the given column. SeeSheet.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, seeRow.setZeroHeight(boolean).- Parameters:
rowIndex- Index of the target row, 0-basedhidden- 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, seeRow.getZeroHeight().- Parameters:
rowIndex- Index of the target row, 0-based- Returns:
- true if the target row is hidden, false if it is visible.
-
read
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
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
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 originalWorkbook. - Throws:
FileNotFoundException- If file name was invalidIOException- If the file can't be written to for any reason
-
write
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) fromSpreadsheetComponentFactory, hyperlinks, cells' comments and cells' contents. Also updates styles for the visible area. -
setResource
-
createConditionalFormatter
Override this method to provide your ownConditionalFormatterimplementation. This method is called each time we open a workbook.- Returns:
- A
ConditionalFormatterthat is tied to this spreadsheet.
-
createSpreadsheetStyleFactory
Override this method to provide your ownSpreadsheetStyleFactoryimplementation. This method is called each time we open a workbook.- Returns:
- A
SpreadsheetStyleFactorythat 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
Sheetis protected, false otherwise.
-
isActiveSheetProtected
public boolean isActiveSheetProtected()Gets the protection state of the current sheet.- Returns:
- true if the current
Sheetis 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
Gets the RPC proxy for communication to the client side.- Returns:
- Client RPC proxy instance
-
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 POIWorkbookAPI will not get automatically updated into the Spreadsheet component.Use
markCellAsDeleted(Cell, boolean),markCellAsUpdated(Cell, boolean), orreloadVisibleCellContents()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 POISheetAPI will not get automatically updated into the Spreadsheet component.Use
markCellAsDeleted(Cell, boolean),markCellAsUpdated(Cell, boolean), orreloadVisibleCellContents()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-basedfirstColumn- Index of the starting column, 1-basedlastRow- Index of the ending row, 1-basedlastColumn- 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-basedheight- 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-basedwidth- New column width in pixels
-
setSpreadsheetComponentFactory
Set a new component factory for this Spreadsheet. If aWorkbookhas been set, all components will be reloaded.- Parameters:
customComponentFactory- The new component factory to use.
-
setPopup
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
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-basedcol- Column index of target cell, 0-basedpopupButton- PopupButton to set for the target cell. Passing null here removes the pop-up button for the target cell.
-
setPopup
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 cellpopupButton- PopupButton to set for the target cell. Passing null here removes the pop-up button for the target cell.
-
registerTable
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 withSpreadsheetFilterTable.clearAllFilters().The pop-up buttons are always removed by the spreadsheet when the sheet changes.
- Parameters:
table- The table to register
-
unregisterTable
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, usedeleteTable(SpreadsheetTable)to completely remove the table.- Parameters:
table- The table to unregister
-
deleteTable
Deletes the given table: removes it from "memory" (seeregisterTable(SpreadsheetTable)), clears and removes all possible filters (if table is aSpreadsheetFilterTable), and clears all table pop-up buttons and content.- Parameters:
table- The table to delete
-
getTables
Gets all the tables that have been registered to this Spreadsheet. SeeregisterTable(SpreadsheetTable).- Returns:
- All tables for this spreadsheet
-
getTablesForActiveSheet
Gets the tables that belong to the currently active sheet (getActiveSheet()). SeeregisterTable(SpreadsheetTable).- Returns:
- All tables for the currently active sheet
-
getCellValue
Returns the formatted value for the given cell, using theDataFormatterwith the current locale. SeeDataFormatter.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
Registrationfor 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
Registrationfor 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
Registrationfor 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
Registrationfor 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 indexcolSplit- 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 callgetSelectedCellReferences().
-
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
Registrationfor 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)withgetWorkbook()parameter. -
setStatusLabelValue
Sets the content of the status label.- Parameters:
value- The new content. Can not be HTML.
-
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-basedcol- 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-basedcol1- Index of the first column of the area, 0-basedrow2- Index of the last row of the area, 0-basedcol2- Index of the last column of the area, 0-based
-
setSelection
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
Gets the ConditionalFormatter- Returns:
- the
ConditionalFormatterused by thisSpreadsheet
-
reset
public void reset()Disposes the currentWorkbook, if any, and loads a new empty XSLX Workbook. Note: Discards all data. Be sure to write out the old Workbook if needed. -
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
Sets the formatting string that is used when a user enters percentages into the Spreadsheet.Default is "0.00%".
-
setCommentAuthorProvider
Sets the given CommentAuthorProvider to this Spreadsheet.- Parameters:
commentAuthorProvider- New provider
-
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
-
setGroupingCollapsed
protected void setGroupingCollapsed(boolean isCols, int index, boolean collapsed) Controls if a column group is collapsed or not.- Parameters:
isCols-truewhen collapsing columns,falsewhen collapsing rowsindex- A column that is part of the group, 0-basedcollapsed- 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 headerslevel- which level the user clicked
-
addSheetOverlay
-
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) adds aSpreadsheet.RowHeaderDoubleClickListenerto the Spreadsheet- Parameters:
listener- The listener to add- Returns:
- a
Registrationfor removing the event listener
-
setTheme
Define the theme of the Spreadsheet.- Parameters:
theme- SpreadsheetTheme
-