com.vaadin.flow.component.spreadsheet.
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:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Spreadsheet.CellDeletionHandler
An interface for handling cell deletion from user input.
static class
Spreadsheet.CellValueChangeEvent
This event is fired when cell value changes.
static interface
Spreadsheet.CellValueChangeListener
Used for knowing when a user has changed the cell value in Spreadsheet UI.
static interface
Spreadsheet.CellValueHandler
An interface for handling the edited cell value from user input.
static interface
Spreadsheet.CommentAuthorProvider
This interface can be implemented to provide the comment author name set to new comments in cells.
static class
Spreadsheet.FormulaValueChangeEvent
This event is fired when the value of a cell referenced by a formula cell changes making the formula value change
static interface
Spreadsheet.FormulaValueChangeListener
Used for knowing when a cell referenced by a formula cell has changed in the Spreadsheet UI making the formula value change
static interface
Spreadsheet.HyperlinkCellClickHandler
An interface for handling clicks on cells that contain a hyperlink.
static class
Spreadsheet.ProtectedEditEvent
An event that is fired when an attempt to modify a locked cell has been made.
static interface
Spreadsheet.ProtectedEditListener
A listener for when an attempt to modify a locked cell has been made.
static class
Spreadsheet.RowHeaderDoubleClickEvent
This event is fired when the border of a row header is double clicked
static interface
Spreadsheet.RowHeaderDoubleClickListener
Interface for listening a
Spreadsheet.RowHeaderDoubleClickEvent
eventstatic class
Spreadsheet.SelectionChangeEvent
This event is fired when cell selection changes.
static interface
Spreadsheet.SelectionChangeListener
Used for knowing when a user has changed the cell selection in any way.
static class
Spreadsheet.SheetChangeEvent
An event that is fired to registered listeners when the selected sheet has been changed.
static interface
Spreadsheet.SheetChangeListener
A listener for when a sheet is selected.
static class
Spreadsheet.SpreadsheetEvent
static class
Spreadsheet.ValueChangeEvent
This 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>
cellStyleToCSSStyle
static String
HIDE_FUNCTION_BAR_STYLE
This is a style which hides the top (address and formula) bar.
static String
HIDE_TABSHEET_STYLE
This is a style which hides the bottom (sheet selection) bar.
protected String
initialSheetSelection
protected MergedRegionUtil.MergedRegionContainer
mergedRegionContainer
Container for merged regions for the currently active sheet.
protected int
mergedRegionCounter
int
tabIndex
-
Constructor Summary
Constructors Constructor Description Spreadsheet()
Creates a new Spreadsheet component using the newer Excel version format
XSSFWorkbook
.Spreadsheet(int defaultRowCount, int defaultColumnCount)
Creates a new Spreadsheet component using the newer Excel version format
XSSFWorkbook
.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 Modifier and Type Method Description void
_setRowBufferSize(int rowBufferSize)
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.
void
addCellValueChangeListener(Spreadsheet.CellValueChangeListener listener)
Adds the given CellValueChangeListener to this Spreadsheet.
void
addFormulaValueChangeListener(Spreadsheet.FormulaValueChangeListener listener)
Adds the given FormulaValueChangeListener to this Spreadsheet.
void
addMergedRegion(int row1, int col1, int row2, int col2)
Merge cells.
void
addMergedRegion(String selectionRange)
Merges cells.
void
addMergedRegion(org.apache.poi.ss.util.CellRangeAddress region)
Merges the given cells.
void
addProtectedEditListener(Spreadsheet.ProtectedEditListener listener)
Add listener for when an attempt to modify a locked cell has been made.
void
addRowHeaderDoubleClickListener(Spreadsheet.RowHeaderDoubleClickListener listener)
adds a
Spreadsheet.RowHeaderDoubleClickListener
to the Spreadsheetvoid
addSelectionChangeListener(Spreadsheet.SelectionChangeListener listener)
Adds the given SelectionChangeListener to this Spreadsheet.
void
addSheetChangeListener(Spreadsheet.SheetChangeListener listener)
Adds the given SheetChangeListener to this Spreadsheet.
void
addSheetOverlay(SheetOverlayWrapper image)
void
autofitColumn(int columnIndex)
Sets the column to automatically adjust the column width to fit the largest cell content within the column.
void
beforeClientResponse(boolean initial)
org.apache.poi.ss.usermodel.Cell
createCell(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 CellValueManager
createCellValueManager()
Override if there are desired changes or temporary bug fixes, but be careful - this class should cache values for performance.
protected ConditionalFormatter
createConditionalFormatter()
Override this method to provide your own
ConditionalFormatter
implementation.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.
protected org.apache.poi.ss.util.CellRangeAddress
createCorrectCellRangeAddress(String addressString)
Creates a CellRangeAddress from the given cell address string.
org.apache.poi.ss.usermodel.Cell
createFormulaCell(int row, int col, String formula)
Creates a new Formula type cell with the given formula.
void
createFreezePane(int rowSplit, int colSplit)
Creates or removes a freeze pane from the currently active sheet.
void
createNewSheet(String sheetName, int rows, int columns)
Creates a new sheet as the last sheet and sets it as the active sheet.
protected SpreadsheetStyleFactory
createSpreadsheetStyleFactory()
Override this method to provide your own
SpreadsheetStyleFactory
implementation.protected void
customInit()
Implement this to perform custom initialization in subclasses.
void
deleteCell(int row, int col)
Deletes the cell from the sheet and the underlying POI model as well.
void
deleteRows(int startRow, int endRow)
Deletes rows.
void
deleteSheet(int sheetIndex)
Deletes the sheet at the given index.
void
deleteSheetWithPOIIndex(int poiSheetIndex)
Deletes the sheet with the given POI model index.
void
deleteTable(SpreadsheetTable table)
Deletes the given table: removes it from "memory" (see
registerTable(SpreadsheetTable)
), clears and removes all possible filters (if table is aSpreadsheetFilterTable
), and clears all table pop-up buttons and content.void
editCellComment(org.apache.poi.ss.util.CellReference cr)
Triggers editing of the cell comment in the given cell reference.
protected void
fireEvent(ComponentEvent event)
Dispatches the event to all listeners registered for the event type.
org.apache.poi.ss.usermodel.Sheet
getActiveSheet()
Note that modifications done directly with the POI
Sheet
API will not get automatically updated into the Spreadsheet component.int
getActiveSheetIndex()
Returns the index of the currently active sheet among the visible sheets ( hidden or very hidden sheets not included).
int
getActiveSheetPOIIndex()
Returns the POI model index of the currently active sheet (index among all sheets including hidden and very hidden sheets).
String
getCaption()
org.apache.poi.ss.usermodel.Cell
getCell(int row, int col)
Returns the Cell at the given coordinates.
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.
org.apache.poi.ss.usermodel.Cell
getCell(String cellAddress)
Returns the Cell at the given address.
org.apache.poi.ss.usermodel.Cell
getCell(String sheetName, int row, int column)
Returns the Cell at the given coordinates.
org.apache.poi.ss.usermodel.Cell
getCell(org.apache.poi.ss.util.CellReference cellReference)
Returns the Cell corresponding to the given reference.
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.
HashMap<String,String>
getCellCommentAuthors()
HashMap<String,String>
getCellComments()
Spreadsheet.CellDeletionHandler
getCellDeletionHandler()
HashMap<String,String>
getCellKeysToEditorIdMap()
CellSelectionManager
getCellSelectionManager()
Gets the CellSelectionManager for this Spreadsheet.
protected CellSelectionShifter
getCellShifter()
Gets the CellShifter for this Spreadsheet.
HashMap<Integer,String>
getCellStyleToCSSStyle()
String
getCellValue(org.apache.poi.ss.usermodel.Cell cell)
Returns the formatted value for the given cell, using the
DataFormatter
with the current locale.Spreadsheet.CellValueHandler
getCellValueHandler()
CellValueManager
getCellValueManager()
Gets the CellValueManager for this Spreadsheet.
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.
List<GroupingData>
getColGroupingData()
int
getColGroupingMax()
int
getCols()
int
getColumnBufferSize()
HashMap<Integer,Integer>
getColumnIndexToStyleIndex()
int
getColumns()
Get the number of columns in the currently active sheet, or if
setMaxColumns(int)
has been used, the current number of columns the component shows (not the amount of columns in the actual sheet in the POI model).int[]
getColW()
Spreadsheet.CommentAuthorProvider
getCommentAuthorProvider()
Gets the CommentAuthorProvider currently set to this Spreadsheet.
HashMap<String,String>
getComponentIDtoCellKeysMap()
ConditionalFormatter
getConditionalFormatter()
Gets the ConditionalFormatter
org.apache.poi.ss.formula.ConditionalFormattingEvaluator
getConditionalFormattingEvaluator()
POI, as of 4.0.0, now accepts this as an argument to formula evaluation.
HashMap<Integer,String>
getConditionalFormattingStyles()
ContextMenuManager
getContextMenuManager()
Gets the ContextMenuManager for this Spreadsheet.
org.apache.poi.ss.usermodel.DataFormatter
getDataFormatter()
Gets the current DataFormatter.
int
getDefaultColumnCount()
Gets the default column count for new sheets.
int
getDefaultColumnWidth()
Gets the default column width for the currently active sheet.
String
getDefaultPercentageFormat()
Returns the formatting string that is used when a user enters percentages into the Spreadsheet.
int
getDefaultRowCount()
Gets the default row count for new sheets.
float
getDefaultRowHeight()
Gets the default row height in points.
int
getDefColW()
float
getDefRowH()
String
getDescription()
ContentMode
getDescriptionContentMode()
ErrorLevel
getErrorLevel()
String
getErrorMessage()
int
getFirstColumn()
Returns the first visible column in the main scroll area (NOT freeze pane)
int
getFirstRow()
Returns the first visible row in the scroll area (not freeze pane)
org.apache.poi.ss.usermodel.FormulaEvaluator
getFormulaEvaluator()
ArrayList<Integer>
getHiddenColumnIndexes()
ArrayList<Integer>
getHiddenRowIndexes()
int[]
getHorizontalScrollPositions()
int
getHorizontalSplitPosition()
Spreadsheet.HyperlinkCellClickHandler
getHyperlinkCellClickHandler()
HashMap<String,String>
getHyperlinksTooltips()
String
getInfoLabelValue()
Set<String>
getInvalidFormulaCells()
String
getInvalidFormulaErrorMessage()
int
getLastColumn()
Returns the last visible column in the main scroll area (NOT freeze pane)
int
getLastFrozenColumn()
Returns the index the last frozen column (last column in left freeze pane).
int
getLastFrozenRow()
Returns the index the last frozen row (last row in top freeze pane).
int
getLastRow()
Returns the last visible row in the main scroll area (NOT freeze pane)
Locale
getLocale()
Gets the locale for this component.
Set<Integer>
getLockedColumnIndexes()
Set<Integer>
getLockedRowIndexes()
protected MergedRegionUtil.MergedRegionContainer
getMergedRegionContainer()
Gets the MergedRegionContainer for this Spreadsheet.
ArrayList<MergedRegion>
getMergedRegions()
int
getMinimumRowHeightForComponents()
Get the minimum row heigth in points for the rows that contain custom components
List<String>
getNamedRanges()
int
getNumberOfSheets()
Returns the total number of sheets in the workbook (includes hidden and very hidden sheets).
int
getNumberOfVisibleSheets()
Returns the number of currently visible sheets in the component.
HashMap<String,OverlayInfo>
getOverlays()
String
getPrimaryStyleName()
Set<String>
getRegisteredEventListeners()
Map<String,String>
getResources()
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.
List<GroupingData>
getRowGroupingData()
int
getRowGroupingMax()
float[]
getRowH()
HashMap<Integer,Integer>
getRowIndexToStyleIndex()
int
getRows()
Get the number of rows in the currently active sheet, or if
setMaxRows(int)
has been used, the current number of rows the component shows (not the amount of rows in the actual sheet in the POI model).protected SpreadsheetClientRpc
getRpcProxy()
Gets the RPC proxy for communication to the client side.
org.apache.poi.ss.util.CellReference
getSelectedCellReference()
Gets a reference to the current single selected cell.
Set<org.apache.poi.ss.util.CellReference>
getSelectedCellReferences()
Gets all the currently selected cells.
int
getSheetIndex()
String[]
getSheetNames()
ArrayList<String>
getShiftedCellBorderStyles()
SpreadsheetComponentFactory
getSpreadsheetComponentFactory()
Gets the current SpreadsheetComponentFactory.
SpreadsheetHistoryManager
getSpreadsheetHistoryManager()
Gets the SpreadsheetHistoryManager for this Spreadsheet.
SpreadsheetStyleFactory
getSpreadsheetStyleFactory()
Gets the currently used style factory for this Spreadsheet.
String
getStatusLabelValue()
Gets the content of the status label
List<String>
getStyles()
int
getTabIndex()
Gets the
tabindex
in 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()
int
getVerticalSplitPosition()
ArrayList<String>
getVisibleCellComments()
String[]
getVisibleSheetNames()
Returns an array containing the names of the currently visible sheets.
int
getVisibleSheetPOIIndex(int visibleSheetIndex)
Returns POI model based index for the given Spreadsheet sheet index.
org.apache.poi.ss.usermodel.Workbook
getWorkbook()
Note that modifications done directly with the POI
Workbook
API will not get automatically updated into the Spreadsheet component.boolean
isActiveSheetProtected()
Gets the protection state of the current sheet.
boolean
isCaptionAsHtml()
boolean
isCellHidden(org.apache.poi.ss.usermodel.Cell cell)
Gets the visibility state of the given cell.
boolean
isCellLocked(org.apache.poi.ss.usermodel.Cell cell)
Gets the locked state of the given cell.
boolean
isChartsEnabled()
Returns true if embedded charts are displayed
boolean
isColGroupingInversed()
boolean
isColumnHidden(int columnIndex)
Gets the visibility state of the given column.
boolean
isDisplayGridlines()
boolean
isDisplayRowColHeadings()
boolean
isEnabled()
Returns whether the object is enabled or disabled.
boolean
isFunctionBarVisible()
Gets the visibility of the top function bar.
boolean
isGridlinesVisible()
Gets grid line visibility for the currently active sheet.
boolean
isHasActions()
boolean
isLockFormatColumns()
boolean
isLockFormatRows()
protected boolean
isRangeEditable(int row1, int col1, int row2, int col2)
Determines if the given cell range is editable or not.
protected boolean
isRangeEditable(org.apache.poi.ss.util.CellRangeAddress cellRangeAddress)
Tells whether the given cell range is editable or not.
boolean
isReload()
boolean
isReportStyle()
Gets the state of the report style.
boolean
isRerenderPending()
Returns true if the component is being fully re-rendered after this round-trip (sheet change etc.)
boolean
isRowColHeadingsVisible()
Gets row and column heading visibility for the currently active sheet.
boolean
isRowGroupingInversed()
boolean
isRowHidden(int rowIndex)
Gets the visibility state of the given row.
boolean
isSheetProtected()
boolean
isSheetProtected(int poiSheetIndex)
Gets the protection state of the sheet at the given POI index.
boolean
isSheetSelectionBarVisible()
Gets the visibility of the bottom sheet selection bar.
boolean
isWorkbookChangeToggle()
boolean
isWorkbookProtected()
Iterator<Component>
iterator()
protected void
levelHeaderClicked(boolean isCols, int level)
Called when a grouping level header is clicked
protected void
loadCells(int firstRow, int firstColumn, int lastRow, int lastColumn)
Sends data of the given cell area to client side.
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.
void
markCellAsDeleted(org.apache.poi.ss.usermodel.Cell cell, boolean cellStyleUpdated)
Marks the cell as deleted.
protected void
onAttach(AttachEvent attachEvent)
Called when the component is attached to a UI.
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.
protected void
onConnectorInit()
This is called when the client-side connector has been initialized.
protected void
onNewSheetCreated(int scrollLeft, int scrollTop)
This method is called when the creation of a new sheet has been requested.
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.
protected void
onSheetRename(int sheetIndex, String sheetName)
This method is called when a request to rename a sheet has been made.
protected void
onSheetScroll(int firstRow, int firstColumn, int lastRow, int lastColumn)
This method is called when the sheet is scrolled.
protected void
onSheetSelected(int tabIndex, int scrollLeft, int scrollTop)
This method will be called when a selected sheet change is requested.
void
read(File file)
Reinitializes the component from the given Excel file.
void
read(InputStream inputStream)
Reinitializes the component from the given input stream.
void
refreshAllCellValues()
Forces recalculation and update to the client side for values of all of the sheet's cells.
void
refreshCells(Collection<org.apache.poi.ss.usermodel.Cell> cells)
Refreshes the given cell(s).
void
refreshCells(org.apache.poi.ss.usermodel.Cell... cells)
Refreshes the given cell(s).
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.
void
reload()
Reloads all data from the current spreadsheet and performs a full re-render.
protected void
reloadActiveSheetData()
Clears and reloads all data related to the currently active sheet.
void
reloadActiveSheetStyles()
Reloads all the styles for the currently active sheet.
void
reloadAllMergedRegions()
Discards all current merged regions for the sheet and reloads them from the POI model.
void
reloadVisibleCellContents()
Call this to force the spreadsheet to reload the currently viewed cell contents.
void
removeActionHandler(Action.Handler actionHandler)
Removes a previously registered action handler for the contents of this container.
void
removeCellValueChangeListener(Spreadsheet.CellValueChangeListener listener)
Removes the given CellValueChangeListener from this Spreadsheet.
void
removeDefaultActionHandler()
Removes the spreadsheet's
SpreadsheetDefaultActionHandler
added oninit()
void
removeFreezePane()
Removes the freeze pane from the currently active sheet if one is present.
void
removeMergedRegion(int index)
Removes a merged region with the given index.
void
removeProtectedEditListener(Spreadsheet.ProtectedEditListener listener)
Removes the given ProtectedEditListener.
void
removeSelectionChangeListener(Spreadsheet.SelectionChangeListener listener)
Removes the given SelectionChangeListener from this Spreadsheet.
void
removeSheetChangeListener(Spreadsheet.SheetChangeListener listener)
Removes the given SheetChangeListener from this Spreadsheet.
void
reset()
Disposes the current
Workbook
, if any, and loads a new empty XSLX Workbook.void
setActiveSheetIndex(int sheetIndex)
Sets the currently active sheet within the sheets that are visible.
void
setActiveSheetProtected(String password)
Sets the protection enabled with the given password for the currently active sheet.
void
setActiveSheetWithPOIIndex(int sheetIndex)
Sets the currently active sheet.
void
setCellCommentAuthors(HashMap<String,String> cellCommentAuthors)
void
setCellComments(HashMap<String,String> cellComments)
void
setCellDeletionHandler(Spreadsheet.CellDeletionHandler customCellDeletionHandler)
Sets the
Spreadsheet.CellDeletionHandler
for this component (not workbook/sheet specific).void
setCellKeysToEditorIdMap(HashMap<String,String> cellKeysToEditorIdMap)
void
setCellStyleToCSSStyle(HashMap<Integer,String> cellStyleToCSSStyle)
void
setCellValueHandler(Spreadsheet.CellValueHandler customCellValueHandler)
Sets the
Spreadsheet.CellValueHandler
for this component (not workbook/sheet specific).void
setChartsEnabled(boolean chartsEnabled)
Use this method to define whether embedded charts should be displayed in the spreadsheet or not.
void
setColBufferSize(int colBufferInPixels)
Sets the column buffer size.
void
setColGroupingData(List<GroupingData> colGroupingData)
void
setColGroupingInversed(boolean colGroupingInversed)
void
setColGroupingMax(int colGroupingMax)
void
setCols(int cols)
void
setColumnBufferSize(int columnBufferSize)
void
setColumnHidden(int columnIndex, boolean hidden)
Hides or shows the given column, see
Sheet.setColumnHidden(int, boolean)
.void
setColumnIndexToStyleIndex(HashMap<Integer,Integer> columnIndexToStyleIndex)
void
setColumnWidth(int index, int width)
Sets the column width in pixels (using conversion) for the currently active sheet.
void
setColW(int[] colW)
void
setCommentAuthorProvider(Spreadsheet.CommentAuthorProvider commentAuthorProvider)
Sets the given CommentAuthorProvider to this Spreadsheet.
void
setComponentIDtoCellKeysMap(HashMap<String,String> componentIDtoCellKeysMap)
void
setConditionalFormattingStyles(HashMap<Integer,String> conditionalFormattingStyles)
void
setDefaultColumnCount(int defaultColumnCount)
Sets the default column count for new sheets.
void
setDefaultColumnWidth(int widthPX)
Sets the default column width in pixels that the component uses, this doesn't change the default column width of the underlying sheet, returned by
getActiveSheet()
andSheet.getDefaultColumnWidth()
.void
setDefaultPercentageFormat(String defaultPercentageFormat)
Sets the formatting string that is used when a user enters percentages into the Spreadsheet.
void
setDefaultRowCount(int defaultRowCount)
Sets the default row count for new sheets.
void
setDefaultRowHeight(float heightPT)
Sets the default row height in points for this Spreadsheet and the currently active sheet, returned by
getActiveSheet()
.void
setDefColW(int defColW)
void
setDefRowH(float defRowH)
void
setDisplayGridlines(boolean displayGridlines)
void
setDisplayRowColHeadings(boolean displayRowColHeadings)
void
setFunctionBarVisible(boolean functionBarVisible)
Sets the visibility of the top function bar.
void
setGridlinesVisible(boolean visible)
Sets grid line visibility for the currently active sheet.
protected void
setGroupingCollapsed(boolean isCols, int index, boolean collapsed)
Controls if a column group is collapsed or not.
void
setHasActions(boolean hasActions)
void
setHeight(String height)
Sets the height of the component.
void
setHiddenColumnIndexes(ArrayList<Integer> hiddenColumnIndexes)
void
setHiddenRowIndexes(ArrayList<Integer> hiddenRowIndexes)
void
setHorizontalScrollPositions(int[] horizontalScrollPositions)
void
setHorizontalSplitPosition(int horizontalSplitPosition)
void
setHyperlinkCellClickHandler(Spreadsheet.HyperlinkCellClickHandler handler)
Sets the
Spreadsheet.HyperlinkCellClickHandler
for this component (not workbook/sheet specific).void
setHyperlinksTooltips(HashMap<String,String> hyperlinksTooltips)
void
setId(String id)
Sets the id of the root element of this component.
void
setInfoLabelValue(String infoLabelValue)
void
setInvalidFormulaCells(Set<String> invalidFormulaCells)
void
setInvalidFormulaErrorMessage(String invalidFormulaErrorMessage)
void
setLocale(Locale locale)
void
setLockedColumnIndexes(Set<Integer> lockedColumnIndexes)
void
setLockedRowIndexes(Set<Integer> lockedRowIndexes)
void
setLockFormatColumns(boolean lockFormatColumns)
void
setLockFormatRows(boolean lockFormatRows)
void
setMaxColumns(int cols)
Set the number of columns shown for the current sheet.
void
setMaxRows(int rows)
Set the number of rows shown for the current sheet.
void
setMergedRegions(ArrayList<MergedRegion> mergedRegions)
void
setMinimumRowHeightForComponents(int minimumRowHeightForComponents)
Set the minimum row heigth in points for the rows that contain custom components.
void
setNamedRanges(List<String> namedRanges)
void
setOverlays(HashMap<String,OverlayInfo> overlays)
void
setPopup(int row, int col, PopupButton popupButton)
Sets a pop-up button to the given cell in the currently active sheet.
void
setPopup(String cellAddress, PopupButton popupButton)
Sets a pop-up button to the given cell in the currently active sheet.
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.
void
setReload(boolean reload)
void
setReportStyle(boolean reportStyle)
Enables or disables the report style.
protected void
setResource(String key, Icon icon)
protected void
setResource(String key, StreamResource resource)
void
setRowBufferSize(int rowBufferInPixels)
Sets the row buffer size.
void
setRowColHeadingsVisible(boolean visible)
Sets row and column heading visibility for the currently active sheet.
void
setRowGroupingData(List<GroupingData> rowGroupingData)
void
setRowGroupingInversed(boolean rowGroupingInversed)
void
setRowGroupingMax(int rowGroupingMax)
void
setRowH(float[] rowH)
void
setRowHeight(int index, float height)
Sets the row height for currently active sheet.
void
setRowHidden(int rowIndex, boolean hidden)
Hides or shows the given row, see
Row.setZeroHeight(boolean)
.void
setRowIndexToStyleIndex(HashMap<Integer,Integer> rowIndexToStyleIndex)
void
setRows(int rows)
void
setSelection(int row, int col)
Selects the cell at the given coordinates
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.
void
setSelectionRange(int row1, int col1, int row2, int col2)
Selects the given range, using the cell at row1 and col1 as an anchor.
void
setSheetHidden(int sheetPOIIndex, int hidden)
Deprecated.
void
setSheetHidden(int sheetPOIIndex, org.apache.poi.ss.usermodel.SheetVisibility visibility)
See
Workbook.setSheetHidden(int, boolean)
.void
setSheetIndex(int sheetIndex)
void
setSheetMaxSize(int rows, int cols)
Does
setMaxColumns(int)
andsetMaxRows(int)
in one method.void
setSheetName(int sheetIndex, String sheetName)
Sets a name for the sheet at the given visible sheet index.
void
setSheetNames(String[] sheetNames)
void
setSheetNameWithPOIIndex(int sheetIndex, String sheetName)
Sets a name for the sheet at the given POI model index.
void
setSheetProtected(boolean sheetProtected)
void
setSheetProtected(int sheetPOIIndex, String password)
Sets the protection enabled with the given password for the sheet at the given index.
void
setSheetSelectionBarVisible(boolean sheetSelectionBarVisible)
Sets the visibility of the bottom sheet selection bar.
void
setShiftedCellBorderStyles(ArrayList<String> shiftedCellBorderStyles)
void
setSpreadsheetComponentFactory(SpreadsheetComponentFactory customComponentFactory)
Set a new component factory for this Spreadsheet.
void
setStatusLabelValue(String value)
Sets the content of the status label.
void
setTabIndex(int tabIndex)
Sets the
tabindex
attribute in the component.void
setVerticalScrollPositions(int[] verticalScrollPositions)
void
setVerticalSplitPosition(int verticalSplitPosition)
void
setVisibleCellComments(ArrayList<String> visibleCellComments)
void
setWidth(String width)
Sets the width of the component.
void
setWorkbook(org.apache.poi.ss.usermodel.Workbook workbook)
Reloads the component with the given Workbook.
void
setWorkbookChangeToggle(boolean workbookChangeToggle)
void
setWorkbookProtected(boolean workbookProtected)
void
shiftRows(int startRow, int endRow, int n)
Shifts rows between startRow and endRow n number of rows.
void
shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight)
Shifts rows between startRow and endRow n number of rows.
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.
void
write(OutputStream outputStream)
Exports current spreadsheet as an output stream.
File
write(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:
-
HIDE_TABSHEET_STYLE
public static final String HIDE_TABSHEET_STYLE
This is a style which hides the bottom (sheet selection) bar.
See Also:
-
mergedRegionCounter
protected int mergedRegionCounter
-
initialSheetSelection
protected String initialSheetSelection
-
mergedRegionContainer
protected final MergedRegionUtil.MergedRegionContainer mergedRegionContainer
Container for merged regions for the currently active sheet.
-
-
Constructor Detail
-
Spreadsheet
public Spreadsheet()
Creates a new Spreadsheet component using the newer Excel version format
XSSFWorkbook
. Also creates one sheet using the default rowSpreadsheetFactory.DEFAULT_ROWS
and columnSpreadsheetFactory.DEFAULT_COLUMNS
counts.
-
Spreadsheet
public Spreadsheet(int defaultRowCount, int defaultColumnCount)
Creates a new Spreadsheet component using the newer Excel version format
XSSFWorkbook
. Also creates one sheet using the given row and column counts. These counts will also be set as default for any new sheets created later.Parameters:
defaultRowCount
- Default row count for new 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 fileThrows:
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:
Component
Sets 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:
HasSize
Sets 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
height
value is null then height is removed.
-
setWidth
public void setWidth(String width)
Description copied from interface:
HasSize
Sets 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
width
value 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:
HasEnabled
Returns 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:
isEnabled
in 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.SelectionChangeEvent
for 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.SelectionChangeEvent
for the spreadsheet, or theCellRangeAddress
defining the selected row / column header.Specified by:
addActionHandler
in interfaceAction.Container
Parameters:
actionHandler
- the new handler to be added.
-
removeDefaultActionHandler
public void removeDefaultActionHandler()
Removes the spreadsheet's
SpreadsheetDefaultActionHandler
added oninit()
-
removeActionHandler
public void removeActionHandler(Action.Handler actionHandler)
Description copied from interface:
Action.Container
Removes a previously registered action handler for the contents of this container.
Specified by:
removeActionHandler
in interfaceAction.Container
Parameters:
actionHandler
- the handler to be removed.
-
setCellValueHandler
public void setCellValueHandler(Spreadsheet.CellValueHandler customCellValueHandler)
Sets the
Spreadsheet.CellValueHandler
for this component (not workbook/sheet specific). It is called when a cell's value has been updated by the user by using the spreadsheet component's default editor (text input).Parameters:
customCellValueHandler
- New handler ornull
if none should be used
-
getCellValueHandler
public Spreadsheet.CellValueHandler getCellValueHandler()
See
Spreadsheet.CellValueHandler
.Returns:
the current
Spreadsheet.CellValueHandler
for this component ornull
if none has been set
-
setCellDeletionHandler
public void setCellDeletionHandler(Spreadsheet.CellDeletionHandler customCellDeletionHandler)
Sets the
Spreadsheet.CellDeletionHandler
for this component (not workbook/sheet specific). It is called when a cell has been deleted by the user.Parameters:
customCellDeletionHandler
- New handler ornull
if none should be used
-
getCellDeletionHandler
public Spreadsheet.CellDeletionHandler getCellDeletionHandler()
See
Spreadsheet.CellDeletionHandler
.Returns:
the current
Spreadsheet.CellDeletionHandler
for this component ornull
if none has been set
-
setHyperlinkCellClickHandler
public void setHyperlinkCellClickHandler(Spreadsheet.HyperlinkCellClickHandler handler)
Sets the
Spreadsheet.HyperlinkCellClickHandler
for this component (not workbook/sheet specific). Called when the user clicks a cell that is a hyperlink or uses the hyperlink function.Parameters:
handler
- new handler ornull
if none should be usedSee Also:
Spreadsheet.HyperlinkCellClickHandler
,DefaultHyperlinkCellClickHandler
-
getHyperlinkCellClickHandler
public Spreadsheet.HyperlinkCellClickHandler getHyperlinkCellClickHandler()
See
Spreadsheet.HyperlinkCellClickHandler
.Returns:
the current
Spreadsheet.HyperlinkCellClickHandler
for this component ornull
if none has been set
-
getContextMenuManager
public ContextMenuManager getContextMenuManager()
Gets the ContextMenuManager for this Spreadsheet. This is component (not workbook/sheet) specific.
Returns:
The ContextMenuManager
-
getCellSelectionManager
public CellSelectionManager getCellSelectionManager()
Gets the CellSelectionManager for this Spreadsheet. This is component (not workbook/sheet) specific.
Returns:
The CellSelectionManager
-
getCellValueManager
public CellValueManager getCellValueManager()
Gets the CellValueManager for this Spreadsheet. This is component (not workbook/sheet) specific.
Returns:
The CellValueManager
-
getCellShifter
protected CellSelectionShifter getCellShifter()
Gets the CellShifter for this Spreadsheet. This is component (not workbook/sheet) specific.
Returns:
The CellShifter
-
getSpreadsheetHistoryManager
public SpreadsheetHistoryManager getSpreadsheetHistoryManager()
Gets the SpreadsheetHistoryManager for this Spreadsheet. This is component (not workbook/sheet) specific.
Returns:
The SpreadsheetHistoryManager
-
getMergedRegionContainer
protected MergedRegionUtil.MergedRegionContainer getMergedRegionContainer()
Gets the MergedRegionContainer for this Spreadsheet. This is component (not workbook/sheet) specific.
Returns:
The MergedRegionContainer
-
getFirstColumn
public int getFirstColumn()
Returns the first visible column in the main scroll area (NOT freeze pane)
Returns:
Index of first visible column, 1-based
-
getLastColumn
public int getLastColumn()
Returns the last visible column in the main scroll area (NOT freeze pane)
Returns:
Index of last visible column, 1-based
-
getFirstRow
public int getFirstRow()
Returns the first visible row in the scroll area (not freeze pane)
Returns:
Index of first visible row, 1-based
-
getLastRow
public int getLastRow()
Returns the last visible row in the main scroll area (NOT freeze pane)
Returns:
Index of last visible row, 1-based
-
getLastFrozenRow
public int getLastFrozenRow()
Returns the index the last frozen row (last row in top freeze pane).
Returns:
Last frozen row or 0 if none
-
getLastFrozenColumn
public int getLastFrozenColumn()
Returns the index the last frozen column (last column in left freeze pane).
Returns:
Last frozen column or 0 if none
-
isChartsEnabled
public boolean isChartsEnabled()
Returns true if embedded charts are displayed
Returns:
See Also:
-
setChartsEnabled
public void setChartsEnabled(boolean chartsEnabled)
Use this method to define whether embedded charts should be displayed in the spreadsheet or not.
Parameters:
chartsEnabled
-
-
isRerenderPending
public boolean isRerenderPending()
Returns true if the component is being fully re-rendered after this round-trip (sheet change etc.)
Returns:
true if re-render will happen, false otherwise
-
fireEvent
protected void fireEvent(ComponentEvent event)
Description copied from class:
Component
Dispatches the event to all listeners registered for the event type.
Overrides:
Parameters:
event
- the event to fireSee Also:
-
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 testReturns:
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-basedReturns:
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-basedReturns:
A CellRangeAddress based on the given coordinates.
-
setLocale
public void setLocale(Locale locale)
-
onAttach
protected void onAttach(AttachEvent attachEvent)
Description copied from class:
Component
Called when the component is attached to a UI.
The default implementation does nothing.
This method is invoked before the
AttachEvent
is fired for the component.
-
setSheetHidden
public void setSheetHidden(int sheetPOIIndex, org.apache.poi.ss.usermodel.SheetVisibility visibility) throws IllegalArgumentException
See
Workbook.setSheetHidden(int, boolean)
.Gets the Workbook with
getWorkbook()
and uses its API to access status on currently visible/hidden/very hidden sheets. If the currently active sheet is set hidden, another sheet is set as active sheet automatically. At least one sheet should be always visible.Parameters:
sheetPOIIndex
- Index of the target sheet within the POI model, 0-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.See
Workbook.setSheetHidden(int, boolean)
.Gets the Workbook with
getWorkbook()
and uses its API to access status on currently visible/hidden/very hidden sheets. If the currently active sheet is set hidden, another sheet is set as active sheet automatically. At least one sheet should be always visible.Parameters:
hidden
- Visibility state to set: 0-visible, 1-hidden, 2-very hidden.sheetPOIIndex
- Index of the target sheet within the POI model, 0-basedThrows:
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 IllegalArgumentException
Sets a name for the sheet at the given visible sheet index.
Parameters:
sheetIndex
- Index of the target sheet among the visible sheets, 0-basedsheetName
- New sheet name. Not null, empty nor longer than 31 characters. Must be unique within the Workbook.Throws:
IllegalArgumentException
- If the index is invalid, or if the sheet name is invalid. SeeWorkbookUtil.validateSheetName(String)
.
-
setSheetNameWithPOIIndex
public void setSheetNameWithPOIIndex(int sheetIndex, String sheetName) throws IllegalArgumentException
Sets a name for the sheet at the given POI model index.
Parameters:
sheetIndex
- Index of the target sheet within the POI model, 0-basedsheetName
- New sheet name. Not null, empty nor longer than 31 characters. Must be unique within the Workbook.Throws:
IllegalArgumentException
- If the index is invalid, or if the sheet name is invalid. SeeWorkbookUtil.validateSheetName(String)
.
-
setSheetProtected
public void setSheetProtected(int sheetPOIIndex, String password)
Sets the protection enabled with the given password for the sheet at the given index.
null
password removes the protection.Parameters:
sheetPOIIndex
- Index of the target sheet within the POI model, 0-basedpassword
- The password to set for the protection. Passnull
to remove the protection.
-
setActiveSheetProtected
public void setActiveSheetProtected(String password)
Sets the protection enabled with the given password for the currently active sheet.
null
password removes the protection.Parameters:
password
- The password to set for the protection. Passnull
to remove the protection.
-
createNewSheet
public void createNewSheet(String sheetName, int rows, int columns) throws IllegalArgumentException
Creates a new sheet as the last sheet and sets it as the active sheet. If the sheetName given is null, then the sheet name is automatically generated by Apache POI in
Workbook.createSheet()
.Parameters:
sheetName
- Can be null, but not empty nor longer than 31 characters. Must be unique within the Workbook.rows
- Number of rows the sheet should havecolumns
- Number of columns the sheet should haveThrows:
IllegalArgumentException
- If the sheet name is empty or over 31 characters long or not unique.
-
deleteSheetWithPOIIndex
public void deleteSheetWithPOIIndex(int poiSheetIndex) throws IllegalArgumentException
Deletes the sheet with the given POI model index. Note: A workbook must contain at least one visible sheet.
Parameters:
poiSheetIndex
- POI model index of the sheet to delete, 0-based, max 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 IllegalArgumentException
Deletes the sheet at the given index. Note: A workbook must contain at least one visible sheet.
Parameters:
sheetIndex
- Index of the sheet to delete among the visible sheets, 0-based, maximum 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 IllegalArgumentException
Sets the currently active sheet within the sheets that are visible.
Parameters:
sheetIndex
- Index of the target sheet (among the visible sheets), 0-basedThrows:
IllegalArgumentException
- If the index is invalid
-
setActiveSheetWithPOIIndex
public void setActiveSheetWithPOIIndex(int sheetIndex) throws IllegalArgumentException
Sets the currently active sheet. The sheet at the given index should be visible (not hidden or very hidden).
Parameters:
sheetIndex
- Index of sheet in the POI model (contains all sheets), 0-basedThrows:
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 if
setMaxColumns(int)
has been used, the current number of columns the component shows (not the amount of columns in the actual sheet in the POI model).Returns:
Number of visible columns.
-
getRows
public int getRows()
Get the number of rows in the currently active sheet, or if
setMaxRows(int)
has been used, the current number of rows the component shows (not the amount of rows in the actual sheet in the POI model).Returns:
Number of visible rows.
-
getDataFormatter
public org.apache.poi.ss.usermodel.DataFormatter getDataFormatter()
Gets the current DataFormatter.
Returns:
The data formatter for this Spreadsheet.
-
getCell
public org.apache.poi.ss.usermodel.Cell getCell(String cellAddress)
Returns the Cell at the given address. If the cell is updated in outside code, call
refreshCells(Cell...)
AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".Parameters:
cellAddress
- Address of the Cell to return, e.g. "A3"Returns:
The cell at the given address, or null if not defined
-
getCell
public org.apache.poi.ss.usermodel.Cell getCell(int row, int col)
Returns the Cell at the given coordinates. If the cell is updated in outside code, call
refreshCells(Cell...)
AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".Parameters:
row
- Row index of the cell to return, 0-basedcol
- Column index of the cell to return, 0-basedReturns:
The cell at the given coordinates, or null if not defined
-
getCell
public org.apache.poi.ss.usermodel.Cell getCell(int row, int col, org.apache.poi.ss.usermodel.Sheet sheet)
Returns the Cell at the given coordinates. If the cell is updated in outside code, call
refreshCells(Cell...)
AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".Parameters:
row
- Row index of the cell to return, 0-basedcol
- Column index of the cell to return, 0-basedsheet
- Sheet of the cellReturns:
The cell at the given coordinates, or null if not defined
-
getCell
public org.apache.poi.ss.usermodel.Cell getCell(org.apache.poi.ss.util.CellReference cellReference)
Returns the Cell corresponding to the given reference. If the cell is updated in outside code, call
refreshCells(Cell...)
AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".Parameters:
cellReference
- Reference to the cell to returnReturns:
The cell corresponding to the given reference, or null if not defined
-
getCell
public org.apache.poi.ss.usermodel.Cell getCell(String sheetName, int row, int column)
Returns the Cell at the given coordinates. If the cell is updated in outside code, call
refreshCells(Cell...)
AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".Parameters:
sheetName
- Name of the sheet the cell is on, or current sheet if nullrow
- Row index of the cell to return, 0-basedcolumn
- Column index of the cell to return, 0-basedReturns:
The cell at the given coordinates, or null if not defined
-
getCell
public org.apache.poi.ss.usermodel.Cell getCell(org.apache.poi.ss.util.CellReference cellReference, org.apache.poi.ss.usermodel.Sheet sheet)
Returns the Cell corresponding to the given reference. If the cell is updated in outside code, call
refreshCells(Cell...)
AFTER ALL UPDATES (value, type, formatting or style) to mark the cell as "dirty".Parameters:
cellReference
- Reference to the cell to returnsheet
- Sheet of the cellReturns:
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 the
Workbook
using POI API.Parameters:
cellStyleUpdated
- True if the cell style has changedcell
- The cell that has been deleted.
-
createFormulaCell
public org.apache.poi.ss.usermodel.Cell createFormulaCell(int row, int col, String formula) throws IllegalArgumentException
Creates a new Formula type cell with the given formula. After all editing is done, call
refreshCells(Cell...)
orrefreshAllCellValues()
to make sure client side is updated.Parameters:
row
- Row index of the new cell, 0-basedcol
- Column index of the new cell, 0-basedformula
- The formula to set to the new cell (should NOT start with "=" nor "+")Returns:
The newly created cell
Throws:
IllegalArgumentException
- If columnIndex < 0 or greater than the maximum number of supported columns (255 for *.xls, 1048576 for *.xlsx)
-
createCell
public org.apache.poi.ss.usermodel.Cell createCell(int row, int col, Object value) throws IllegalArgumentException
Create a new cell (or replace existing) with the given value, the type of the value parameter will define the type of the cell. The value may be of the following types: Boolean, Calendar, Date, Double or String. The default type will be String, value of (
Object.toString()
will be given as the cell value. For formula cells, usecreateFormulaCell(int, int, String)
. After all editing is done, callrefreshCells(Cell...)
orrefreshAllCellValues()
to make sure the client side is updated.Parameters:
row
- Row index of the new cell, 0-basedcol
- Column index of the new cell, 0-basedvalue
- Object representing the type and value of the CellReturns:
The newly created cell
Throws:
IllegalArgumentException
- If columnIndex < 0 or greater than the maximum number of supported columns (255 for *.xls, 1048576 for *.xlsx)
-
refreshAllCellValues
public void refreshAllCellValues()
Forces recalculation and update to the client side for values of all of the sheet's cells. Note: DOES NOT UPDATE STYLES; use
refreshCells(Cell...)
when cell styles change.
-
setMaxColumns
public void setMaxColumns(int cols)
Set the number of columns shown for the current sheet. Any null cells are left empty. Any cells outside the given columns are hidden. Does not update the actual POI-based model! The default value will be the actual size of the sheet from the POI model.
Parameters:
cols
- New maximum column count.
-
setMaxRows
public void setMaxRows(int rows)
Set the number of rows shown for the current sheet. Any null cells are left empty. Any cells outside the given rows are hidden. Does not update the actual POI-based model! The default value will be the actual size of the sheet from the POI model.
Parameters:
rows
- New maximum row count.
-
setSheetMaxSize
public void setSheetMaxSize(int rows, int cols)
Does
setMaxColumns(int)
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 by
getActiveSheet()
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 as
Sheet.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 by
getActiveSheet()
.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 a
Spreadsheet.RowHeaderDoubleClickListener
to the SpreadsheetParameters:
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. See
Sheet.autoSizeColumn(int)
.This does not take into account cells that have custom Vaadin components inside them.
Parameters:
columnIndex
- Index of the target column, 0-based
-
shiftRows
public void shiftRows(int startRow, int endRow, int n)
Shifts rows between startRow and endRow n number of rows. If you use a negative number for n, the rows will be shifted upwards. This method ensures that rows can't wrap around.
If you are adding / deleting rows, you might want to change the number of visible rows rendered
getRows()
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
FormulaEvaluator
instance.
-
getConditionalFormattingEvaluator
public org.apache.poi.ss.formula.ConditionalFormattingEvaluator getConditionalFormattingEvaluator()
POI, as of 4.0.0, now accepts this as an argument to formula evaluation. Some conditional formats can modify the display text of a cell.
Returns:
the common
ConditionalFormattingEvaluator
instance.
-
deleteRows
public void deleteRows(int startRow, int endRow)
Deletes rows. See
Sheet.removeRow(Row)
. Removes all row content, deletes cells and resets the sheet size. Does not shift rows up (!) - 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. See
Sheet.addMergedRegion(CellRangeAddress)
.Parameters:
selectionRange
- The cell range to merge, e.g. "B3:C5"
-
addMergedRegion
public void addMergedRegion(int row1, int col1, int row2, int col2)
Merge cells. See
Sheet.addMergedRegion(CellRangeAddress)
.Parameters:
row1
- Index of the starting row of the merged region, 0-basedcol1
- Index of the starting column of the merged region, 0-basedrow2
- Index of the ending row of the merged region, 0-basedcol2
- Index of the ending column of the merged region, 0-based
-
addMergedRegion
public void addMergedRegion(org.apache.poi.ss.util.CellRangeAddress region) throws IllegalArgumentException
Merges the given cells. See
Sheet.addMergedRegion(CellRangeAddress)
.If another existing merged region is completely inside the given range, it is removed. If another existing region either encloses or overlaps the given range, an error is thrown. See
CellRangeUtil.intersect(CellRangeAddress, CellRangeAddress)
.Note: POI doesn't seem to update the cells that are "removed" due to the merge - the values for those cells still exist and continue being used in possible formulas. If you need to make sure those values are removed, just delete the cells before creating the merged region.
If the added region affects the currently selected cell, a new
Spreadsheet.SelectionChangeEvent
is fired.Parameters:
region
- The range of cells to mergeThrows:
IllegalArgumentException
- If the given region overlaps with or encloses another existing region within the sheet.
-
removeMergedRegion
public void removeMergedRegion(int index)
Removes a merged region with the given index. Current merged regions can be inspected within the currently active sheet with
getActiveSheet()
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.SelectionChangeEvent
is fired.Parameters:
index
- Position of the target merged region in the POI merged region array, 0-based
-
reloadAllMergedRegions
public void reloadAllMergedRegions()
Discards all current merged regions for the sheet and reloads them from the POI model.
This can be used if you want to add / remove multiple merged regions directly from the POI model and need to update the component. Note that you must also make sure that possible styles for the merged regions are updated, if those were modified, by calling
reloadActiveSheetStyles()
.
-
reloadActiveSheetStyles
public void reloadActiveSheetStyles()
Reloads all the styles for the currently active sheet.
-
setColumnHidden
public void setColumnHidden(int columnIndex, boolean hidden)
Hides or shows the given column, see
Sheet.setColumnHidden(int, boolean)
.Parameters:
columnIndex
- Index of the target column, 0-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. See
Sheet.isColumnHidden(int)
.Parameters:
columnIndex
- Index of the target column, 0-basedReturns:
true if the target column is hidden, false if it is visible.
-
setRowHidden
public void setRowHidden(int rowIndex, boolean hidden)
Hides or shows the given row, see
Row.setZeroHeight(boolean)
.Parameters:
rowIndex
- Index of the target row, 0-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, see
Row.getZeroHeight()
.Parameters:
rowIndex
- Index of the target row, 0-basedReturns:
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 streamThrows:
IOException
- If writing to the stream fails
-
getRowBufferSize
public int getRowBufferSize()
The row buffer size determines the amount of content rendered outside the top and bottom edges of the visible cell area, for smoother scrolling.
Size is in pixels, the default is 200.
Returns:
The current row buffer size
-
setRowBufferSize
public void setRowBufferSize(int rowBufferInPixels)
Sets the row buffer size. Comes into effect the next time sheet is scrolled or reloaded.
The row buffer size determines the amount of content rendered outside the top and bottom edges of the visible cell area, for smoother scrolling.
Parameters:
rowBufferInPixels
- The amount of extra content rendered outside the top and bottom edges of the visible area.
-
getColBufferSize
public int getColBufferSize()
The column buffer size determines the amount of content rendered outside the left and right edges of the visible cell area, for smoother scrolling.
Size is in pixels, the default is 200.
Returns:
The current column buffer size
-
setColBufferSize
public void setColBufferSize(int colBufferInPixels)
Sets the column buffer size. Comes into effect the next time sheet is scrolled or reloaded.
The column buffer size determines the amount of content rendered outside the left and right edges of the visible cell area, for smoother scrolling.
Parameters:
colBufferInPixels
- The amount of extra content rendered outside the left and right edges of the visible area.
-
getDefaultRowCount
public int getDefaultRowCount()
Gets the default row count for new sheets.
Returns:
The default row count for new sheets.
-
setDefaultRowCount
public void setDefaultRowCount(int defaultRowCount)
Sets the default row count for new sheets.
Parameters:
defaultRowCount
- The number of rows to give sheets that are created with the '+' button on the client side.
-
getDefaultColumnCount
public int getDefaultColumnCount()
Gets the default column count for new sheets.
Returns:
The default column count for new sheets.
-
setDefaultColumnCount
public void setDefaultColumnCount(int defaultColumnCount)
Sets the default column count for new sheets.
Parameters:
defaultColumnCount
- The number of columns to give sheets that are created with the '+' button on the client side.
-
reloadVisibleCellContents
public void reloadVisibleCellContents()
Call this to force the spreadsheet to reload the currently viewed cell contents. This forces reload of all: custom components (always visible and editors) from
SpreadsheetComponentFactory
, hyperlinks, cells' comments and cells' contents. Also updates styles for the visible area.
-
setResource
protected void setResource(String key, StreamResource resource)
-
createConditionalFormatter
protected ConditionalFormatter createConditionalFormatter()
Override this method to provide your own
ConditionalFormatter
implementation. This method is called each time we open a workbook.Returns:
A
ConditionalFormatter
that is tied to this spreadsheet.
-
createSpreadsheetStyleFactory
protected SpreadsheetStyleFactory createSpreadsheetStyleFactory()
Override this method to provide your own
SpreadsheetStyleFactory
implementation. This method is called each time we open a workbook.Returns:
A
SpreadsheetStyleFactory
that is tied to this Spreadsheet.
-
reloadActiveSheetData
protected void reloadActiveSheetData()
Clears and reloads all data related to the currently active sheet.
-
loadCustomEditorOnSelectedCell
protected void loadCustomEditorOnSelectedCell()
This method should be always called when the selected cell has changed so proper actions can be triggered for possible custom component inside the cell.
-
getVisibleSheetPOIIndex
public int getVisibleSheetPOIIndex(int visibleSheetIndex)
Returns POI model based index for the given Spreadsheet sheet index.
Parameters:
visibleSheetIndex
- Index of the sheet within this Spreadsheet, 0-basedReturns:
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-basedReturns:
true if the target
Sheet
is protected, false otherwise.
-
isActiveSheetProtected
public boolean isActiveSheetProtected()
Gets the protection state of the current sheet.
Returns:
true if the current
Sheet
is protected, false otherwise.
-
isCellHidden
public boolean isCellHidden(org.apache.poi.ss.usermodel.Cell cell)
Gets the visibility state of the given cell.
Parameters:
cell
- The cell to checkReturns:
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 checkReturns:
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 POI
Workbook
API 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 POI
Sheet
API 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 a
Workbook
has 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, use
deleteTable(SpreadsheetTable)
to completely remove the table.See
registerTable(SpreadsheetTable)
.Parameters:
table
- The table to unregister
-
deleteTable
public void deleteTable(SpreadsheetTable table)
Deletes the given table: removes it from "memory" (see
registerTable(SpreadsheetTable)
), clears and removes all possible filters (if table is 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. See
registerTable(SpreadsheetTable)
.Returns:
All tables for this spreadsheet
-
getTablesForActiveSheet
public List<SpreadsheetTable> getTablesForActiveSheet()
Gets the tables that belong to the currently active sheet (
getActiveSheet()
). 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 the
DataFormatter
with the current locale. SeeDataFormatter.formatCellValue(Cell, FormulaEvaluator, ConditionalFormattingEvaluator)
.Parameters:
cell
- Cell to get the value fromReturns:
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
ConditionalFormatter
used by thisSpreadsheet
-
reset
public void reset()
Disposes the current
Workbook
, if any, and loads a new empty XSLX Workbook. Note: Discards all data. Be sure to write out the old Workbook if needed.
-
getDefaultPercentageFormat
public String getDefaultPercentageFormat()
Returns the formatting string that is used when a user enters percentages into the Spreadsheet.
Default is "0.00%".
Returns:
The formatting applied to percentage values when entered by the user
-
setDefaultPercentageFormat
public void setDefaultPercentageFormat(String defaultPercentageFormat)
Sets the formatting string that is used when a user enters percentages into the Spreadsheet.
Default is "0.00%".
-
setCommentAuthorProvider
public void setCommentAuthorProvider(Spreadsheet.CommentAuthorProvider commentAuthorProvider)
Sets the given CommentAuthorProvider to this Spreadsheet.
Parameters:
commentAuthorProvider
- New provider
-
getCommentAuthorProvider
public Spreadsheet.CommentAuthorProvider getCommentAuthorProvider()
Gets the CommentAuthorProvider currently set to this Spreadsheet.
Returns:
Current provider or null if not set.
-
editCellComment
public void editCellComment(org.apache.poi.ss.util.CellReference cr)
Triggers editing of the cell comment in the given cell reference. Note that the cell must have a previously set cell comment in order to be able to edit it.
Parameters:
cr
- Reference to the cell containing the comment to edit
-
setFunctionBarVisible
public void setFunctionBarVisible(boolean functionBarVisible)
Sets the visibility of the top function bar. By default the bar is visible.
Parameters:
functionBarVisible
- True to show the top bar, false to hide it.
-
isFunctionBarVisible
public boolean isFunctionBarVisible()
Gets the visibility of the top function bar. By default the bar is visible.
Returns:
True if the function bar is visible, false otherwise.
-
setSheetSelectionBarVisible
public void setSheetSelectionBarVisible(boolean sheetSelectionBarVisible)
Sets the visibility of the bottom sheet selection bar. By default the bar is visible.
Parameters:
sheetSelectionBarVisible
- True to show the sheet selection bar, false to hide it.
-
isSheetSelectionBarVisible
public boolean isSheetSelectionBarVisible()
Gets the visibility of the bottom sheet selection bar. By default the bar is visible.
Returns:
True if the sheet selection bar is visible, false otherwise.
-
setReportStyle
public void setReportStyle(boolean reportStyle)
Enables or disables the report style. When enabled, the top and bottom bars of Spreadsheet will be hidden.
Parameters:
reportStyle
- True to hide both toolbars, false to show them.
-
isReportStyle
public boolean isReportStyle()
Gets the state of the report style.
Returns:
True if report style is enabled, false otherwise.
-
setInvalidFormulaErrorMessage
public void setInvalidFormulaErrorMessage(String invalidFormulaErrorMessage)
-
getTabIndex
public int getTabIndex()
Description copied from interface:
Focusable
Gets the
tabindex
in 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 anIllegalStateException
is thrown.Specified by:
getTabIndex
in interfaceFocusable
Returns:
the tabindex attribute, or 0 if none
See Also:
-
setTabIndex
public void setTabIndex(int tabIndex)
Description copied from interface:
Focusable
Sets the
tabindex
attribute 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 = -1
means that the component should be focusable, but should not be reachable via sequential keyboard navigation. tabindex = 0
means 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 = 4
would 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:
setTabIndex
in interfaceFocusable
Parameters:
tabIndex
- the tabindex attributeSee Also:
- 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
-true
when collapsing columns,false
when 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:
Component
Gets the locale for this component.
It returns the
UI
locale if it has been set. If there is noUI
locale 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.
-
-