Class Spreadsheet
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.spreadsheet.Spreadsheet
-
- All Implemented Interfaces:
AttachNotifier,BlurNotifier,DetachNotifier,Focusable,FocusNotifier,HasComponents,HasElement,HasEnabled,HasSize,HasStyle,Action.Container,Serializable
@Tag("vaadin-spreadsheet") @JsModule("./vaadin-spreadsheet/vaadin-spreadsheet.js") public class Spreadsheet extends Component implements HasComponents, HasSize, HasStyle, Action.Container, Focusable
Vaadin Spreadsheet is a Vaadin Add-On 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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSpreadsheet.CellDeletionHandlerAn interface for handling cell deletion from user input.static classSpreadsheet.CellValueChangeEventThis event is fired when cell value changes.static interfaceSpreadsheet.CellValueChangeListenerUsed for knowing when a user has changed the cell value in Spreadsheet UI.static interfaceSpreadsheet.CellValueHandlerAn interface for handling the edited cell value from user input.static interfaceSpreadsheet.CommentAuthorProviderThis interface can be implemented to provide the comment author name set to new comments in cells.static classSpreadsheet.FormulaValueChangeEventThis event is fired when the value of a cell referenced by a formula cell changes making the formula value changestatic interfaceSpreadsheet.FormulaValueChangeListenerUsed for knowing when a cell referenced by a formula cell has changed in the Spreadsheet UI making the formula value changestatic interfaceSpreadsheet.HyperlinkCellClickHandlerAn interface for handling clicks on cells that contain a hyperlink.static classSpreadsheet.ProtectedEditEventAn event that is fired when an attempt to modify a locked cell has been made.static interfaceSpreadsheet.ProtectedEditListenerA listener for when an attempt to modify a locked cell has been made.static classSpreadsheet.RowHeaderDoubleClickEventThis event is fired when the border of a row header is double clickedstatic interfaceSpreadsheet.RowHeaderDoubleClickListenerInterface for listening aSpreadsheet.RowHeaderDoubleClickEventeventstatic classSpreadsheet.SelectionChangeEventThis event is fired when cell selection changes.static interfaceSpreadsheet.SelectionChangeListenerUsed for knowing when a user has changed the cell selection in any way.static classSpreadsheet.SheetChangeEventAn event that is fired to registered listeners when the selected sheet has been changed.static interfaceSpreadsheet.SheetChangeListenerA listener for when a sheet is selected.static classSpreadsheet.SpreadsheetEventstatic classSpreadsheet.ValueChangeEventThis is a parent class for a value change events.-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
BlurNotifier.BlurEvent<C extends Component>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
FocusNotifier.FocusEvent<C extends Component>
-
-
Field Summary
Fields Modifier and Type Field Description protected HashMap<Integer,String>cellStyleToCSSStylestatic StringHIDE_FUNCTION_BAR_STYLEThis is a style which hides the top (address and formula) bar.static StringHIDE_TABSHEET_STYLEThis is a style which hides the bottom (sheet selection) bar.protected StringinitialSheetSelectionprotected MergedRegionUtil.MergedRegionContainermergedRegionContainerContainer for merged regions for the currently active sheet.protected intmergedRegionCounterinttabIndex
-
Constructor Summary
Constructors Constructor Description Spreadsheet()Creates 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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void_setRowBufferSize(int rowBufferSize)voidaddActionHandler(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.voidaddCellValueChangeListener(Spreadsheet.CellValueChangeListener listener)Adds the given CellValueChangeListener to this Spreadsheet.voidaddFormulaValueChangeListener(Spreadsheet.FormulaValueChangeListener listener)Adds 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.voidaddProtectedEditListener(Spreadsheet.ProtectedEditListener listener)Add listener for when an attempt to modify a locked cell has been made.voidaddRowHeaderDoubleClickListener(Spreadsheet.RowHeaderDoubleClickListener listener)adds aSpreadsheet.RowHeaderDoubleClickListenerto the SpreadsheetvoidaddSelectionChangeListener(Spreadsheet.SelectionChangeListener listener)Adds the given SelectionChangeListener to this Spreadsheet.voidaddSheetChangeListener(Spreadsheet.SheetChangeListener listener)Adds the given SheetChangeListener to this Spreadsheet.voidaddSheetOverlay(SheetOverlayWrapper image)voidautofitColumn(int columnIndex)Sets the column to automatically adjust the column width to fit the largest cell content within the column.voidbeforeClientResponse(boolean initial)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 CellValueManagercreateCellValueManager()Override if there are desired changes or temporary bug fixes, but be careful - this class should cache values for performance.protected ConditionalFormattercreateConditionalFormatter()Override 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.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 SpreadsheetStyleFactorycreateSpreadsheetStyleFactory()Override this method to provide your ownSpreadsheetStyleFactoryimplementation.protected voidcustomInit()Implement 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(ComponentEvent event)Dispatches the event to all listeners registered for the event type.org.apache.poi.ss.usermodel.SheetgetActiveSheet()Note that modifications done directly with the POISheetAPI will not get automatically updated into the Spreadsheet component.intgetActiveSheetIndex()Returns the index of the currently active sheet among the visible sheets ( hidden or very hidden sheets not included).intgetActiveSheetPOIIndex()Returns the POI model index of the currently active sheet (index among all sheets including hidden and very hidden sheets).StringgetCaption()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.CellgetCell(String cellAddress)Returns the Cell at the given address.org.apache.poi.ss.usermodel.CellgetCell(String sheetName, int row, int column)Returns 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.HashMap<String,String>getCellCommentAuthors()HashMap<String,String>getCellComments()Spreadsheet.CellDeletionHandlergetCellDeletionHandler()HashMap<String,String>getCellKeysToEditorIdMap()CellSelectionManagergetCellSelectionManager()Gets the CellSelectionManager for this Spreadsheet.protected CellSelectionShiftergetCellShifter()Gets the CellShifter for this Spreadsheet.HashMap<Integer,String>getCellStyleToCSSStyle()StringgetCellValue(org.apache.poi.ss.usermodel.Cell cell)Returns the formatted value for the given cell, using theDataFormatterwith the current locale.Spreadsheet.CellValueHandlergetCellValueHandler()CellValueManagergetCellValueManager()Gets the CellValueManager for this Spreadsheet.intgetColBufferSize()The column buffer size determines the amount of content rendered outside the left and right edges of the visible cell area, for smoother scrolling.List<GroupingData>getColGroupingData()intgetColGroupingMax()intgetCols()intgetColumnBufferSize()HashMap<Integer,Integer>getColumnIndexToStyleIndex()intgetColumns()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).int[]getColW()Spreadsheet.CommentAuthorProvidergetCommentAuthorProvider()Gets the CommentAuthorProvider currently set to this Spreadsheet.HashMap<String,String>getComponentIDtoCellKeysMap()ConditionalFormattergetConditionalFormatter()Gets the ConditionalFormatterorg.apache.poi.ss.formula.ConditionalFormattingEvaluatorgetConditionalFormattingEvaluator()POI, as of 4.0.0, now accepts this as an argument to formula evaluation.HashMap<Integer,String>getConditionalFormattingStyles()ContextMenuManagergetContextMenuManager()Gets the ContextMenuManager for this Spreadsheet.org.apache.poi.ss.usermodel.DataFormattergetDataFormatter()Gets the current DataFormatter.intgetDefaultColumnCount()Gets the default column count for new sheets.intgetDefaultColumnWidth()Gets the default column width for the currently active sheet.StringgetDefaultPercentageFormat()Returns the formatting string that is used when a user enters percentages into the Spreadsheet.intgetDefaultRowCount()Gets the default row count for new sheets.floatgetDefaultRowHeight()Gets the default row height in points.intgetDefColW()floatgetDefRowH()StringgetDescription()ContentModegetDescriptionContentMode()ErrorLevelgetErrorLevel()StringgetErrorMessage()intgetFirstColumn()Returns the first visible column in the main scroll area (NOT freeze pane)intgetFirstRow()Returns the first visible row in the scroll area (not freeze pane)org.apache.poi.ss.usermodel.FormulaEvaluatorgetFormulaEvaluator()ArrayList<Integer>getHiddenColumnIndexes()ArrayList<Integer>getHiddenRowIndexes()int[]getHorizontalScrollPositions()intgetHorizontalSplitPosition()Spreadsheet.HyperlinkCellClickHandlergetHyperlinkCellClickHandler()HashMap<String,String>getHyperlinksTooltips()StringgetInfoLabelValue()Set<String>getInvalidFormulaCells()StringgetInvalidFormulaErrorMessage()intgetLastColumn()Returns the last visible column in the main scroll area (NOT freeze pane)intgetLastFrozenColumn()Returns the index the last frozen column (last column in left freeze pane).intgetLastFrozenRow()Returns the index the last frozen row (last row in top freeze pane).intgetLastRow()Returns the last visible row in the main scroll area (NOT freeze pane)LocalegetLocale()Gets the locale for this component.Set<Integer>getLockedColumnIndexes()Set<Integer>getLockedRowIndexes()protected MergedRegionUtil.MergedRegionContainergetMergedRegionContainer()Gets the MergedRegionContainer for this Spreadsheet.ArrayList<MergedRegion>getMergedRegions()intgetMinimumRowHeightForComponents()Get the minimum row heigth in points for the rows that contain custom componentsList<String>getNamedRanges()intgetNumberOfSheets()Returns the total number of sheets in the workbook (includes hidden and very hidden sheets).intgetNumberOfVisibleSheets()Returns the number of currently visible sheets in the component.HashMap<String,OverlayInfo>getOverlays()StringgetPrimaryStyleName()Set<String>getRegisteredEventListeners()Map<String,String>getResources()intgetRowBufferSize()The row buffer size determines the amount of content rendered outside the top and bottom edges of the visible cell area, for smoother scrolling.List<GroupingData>getRowGroupingData()intgetRowGroupingMax()float[]getRowH()HashMap<Integer,Integer>getRowIndexToStyleIndex()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 SpreadsheetClientRpcgetRpcProxy()Gets the RPC proxy for communication to the client side.org.apache.poi.ss.util.CellReferencegetSelectedCellReference()Gets a reference to the current single selected cell.Set<org.apache.poi.ss.util.CellReference>getSelectedCellReferences()Gets all the currently selected cells.intgetSheetIndex()String[]getSheetNames()ArrayList<String>getShiftedCellBorderStyles()SpreadsheetComponentFactorygetSpreadsheetComponentFactory()Gets the current SpreadsheetComponentFactory.SpreadsheetHistoryManagergetSpreadsheetHistoryManager()Gets the SpreadsheetHistoryManager for this Spreadsheet.SpreadsheetStyleFactorygetSpreadsheetStyleFactory()Gets the currently used style factory for this Spreadsheet.StringgetStatusLabelValue()Gets the content of the status labelList<String>getStyles()intgetTabIndex()Gets thetabindexin the component.HashSet<SpreadsheetTable>getTables()Gets all the tables that have been registered to this Spreadsheet.List<SpreadsheetTable>getTablesForActiveSheet()Gets the tables that belong to the currently active sheet (getActiveSheet()).int[]getVerticalScrollPositions()intgetVerticalSplitPosition()ArrayList<String>getVisibleCellComments()String[]getVisibleSheetNames()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.WorkbookgetWorkbook()Note that modifications done directly with the POIWorkbookAPI will not get automatically updated into the Spreadsheet component.booleanisActiveSheetProtected()Gets the protection state of the current sheet.booleanisCaptionAsHtml()booleanisCellHidden(org.apache.poi.ss.usermodel.Cell cell)Gets the visibility state of the given cell.booleanisCellLocked(org.apache.poi.ss.usermodel.Cell cell)Gets the locked state of the given cell.booleanisChartsEnabled()Returns true if embedded charts are displayedbooleanisColGroupingInversed()booleanisColumnHidden(int columnIndex)Gets the visibility state of the given column.booleanisDisplayGridlines()booleanisDisplayRowColHeadings()booleanisEnabled()Returns whether the object is enabled or disabled.booleanisFunctionBarVisible()Gets the visibility of the top function bar.booleanisGridlinesVisible()Gets grid line visibility for the currently active sheet.booleanisHasActions()booleanisLockFormatColumns()booleanisLockFormatRows()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.booleanisReload()booleanisReportStyle()Gets the state of the report style.booleanisRerenderPending()Returns true if the component is being fully re-rendered after this round-trip (sheet change etc.)booleanisRowColHeadingsVisible()Gets row and column heading visibility for the currently active sheet.booleanisRowGroupingInversed()booleanisRowHidden(int rowIndex)Gets the visibility state of the given row.booleanisSheetProtected()booleanisSheetProtected(int poiSheetIndex)Gets the protection state of the sheet at the given POI index.booleanisSheetSelectionBarVisible()Gets the visibility of the bottom sheet selection bar.booleanisWorkbookChangeToggle()booleanisWorkbookProtected()Iterator<Component>iterator()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 voidloadCustomEditorOnSelectedCell()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.voidmarkCellAsDeleted(org.apache.poi.ss.usermodel.Cell cell, boolean cellStyleUpdated)Marks the cell as deleted.protected voidonAttach(AttachEvent attachEvent)Called when the component is attached to a UI.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 voidonConnectorInit()This 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.voidread(File file)Reinitializes the component from the given Excel file.voidread(InputStream inputStream)Reinitializes the component from the given input stream.voidrefreshAllCellValues()Forces 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 voidreloadActiveSheetData()Clears and reloads all data related to the currently active sheet.voidreloadActiveSheetStyles()Reloads all the styles for the currently active sheet.voidreloadAllMergedRegions()Discards all current merged regions for the sheet and reloads them from the POI model.voidreloadVisibleCellContents()Call 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.voidremoveCellValueChangeListener(Spreadsheet.CellValueChangeListener listener)Removes the given CellValueChangeListener from this Spreadsheet.voidremoveDefaultActionHandler()Removes the spreadsheet'sSpreadsheetDefaultActionHandleradded oninit()voidremoveFreezePane()Removes the freeze pane from the currently active sheet if one is present.voidremoveMergedRegion(int index)Removes a merged region with the given index.voidremoveProtectedEditListener(Spreadsheet.ProtectedEditListener listener)Removes the given ProtectedEditListener.voidremoveSelectionChangeListener(Spreadsheet.SelectionChangeListener listener)Removes the given SelectionChangeListener from this Spreadsheet.voidremoveSheetChangeListener(Spreadsheet.SheetChangeListener listener)Removes the given SheetChangeListener from this Spreadsheet.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.voidsetCellCommentAuthors(HashMap<String,String> cellCommentAuthors)voidsetCellComments(HashMap<String,String> cellComments)voidsetCellDeletionHandler(Spreadsheet.CellDeletionHandler customCellDeletionHandler)Sets theSpreadsheet.CellDeletionHandlerfor this component (not workbook/sheet specific).voidsetCellKeysToEditorIdMap(HashMap<String,String> cellKeysToEditorIdMap)voidsetCellStyleToCSSStyle(HashMap<Integer,String> cellStyleToCSSStyle)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.voidsetColGroupingData(List<GroupingData> colGroupingData)voidsetColGroupingInversed(boolean colGroupingInversed)voidsetColGroupingMax(int colGroupingMax)voidsetCols(int cols)voidsetColumnBufferSize(int columnBufferSize)voidsetColumnHidden(int columnIndex, boolean hidden)Hides or shows the given column, seeSheet.setColumnHidden(int, boolean).voidsetColumnIndexToStyleIndex(HashMap<Integer,Integer> columnIndexToStyleIndex)voidsetColumnWidth(int index, int width)Sets the column width in pixels (using conversion) for the currently active sheet.voidsetColW(int[] colW)voidsetCommentAuthorProvider(Spreadsheet.CommentAuthorProvider commentAuthorProvider)Sets the given CommentAuthorProvider to this Spreadsheet.voidsetComponentIDtoCellKeysMap(HashMap<String,String> componentIDtoCellKeysMap)voidsetConditionalFormattingStyles(HashMap<Integer,String> conditionalFormattingStyles)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().voidsetDefColW(int defColW)voidsetDefRowH(float defRowH)voidsetDisplayGridlines(boolean displayGridlines)voidsetDisplayRowColHeadings(boolean displayRowColHeadings)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.voidsetHasActions(boolean hasActions)voidsetHeight(String height)Sets the height of the component.voidsetHiddenColumnIndexes(ArrayList<Integer> hiddenColumnIndexes)voidsetHiddenRowIndexes(ArrayList<Integer> hiddenRowIndexes)voidsetHorizontalScrollPositions(int[] horizontalScrollPositions)voidsetHorizontalSplitPosition(int horizontalSplitPosition)voidsetHyperlinkCellClickHandler(Spreadsheet.HyperlinkCellClickHandler handler)Sets theSpreadsheet.HyperlinkCellClickHandlerfor this component (not workbook/sheet specific).voidsetHyperlinksTooltips(HashMap<String,String> hyperlinksTooltips)voidsetId(String id)Sets the id of the root element of this component.voidsetInfoLabelValue(String infoLabelValue)voidsetInvalidFormulaCells(Set<String> invalidFormulaCells)voidsetInvalidFormulaErrorMessage(String invalidFormulaErrorMessage)voidsetLocale(Locale locale)voidsetLockedColumnIndexes(Set<Integer> lockedColumnIndexes)voidsetLockedRowIndexes(Set<Integer> lockedRowIndexes)voidsetLockFormatColumns(boolean lockFormatColumns)voidsetLockFormatRows(boolean lockFormatRows)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.voidsetMergedRegions(ArrayList<MergedRegion> mergedRegions)voidsetMinimumRowHeightForComponents(int minimumRowHeightForComponents)Set the minimum row heigth in points for the rows that contain custom components.voidsetNamedRanges(List<String> namedRanges)voidsetOverlays(HashMap<String,OverlayInfo> overlays)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.voidsetReload(boolean reload)voidsetReportStyle(boolean reportStyle)Enables or disables the report style.protected voidsetResource(String key, Icon icon)protected voidsetResource(String key, StreamResource resource)voidsetRowBufferSize(int rowBufferInPixels)Sets the row buffer size.voidsetRowColHeadingsVisible(boolean visible)Sets row and column heading visibility for the currently active sheet.voidsetRowGroupingData(List<GroupingData> rowGroupingData)voidsetRowGroupingInversed(boolean rowGroupingInversed)voidsetRowGroupingMax(int rowGroupingMax)voidsetRowH(float[] rowH)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).voidsetRowIndexToStyleIndex(HashMap<Integer,Integer> rowIndexToStyleIndex)voidsetRows(int rows)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, int hidden)Deprecated.voidsetSheetHidden(int sheetPOIIndex, org.apache.poi.ss.usermodel.SheetVisibility visibility)SeeWorkbook.setSheetHidden(int, boolean).voidsetSheetIndex(int sheetIndex)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.voidsetSheetNames(String[] sheetNames)voidsetSheetNameWithPOIIndex(int sheetIndex, String sheetName)Sets a name for the sheet at the given POI model index.voidsetSheetProtected(boolean sheetProtected)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.voidsetShiftedCellBorderStyles(ArrayList<String> shiftedCellBorderStyles)voidsetSpreadsheetComponentFactory(SpreadsheetComponentFactory customComponentFactory)Set a new component factory for this Spreadsheet.voidsetStatusLabelValue(String value)Sets the content of the status label.voidsetTabIndex(int tabIndex)Sets thetabindexattribute in the component.voidsetVerticalScrollPositions(int[] verticalScrollPositions)voidsetVerticalSplitPosition(int verticalSplitPosition)voidsetVisibleCellComments(ArrayList<String> visibleCellComments)voidsetWidth(String width)Sets the width of the component.voidsetWorkbook(org.apache.poi.ss.usermodel.Workbook workbook)Reloads the component with the given Workbook.voidsetWorkbookChangeToggle(boolean workbookChangeToggle)voidsetWorkbookProtected(boolean workbookProtected)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.Filewrite(String fileName)Exports current spreadsheet into a File with the given name.-
Methods inherited from class com.vaadin.flow.component.Component
addListener, from, get, getChildren, getElement, getEventBus, getId, getParent, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, scrollIntoView, set, setElement, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
Methods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus
-
Methods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListener
-
Methods inherited from interface com.vaadin.flow.component.HasComponents
add, add, addComponentAsFirst, addComponentAtIndex, remove, removeAll
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidthFull
-
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
-
-
-
Field Detail
-
tabIndex
public int tabIndex
-
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:
- Constant Field Values
-
HIDE_TABSHEET_STYLE
public static final String HIDE_TABSHEET_STYLE
This is a style which hides the bottom (sheet selection) bar.- See Also:
- Constant Field Values
-
mergedRegionCounter
protected int mergedRegionCounter
-
initialSheetSelection
protected String initialSheetSelection
-
mergedRegionContainer
protected final MergedRegionUtil.MergedRegionContainer mergedRegionContainer
Container for merged regions for the currently active sheet.
-
-
Constructor Detail
-
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
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 Detail
-
setId
public void setId(String id)
Description copied from class:ComponentSets the id of the root element of this component. The id is used with various APIs to identify the element, and it should be unique on the page.
-
setHeight
public void setHeight(String height)
Description copied from interface:HasSizeSets the height of the component.The height should be in a format understood by the browser, e.g. "100px" or "2.5em".
If the provided
heightvalue is null then height is removed.
-
setWidth
public void setWidth(String width)
Description copied from interface:HasSizeSets the width of the component.The width should be in a format understood by the browser, e.g. "100px" or "2.5em".
If the provided
widthvalue is null then width is removed.
-
getDescription
public String getDescription()
-
getDescriptionContentMode
public ContentMode getDescriptionContentMode()
-
getCaption
public String getCaption()
-
getPrimaryStyleName
public String getPrimaryStyleName()
-
getErrorMessage
public String getErrorMessage()
-
getErrorLevel
public ErrorLevel getErrorLevel()
-
isCaptionAsHtml
public boolean isCaptionAsHtml()
-
isEnabled
public boolean isEnabled()
Description copied from interface:HasEnabledReturns whether the object is enabled or disabled.Object may be enabled by itself by but if its ascendant is disabled then it's considered as (implicitly) disabled.
- Specified by:
isEnabledin interfaceHasEnabled- Returns:
- enabled state of the object
-
getColumnBufferSize
public int getColumnBufferSize()
-
getCols
public int getCols()
-
getColGroupingData
public List<GroupingData> getColGroupingData()
-
getRowGroupingData
public List<GroupingData> getRowGroupingData()
-
getColGroupingMax
public int getColGroupingMax()
-
getRowGroupingMax
public int getRowGroupingMax()
-
isColGroupingInversed
public boolean isColGroupingInversed()
-
isRowGroupingInversed
public boolean isRowGroupingInversed()
-
getDefRowH
public float getDefRowH()
-
getDefColW
public int getDefColW()
-
getRowH
public float[] getRowH()
-
getColW
public int[] getColW()
-
isReload
public boolean isReload()
-
getSheetIndex
public int getSheetIndex()
-
getSheetNames
public String[] getSheetNames()
-
getVerticalScrollPositions
public int[] getVerticalScrollPositions()
-
getHorizontalScrollPositions
public int[] getHorizontalScrollPositions()
-
isSheetProtected
public boolean isSheetProtected()
-
isWorkbookProtected
public boolean isWorkbookProtected()
-
isHasActions
public boolean isHasActions()
-
getOverlays
public HashMap<String,OverlayInfo> getOverlays()
-
getMergedRegions
public ArrayList<MergedRegion> getMergedRegions()
-
isDisplayGridlines
public boolean isDisplayGridlines()
-
isDisplayRowColHeadings
public boolean isDisplayRowColHeadings()
-
getVerticalSplitPosition
public int getVerticalSplitPosition()
-
getHorizontalSplitPosition
public int getHorizontalSplitPosition()
-
getInfoLabelValue
public String getInfoLabelValue()
-
isWorkbookChangeToggle
public boolean isWorkbookChangeToggle()
-
getInvalidFormulaErrorMessage
public String getInvalidFormulaErrorMessage()
-
isLockFormatColumns
public boolean isLockFormatColumns()
-
isLockFormatRows
public boolean isLockFormatRows()
-
_setRowBufferSize
public void _setRowBufferSize(int rowBufferSize)
-
setColumnBufferSize
public void setColumnBufferSize(int columnBufferSize)
-
setRows
public void setRows(int rows)
-
setCols
public void setCols(int cols)
-
setColGroupingData
public void setColGroupingData(List<GroupingData> colGroupingData)
-
setRowGroupingData
public void setRowGroupingData(List<GroupingData> rowGroupingData)
-
setColGroupingMax
public void setColGroupingMax(int colGroupingMax)
-
setRowGroupingMax
public void setRowGroupingMax(int rowGroupingMax)
-
setColGroupingInversed
public void setColGroupingInversed(boolean colGroupingInversed)
-
setRowGroupingInversed
public void setRowGroupingInversed(boolean rowGroupingInversed)
-
setDefRowH
public void setDefRowH(float defRowH)
-
setDefColW
public void setDefColW(int defColW)
-
setRowH
public void setRowH(float[] rowH)
-
setColW
public void setColW(int[] colW)
-
setReload
public void setReload(boolean reload)
-
setSheetIndex
public void setSheetIndex(int sheetIndex)
-
setSheetNames
public void setSheetNames(String[] sheetNames)
-
setCellStyleToCSSStyle
public void setCellStyleToCSSStyle(HashMap<Integer,String> cellStyleToCSSStyle)
-
setRowIndexToStyleIndex
public void setRowIndexToStyleIndex(HashMap<Integer,Integer> rowIndexToStyleIndex)
-
setColumnIndexToStyleIndex
public void setColumnIndexToStyleIndex(HashMap<Integer,Integer> columnIndexToStyleIndex)
-
setShiftedCellBorderStyles
public void setShiftedCellBorderStyles(ArrayList<String> shiftedCellBorderStyles)
-
setConditionalFormattingStyles
public void setConditionalFormattingStyles(HashMap<Integer,String> conditionalFormattingStyles)
-
setVerticalScrollPositions
public void setVerticalScrollPositions(int[] verticalScrollPositions)
-
setHorizontalScrollPositions
public void setHorizontalScrollPositions(int[] horizontalScrollPositions)
-
setSheetProtected
public void setSheetProtected(boolean sheetProtected)
-
setWorkbookProtected
public void setWorkbookProtected(boolean workbookProtected)
-
setCellKeysToEditorIdMap
public void setCellKeysToEditorIdMap(HashMap<String,String> cellKeysToEditorIdMap)
-
setComponentIDtoCellKeysMap
public void setComponentIDtoCellKeysMap(HashMap<String,String> componentIDtoCellKeysMap)
-
setHyperlinksTooltips
public void setHyperlinksTooltips(HashMap<String,String> hyperlinksTooltips)
-
setCellCommentAuthors
public void setCellCommentAuthors(HashMap<String,String> cellCommentAuthors)
-
setHasActions
public void setHasActions(boolean hasActions)
-
setOverlays
public void setOverlays(HashMap<String,OverlayInfo> overlays)
-
setMergedRegions
public void setMergedRegions(ArrayList<MergedRegion> mergedRegions)
-
setDisplayGridlines
public void setDisplayGridlines(boolean displayGridlines)
-
setDisplayRowColHeadings
public void setDisplayRowColHeadings(boolean displayRowColHeadings)
-
setVerticalSplitPosition
public void setVerticalSplitPosition(int verticalSplitPosition)
-
setHorizontalSplitPosition
public void setHorizontalSplitPosition(int horizontalSplitPosition)
-
setInfoLabelValue
public void setInfoLabelValue(String infoLabelValue)
-
setWorkbookChangeToggle
public void setWorkbookChangeToggle(boolean workbookChangeToggle)
-
setLockFormatColumns
public void setLockFormatColumns(boolean lockFormatColumns)
-
setLockFormatRows
public void setLockFormatRows(boolean lockFormatRows)
-
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)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
public void removeActionHandler(Action.Handler actionHandler)
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
public void setCellValueHandler(Spreadsheet.CellValueHandler customCellValueHandler)
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
public Spreadsheet.CellValueHandler getCellValueHandler()
- Returns:
- the current
Spreadsheet.CellValueHandlerfor this component ornullif none has been set
-
setCellDeletionHandler
public void setCellDeletionHandler(Spreadsheet.CellDeletionHandler customCellDeletionHandler)
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
public Spreadsheet.CellDeletionHandler getCellDeletionHandler()
- Returns:
- the current
Spreadsheet.CellDeletionHandlerfor this component ornullif none has been set
-
setHyperlinkCellClickHandler
public void setHyperlinkCellClickHandler(Spreadsheet.HyperlinkCellClickHandler handler)
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:
Spreadsheet.HyperlinkCellClickHandler,DefaultHyperlinkCellClickHandler
-
getHyperlinkCellClickHandler
public Spreadsheet.HyperlinkCellClickHandler getHyperlinkCellClickHandler()
- Returns:
- the current
Spreadsheet.HyperlinkCellClickHandlerfor this component ornullif 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(boolean)
-
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
-
fireEvent
protected void fireEvent(ComponentEvent event)
Description copied from class:ComponentDispatches the event to all listeners registered for the event type.- Overrides:
fireEventin classComponent- Parameters:
event- the event to fire- See Also:
ComponentUtil.fireEvent(Component, ComponentEvent)
-
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
public void setLocale(Locale locale)
-
onAttach
protected void onAttach(AttachEvent attachEvent)
Description copied from class:ComponentCalled when the component is attached to a UI.The default implementation does nothing.
This method is invoked before the
AttachEventis fired for the component.
-
setSheetHidden
public void setSheetHidden(int sheetPOIIndex, org.apache.poi.ss.usermodel.SheetVisibility visibility) throws IllegalArgumentExceptionSeeWorkbook.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.
-
setSheetHidden
@Deprecated public void setSheetHidden(int sheetPOIIndex, int hidden) throws IllegalArgumentException
Deprecated.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:
hidden- Visibility state to set: 0-visible, 1-hidden, 2-very hidden.sheetPOIIndex- Index of the target sheet within the POI model, 0-based- 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 withgetWorkbook().- Returns:
- Names of the currently visible sheets.
-
setSheetName
public void setSheetName(int sheetIndex, String sheetName) throws IllegalArgumentExceptionSets 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 IllegalArgumentExceptionSets 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
public void setSheetProtected(int sheetPOIIndex, String password)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
public void setActiveSheetProtected(String password)
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
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 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
public void deleteSheetWithPOIIndex(int poiSheetIndex) throws IllegalArgumentExceptionDeletes 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
public void deleteSheet(int sheetIndex) throws IllegalArgumentExceptionDeletes 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
public void setActiveSheetIndex(int sheetIndex) throws IllegalArgumentExceptionSets 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 IllegalArgumentExceptionSets 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
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 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
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, 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
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, 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
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 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 IllegalArgumentExceptionCreates 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 IllegalArgumentExceptionCreate 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.
-
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 void addRowHeaderDoubleClickListener(Spreadsheet.RowHeaderDoubleClickListener listener)
adds aSpreadsheet.RowHeaderDoubleClickListenerto the Spreadsheet- Parameters:
listener- The listener to add
-
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
public void addMergedRegion(String selectionRange)
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 IllegalArgumentExceptionMerges 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
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 originalWorkbook. - Throws:
FileNotFoundException- If file name was invalidIOException- 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) fromSpreadsheetComponentFactory, hyperlinks, cells' comments and cells' contents. Also updates styles for the visible area.
-
setResource
protected void setResource(String key, StreamResource resource)
-
createConditionalFormatter
protected ConditionalFormatter 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
protected SpreadsheetStyleFactory 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.usermodel.Cell cell)
Gets the locked state of the given cell.- Parameters:
cell- 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
-
beforeClientResponse
public void beforeClientResponse(boolean initial)
-
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 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
public void setSpreadsheetComponentFactory(SpreadsheetComponentFactory customComponentFactory)
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.
-
getSpreadsheetComponentFactory
public SpreadsheetComponentFactory getSpreadsheetComponentFactory()
Gets the current SpreadsheetComponentFactory.- Returns:
- The currently used component factory.
-
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-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
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 cellpopupButton- 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 withSpreadsheetFilterTable.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, usedeleteTable(SpreadsheetTable)to completely remove the table.- Parameters:
table- The table to unregister
-
deleteTable
public void deleteTable(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.- Parameters:
table- The table to delete
-
getTables
public HashSet<SpreadsheetTable> getTables()
Gets all the tables that have been registered to this Spreadsheet. SeeregisterTable(SpreadsheetTable).- Returns:
- All tables for this spreadsheet
-
getTablesForActiveSheet
public List<SpreadsheetTable> getTablesForActiveSheet()
Gets the tables that belong to the currently active sheet (getActiveSheet()). SeeregisterTable(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 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 void addSelectionChangeListener(Spreadsheet.SelectionChangeListener listener)
Adds the given SelectionChangeListener to this Spreadsheet.- Parameters:
listener- Listener to add.
-
addCellValueChangeListener
public void addCellValueChangeListener(Spreadsheet.CellValueChangeListener listener)
Adds the given CellValueChangeListener to this Spreadsheet.- Parameters:
listener- Listener to add.
-
addFormulaValueChangeListener
public void addFormulaValueChangeListener(Spreadsheet.FormulaValueChangeListener listener)
Adds the given FormulaValueChangeListener to this Spreadsheet.- Parameters:
listener- Listener to add.
-
removeSelectionChangeListener
public void removeSelectionChangeListener(Spreadsheet.SelectionChangeListener listener)
Removes the given SelectionChangeListener from this Spreadsheet.- Parameters:
listener- Listener to remove.
-
removeCellValueChangeListener
public void removeCellValueChangeListener(Spreadsheet.CellValueChangeListener listener)
Removes the given CellValueChangeListener from this Spreadsheet.- Parameters:
listener- Listener to remove.
-
addProtectedEditListener
public void addProtectedEditListener(Spreadsheet.ProtectedEditListener listener)
Add listener for when an attempt to modify a locked cell has been made.- Parameters:
listener- The listener to add.
-
removeProtectedEditListener
public void removeProtectedEditListener(Spreadsheet.ProtectedEditListener listener)
Removes the given ProtectedEditListener.- Parameters:
listener- The listener to remove.
-
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
public Set<org.apache.poi.ss.util.CellReference> getSelectedCellReferences()
Gets all the currently selected cells.- Returns:
- References to all currently selected cells.
-
addSheetChangeListener
public void addSheetChangeListener(Spreadsheet.SheetChangeListener listener)
Adds the given SheetChangeListener to this Spreadsheet.- Parameters:
listener- Listener to add
-
removeSheetChangeListener
public void removeSheetChangeListener(Spreadsheet.SheetChangeListener listener)
Removes the given SheetChangeListener from this Spreadsheet.- Parameters:
listener- Listener to remove
-
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
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-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
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
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
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)
-
getTabIndex
public int getTabIndex()
Description copied from interface:FocusableGets thetabindexin the component. The tabIndex indicates if its element can be focused, and if/where it participates in sequential keyboard navigation.If there's no such attribute set, it returns the default setting for the element, which depends on the element and on the browser. If the attribute cannot be parsed to
int, then anIllegalStateExceptionis thrown.- Specified by:
getTabIndexin interfaceFocusable- Returns:
- the tabindex attribute, or 0 if none
- See Also:
- tabindex at MDN
-
setTabIndex
public void setTabIndex(int tabIndex)
Description copied from interface:FocusableSets thetabindexattribute in the component. The tabIndex indicates if its element can be focused, and if/where it participates in sequential keyboard navigation:- A negative value (usually
tabindex = -1means that the component should be focusable, but should not be reachable via sequential keyboard navigation. tabindex = 0means that the component should be focusable in sequential keyboard navigation, but its order is defined by the document's source order.- A positive value means the component should be focusable in
sequential keyboard navigation, with its order defined by the value of
the number. That is,
tabindex = 4would be focused beforetabindex = 5, but aftertabindex = 3. If multiple components share the same positive tabindex value, their order relative to each other follows their position in the document source.
- Specified by:
setTabIndexin interfaceFocusable- Parameters:
tabIndex- the tabindex attribute- See Also:
- tabindex at MDN
- A negative value (usually
-
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
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
-
getLocale
public Locale getLocale()
Description copied from class:ComponentGets the locale for this component.It returns the
UIlocale if it has been set. If there is noUIlocale available then it tries to use the first locale provided by theI18NProvider. If there is no any provided locale then the default locale is used.
-
-