Class XSSFSheet
- java.lang.Object
-
- org.apache.poi.ooxml.POIXMLDocumentPart
-
- org.apache.poi.xssf.usermodel.XSSFSheet
-
- All Implemented Interfaces:
Iterable<Row>,Sheet,OoxmlSheetExtensions
- Direct Known Subclasses:
XSSFChartSheet,XSSFDialogsheet
public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetExtensions
High level representation of a SpreadsheetML worksheet.Sheets are the central structures within a workbook, and are where a user does most of his spreadsheet work. The most common type of sheet is the worksheet, which is represented as a grid of cells. Worksheet cells can contain text, numbers, dates, and formulas. Cells can also be formatted.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.poi.ooxml.POIXMLDocumentPart
POIXMLDocumentPart.RelationPart
-
-
Field Summary
Fields Modifier and Type Field Description protected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetsheetprotected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheetworksheet-
Fields inherited from interface org.apache.poi.ss.usermodel.Sheet
BottomMargin, FooterMargin, HeaderMargin, LeftMargin, PANE_LOWER_LEFT, PANE_LOWER_RIGHT, PANE_UPPER_LEFT, PANE_UPPER_RIGHT, RightMargin, TopMargin
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedXSSFSheet()Creates new XSSFSheet - called by XSSFWorkbook to create a sheet from scratch.protectedXSSFSheet(PackagePart part)Creates an XSSFSheet representing the given package part and relationship.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHyperlink(XSSFHyperlink hyperlink)Register a hyperlink in the collection of hyperlinks on this sheet.voidaddIgnoredErrors(CellRangeAddress region, IgnoredErrorType... ignoredErrorTypes)Ignore errors across a range of cells.voidaddIgnoredErrors(CellReference cell, IgnoredErrorType... ignoredErrorTypes)Add ignored errors (usually to suppress them in the UI of a consuming application).intaddMergedRegion(CellRangeAddress region)Adds a merged region of cells on a sheet.intaddMergedRegionUnsafe(CellRangeAddress region)Adds a merged region of cells (hence those cells form one).voidaddValidationData(DataValidation dataValidation)voidautoSizeColumn(int column)Adjusts the column width to fit the contents.voidautoSizeColumn(int column, boolean useMergedCells)Adjusts the column width to fit the contents.protected voidcommit()Save the content in the underlying package part.voidcopyRows(int srcStartRow, int srcEndRow, int destStartRow, CellCopyPolicy cellCopyPolicy)Copies rows between srcStartRow and srcEndRow to the same sheet, starting at destStartRow Convenience function forcopyRows(List, int, CellCopyPolicy)Equivalent to copyRows(getRows(srcStartRow, srcEndRow, false), destStartRow, cellCopyPolicy)voidcopyRows(List<? extends Row> srcRows, int destStartRow, CellCopyPolicy policy)copyRows rows from srcRows to this sheet starting at destStartRow Additionally copies merged regions that are completely defined in these rows (ie.XSSFDrawingcreateDrawingPatriarch()Create a new SpreadsheetML drawing.voidcreateFreezePane(int colSplit, int rowSplit)Creates a split (freezepane).voidcreateFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow)Creates a split (freezepane).XSSFPivotTablecreatePivotTable(Name source, CellReference position)Create a pivot table using the Name range, at the given position.XSSFPivotTablecreatePivotTable(Name source, CellReference position, Sheet sourceSheet)Create a pivot table using the Name range reference on sourceSheet, at the given position.XSSFPivotTablecreatePivotTable(Table source, CellReference position)Create a pivot table using the Table, at the given position.XSSFPivotTablecreatePivotTable(AreaReference source, CellReference position)Create a pivot table using the AreaReference range, at the given position.XSSFPivotTablecreatePivotTable(AreaReference source, CellReference position, Sheet sourceSheet)Create a pivot table using the AreaReference range on sourceSheet, at the given position.XSSFRowcreateRow(int rownum)Create a new row within the sheet and return the high level representation Note: If a row already exists at this position, it is removed/overwritten and any existing cell is removed!voidcreateSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane)Creates a split pane.XSSFTablecreateTable(AreaReference tableArea)Creates a new Table, and associates it with this Sheet.voiddisableLocking()Disable sheet protectionvoidenableLocking()Enable sheet protectionintfindEndOfRowOutlineGroup(int row)CellAddressgetActiveCell()Return location of the active cell, e.g.booleangetAutobreaks()Flag indicating whether the sheet displays Automatic Page Breaks.XSSFCommentgetCellComment(CellAddress address)Return cell comment at row, column, if one exists.Map<CellAddress,XSSFComment>getCellComments()Returns all cell comments on this sheet.int[]getColumnBreaks()Vertical page break information used for print layout view, page layout view, drawing print breaks in normal view, and for printing the worksheet.ColumnHelpergetColumnHelper()intgetColumnOutlineLevel(int columnIndex)CellStylegetColumnStyle(int column)Returns the CellStyle that applies to the given (0 based) column, or null if no style has been set for that columnintgetColumnWidth(int columnIndex)Get the actual column width (in units of 1/256th of a character width )floatgetColumnWidthInPixels(int columnIndex)Get the actual column width in pixelsprotected CommentsgetCommentsTable(boolean create)Returns the sheet's comments object if there is one, or null if notprotected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDrawinggetCTDrawing()protected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTLegacyDrawinggetCTLegacyDrawing()org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheetgetCTWorksheet()Provide access to the CTWorksheet bean holding this sheet's dataDataValidationHelpergetDataValidationHelper()List<XSSFDataValidation>getDataValidations()intgetDefaultColumnWidth()Get the default column width for the sheet (if the columns do not define their own width) in characters.shortgetDefaultRowHeight()Get the default row height for the sheet (if the rows do not define their own height) in twips (1/20 of a point)floatgetDefaultRowHeightInPoints()Get the default row height for the sheet measued in point size (if the rows do not define their own height).booleangetDisplayGuts()Get whether to display the guts or not, default value is trueXSSFDrawinggetDrawingPatriarch()Return the sheet's existing drawing, or null if there isn't yet one.FootergetEvenFooter()Returns the even footer.HeadergetEvenHeader()Returns the even header.FootergetFirstFooter()Returns the first page footer.HeadergetFirstHeader()Returns the first page header.intgetFirstRowNum()Gets the first row on the sheetbooleangetFitToPage()Flag indicating whether the Fit to Page print option is enabled.FootergetFooter()Returns the default footer for the sheet, creating one as needed.booleangetForceFormulaRecalculation()Whether Excel will be asked to recalculate all formulas of this sheet when the workbook is opened.HeadergetHeader()Returns the default header for the sheet, creating one as needed.XSSFHeaderFooterPropertiesgetHeaderFooterProperties()booleangetHorizontallyCenter()Determine whether printed output for this sheet will be horizontally centered.XSSFHyperlinkgetHyperlink(int row, int column)Get a Hyperlink in this sheet anchored at row, columnXSSFHyperlinkgetHyperlink(CellAddress addr)Get a Hyperlink in this sheet located in a cell specified by {code addr}List<XSSFHyperlink>getHyperlinkList()Get a list of Hyperlinks in this sheetMap<IgnoredErrorType,Set<CellRangeAddress>>getIgnoredErrors()Returns the errors currently being ignored and the ranges where they are ignored.intgetLastRowNum()shortgetLeftCol()doublegetMargin(short margin)Gets the size of the margin in inches.CellRangeAddressgetMergedRegion(int index)Returns the merged region at the specified index.List<CellRangeAddress>getMergedRegions()Returns the list of merged regions.protected intgetNumberOfComments()intgetNumHyperlinks()intgetNumMergedRegions()Returns the number of merged regions defined in this worksheetFootergetOddFooter()Returns the odd footer.HeadergetOddHeader()Returns the odd header.PaneInformationgetPaneInformation()Returns the information regarding the currently configured pane (split or freeze).intgetPhysicalNumberOfRows()Returns the number of physically defined rows (NOT the number of rows in the sheet)List<XSSFPivotTable>getPivotTables()Returns all the pivot tables for this SheetXSSFPrintSetupgetPrintSetup()Gets the print setup object.booleangetProtect()Answer whether protection is enabled or disabledCellRangeAddressgetRepeatingColumns()CellRangeAddressgetRepeatingRows()XSSFRowgetRow(int rownum)Returns the logical row ( 0-based).int[]getRowBreaks()Horizontal page break information used for print layout view, page layout view, drawing print breaks in normal view, and for printing the worksheet.booleangetRowSumsBelow()Flag indicating whether summary rows appear below detail in an outline, when applying an outline.booleangetRowSumsRight()Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline.booleangetScenarioProtect()A flag indicating whether scenarios are locked when the sheet is protected.org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormulagetSharedFormula(int sid)Return a master shared formula by indexXSSFSheetConditionalFormattinggetSheetConditionalFormatting()StringgetSheetName()Returns the name of this sheetprotected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViewsgetSheetTypeSheetViews(boolean create)XSSFColorgetTabColor()Get background color of the sheet tab.List<XSSFTable>getTables()Returns any tables associated with this SheetshortgetTopRow()The top row in the visible view when the sheet is first viewed after opening it in a viewerbooleangetVerticallyCenter()Determine whether printed output for this sheet will be vertically centered.XSSFVMLDrawinggetVMLDrawing(boolean autoCreate)Get VML drawing for this sheet (aka 'legacy' drawing).XSSFWorkbookgetWorkbook()Returns the parent XSSFWorkbookvoidgroupColumn(int fromColumn, int toColumn)Group between (0 based) columnsvoidgroupRow(int fromRow, int toRow)Tie a range of cell together so that they can be collapsed or expandedbooleanhasComments()Does this sheet have any comments on it? We need to know, so we can decide about writing it to disk or notbooleanisAutoFilterLocked()booleanisColumnBroken(int column)Determines if there is a page break at the indicated columnbooleanisColumnHidden(int columnIndex)Get the hidden state for a given column.booleanisDeleteColumnsLocked()booleanisDeleteRowsLocked()booleanisDisplayFormulas()Gets the flag indicating whether this sheet should display formulas.booleanisDisplayGridlines()Gets the flag indicating whether this sheet displays the lines between rows and columns to make editing and reading easier.booleanisDisplayRowColHeadings()Gets the flag indicating whether this sheet should display row and column headings.booleanisDisplayZeros()Gets the flag indicating whether the window should show 0 (zero) in cells containing zero value.booleanisFormatCellsLocked()booleanisFormatColumnsLocked()booleanisFormatRowsLocked()booleanisInsertColumnsLocked()booleanisInsertHyperlinksLocked()booleanisInsertRowsLocked()booleanisObjectsLocked()booleanisPivotTablesLocked()booleanisPrintGridlines()Returns whether gridlines are printed.booleanisPrintRowAndColumnHeadings()Returns whether row and column headings are printed.booleanisRightToLeft()Whether the text is displayed in right-to-left mode in the windowbooleanisRowBroken(int row)Tests if there is a page break at the indicated rowbooleanisScenariosLocked()booleanisSelected()Returns a flag indicating whether this sheet is selected.booleanisSelectLockedCellsLocked()booleanisSelectUnlockedCellsLocked()booleanisSheetLocked()booleanisSortLocked()voidlockAutoFilter(boolean enabled)Enable or disable Autofilters locking.voidlockDeleteColumns(boolean enabled)Enable or disable Deleting columns locking.voidlockDeleteRows(boolean enabled)Enable or disable Deleting rows locking.voidlockFormatCells(boolean enabled)Enable or disable Formatting cells locking.voidlockFormatColumns(boolean enabled)Enable or disable Formatting columns locking.voidlockFormatRows(boolean enabled)Enable or disable Formatting rows locking.voidlockInsertColumns(boolean enabled)Enable or disable Inserting columns locking.voidlockInsertHyperlinks(boolean enabled)Enable or disable Inserting hyperlinks locking.voidlockInsertRows(boolean enabled)Enable or disable Inserting rows locking.voidlockObjects(boolean enabled)Enable or disable Objects locking.voidlockPivotTables(boolean enabled)Enable or disable Pivot Tables locking.voidlockScenarios(boolean enabled)Enable or disable Scenarios locking.voidlockSelectLockedCells(boolean enabled)Enable or disable Selection of locked cells locking.voidlockSelectUnlockedCells(boolean enabled)Enable or disable Selection of unlocked cells locking.voidlockSort(boolean enabled)Enable or disable Sort locking.protected voidonDeleteFormula(XSSFCell cell, BaseXSSFEvaluationWorkbook evalWb)when a cell with a 'master' shared formula is removed, the next cell in the range becomes the masterprotected voidonDocumentCreate()Initialize worksheet data when creating a new sheet.protected voidonDocumentRead()Initialize worksheet data when reading in an exisiting file.protected voidonSheetDelete()called when a sheet is being deleted/removed from a workbook, to clean up relations and other document pieces tied to the sheetvoidprotectSheet(String password)Enables sheet protection and sets the password for the sheet.protected voidread(InputStream is)protected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOleObjectreadOleObject(long shapeId)Determine the OleObject which links shapes with embedded resourcesCellRange<XSSFCell>removeArrayFormula(Cell cell)voidremoveColumnBreak(int column)Removes a page break at the indicated columnvoidremoveHyperlink(int row, int column)Removes a hyperlink in the collection of hyperlinks on this sheetvoidremoveHyperlink(XSSFHyperlink hyperlink)Remove a hyperlink in the collection of hyperlinks on this sheet.voidremoveMergedRegion(int index)Removes a merged region of cells (hence letting them free)voidremoveMergedRegions(Collection<Integer> indices)Removes a number of merged regions of cells (hence letting them free) This method can be used to bulk-remove merged regions in a way much faster than calling removeMergedRegion() for every single merged region.voidremoveRow(Row row)Remove a row from this sheet.voidremoveRowBreak(int row)Removes the page break at the indicated rowvoidremoveTable(XSSFTable t)Remove table references and relationsIterator<Row>rowIterator()voidsetActiveCell(CellAddress address)CellRange<XSSFCell>setArrayFormula(String formula, CellRangeAddress range)voidsetAutobreaks(boolean value)Flag indicating whether the sheet displays Automatic Page Breaks.XSSFAutoFiltersetAutoFilter(CellRangeAddress range)voidsetColumnBreak(int column)Sets a page break at the indicated column.voidsetColumnGroupCollapsed(int columnNumber, boolean collapsed)voidsetColumnHidden(int columnIndex, boolean hidden)Get the visibility state for a given column.voidsetColumnWidth(int columnIndex, int width)Set the width (in units of 1/256th of a character width)voidsetDefaultColumnStyle(int column, CellStyle style)voidsetDefaultColumnWidth(int width)Specifies the number of characters of the maximum digit width of the normal style's font.voidsetDefaultRowHeight(short height)Set the default row height for the sheet (if the rows do not define their own height) in twips (1/20 of a point)voidsetDefaultRowHeightInPoints(float height)Sets default row height measured in point size.voidsetDisplayFormulas(boolean show)Sets the flag indicating whether this sheet should display formulas.voidsetDisplayGridlines(boolean show)Sets the flag indicating whether this sheet should display the lines between rows and columns to make editing and reading easier.voidsetDisplayGuts(boolean value)Set whether to display the guts or notvoidsetDisplayRowColHeadings(boolean show)Sets the flag indicating whether this sheet should display row and column headings.voidsetDisplayZeros(boolean value)Set whether the window should show 0 (zero) in cells containing zero value.voidsetFitToPage(boolean b)Flag indicating whether the Fit to Page print option is enabled.voidsetForceFormulaRecalculation(boolean value)Control if Excel should be asked to recalculate all formulas on this sheet when the workbook is opened.voidsetHorizontallyCenter(boolean value)Center on page horizontally when printing.voidsetMargin(short margin, double size)Sets the size of the margin in inches.voidsetPrintGridlines(boolean value)Turns on or off the printing of gridlines.voidsetPrintRowAndColumnHeadings(boolean value)Turns on or off the printing of row and column headings.voidsetRepeatingColumns(CellRangeAddress columnRangeRef)voidsetRepeatingRows(CellRangeAddress rowRangeRef)voidsetRightToLeft(boolean value)Sets whether the worksheet is displayed from right to left instead of from left to right.voidsetRowBreak(int row)Sets a page break at the indicated row Breaks occur above the specified row and left of the specified column inclusive.voidsetRowGroupCollapsed(int rowIndex, boolean collapse)group the row It is possible for collapsed to be false and yet still have the rows in question hidden.voidsetRowSumsBelow(boolean value)Flag indicating whether summary rows appear below detail in an outline, when applying an outline.voidsetRowSumsRight(boolean value)Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline.voidsetSelected(boolean value)Sets a flag indicating whether this sheet is selected.voidsetSheetPassword(String password, HashAlgorithm hashAlgo)Sets the sheet password.voidsetTabColor(XSSFColor color)Set background color of the sheet tabvoidsetVerticallyCenter(boolean value)Whether the output is vertically centered on the page.voidsetZoom(int scale)Window zoom magnification for current view representing percent values.voidshiftColumns(int startColumn, int endColumn, int n)Shifts columns between startColumn and endColumn n number of columns.voidshiftRows(int startRow, int endRow, int n)Shifts rows between startRow and endRow n number of rows.voidshiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight)Shifts rows between startRow and endRow n number of rows.voidshowInPane(int topRow, int leftCol)Location of the top left visible cell Location of the top left visible cell in the bottom right pane (when in Left-to-Right mode).Spliterator<Row>spliterator()voidungroupColumn(int fromColumn, int toColumn)voidungroupRow(int fromRow, int toRow)Ungroup a range of rows that were previously grouppedvoidvalidateMergedRegions()Verify that merged regions do not intersect multi-cell array formulas and no merged regions intersect another merged region in this sheet.booleanvalidateSheetPassword(String password)Validate the password against the stored hash, the hashing method will be determined by the existing password attributesprotected voidwrite(OutputStream out)-
Methods inherited from class org.apache.poi.ooxml.POIXMLDocumentPart
_invokeOnDocumentRead, addRelation, createRelationship, createRelationship, createRelationship, getNextPartNumber, getPackagePart, getParent, getRelationById, getRelationId, getRelationPartById, getRelationParts, getRelations, getTargetPart, isCommitted, onDocumentRemove, onSave, prepareForCommit, read, rebase, removeRelation, removeRelation, removeRelation, setCommitted, toString
-
-
-
-
Constructor Detail
-
XSSFSheet
protected XSSFSheet()
Creates new XSSFSheet - called by XSSFWorkbook to create a sheet from scratch.- See Also:
XSSFWorkbook.createSheet()
-
XSSFSheet
protected XSSFSheet(PackagePart part)
Creates an XSSFSheet representing the given package part and relationship. Should only be called by XSSFWorkbook when reading in an existing file.- Parameters:
part- - The package part that holds xml data representing this sheet.- Since:
- POI 3.14-Beta1
-
-
Method Detail
-
getWorkbook
public XSSFWorkbook getWorkbook()
Returns the parent XSSFWorkbook- Specified by:
getWorkbookin interfaceSheet- Returns:
- the parent XSSFWorkbook
-
onDocumentRead
protected void onDocumentRead()
Initialize worksheet data when reading in an exisiting file.- Overrides:
onDocumentReadin classPOIXMLDocumentPart
-
read
protected void read(InputStream is) throws IOException
- Throws:
IOException
-
onDocumentCreate
protected void onDocumentCreate()
Initialize worksheet data when creating a new sheet.- Overrides:
onDocumentCreatein classPOIXMLDocumentPart
-
getCTWorksheet
@Internal public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet getCTWorksheet()
Provide access to the CTWorksheet bean holding this sheet's data- Returns:
- the CTWorksheet bean holding this sheet's data
-
getColumnHelper
public ColumnHelper getColumnHelper()
-
getSheetName
public String getSheetName()
Returns the name of this sheet- Specified by:
getSheetNamein interfaceSheet- Returns:
- the name of this sheet
-
addMergedRegion
public int addMergedRegion(CellRangeAddress region)
Adds a merged region of cells on a sheet.- Specified by:
addMergedRegionin interfaceSheet- Parameters:
region- to merge- Returns:
- index of this region
- Throws:
IllegalArgumentException- if region contains fewer than 2 cellsIllegalStateException- if region intersects with a multi-cell array formulaIllegalStateException- if region intersects with an existing region on this sheet
-
addMergedRegionUnsafe
public int addMergedRegionUnsafe(CellRangeAddress region)
Adds a merged region of cells (hence those cells form one). Skips validation. It is possible to create overlapping merged regions or create a merged region that intersects a multi-cell array formula with this formula, which may result in a corrupt workbook. To check for merged regions overlapping array formulas or other merged regions after addMergedRegionUnsafe has been called, callvalidateMergedRegions(), which runs in O(n^2) time.- Specified by:
addMergedRegionUnsafein interfaceSheet- Parameters:
region- to merge- Returns:
- index of this region
- Throws:
IllegalArgumentException- if region contains fewer than 2 cells
-
validateMergedRegions
public void validateMergedRegions()
Verify that merged regions do not intersect multi-cell array formulas and no merged regions intersect another merged region in this sheet.- Specified by:
validateMergedRegionsin interfaceSheet- Throws:
IllegalStateException- if region intersects with a multi-cell array formulaIllegalStateException- if at least one region intersects with another merged region in this sheet
-
autoSizeColumn
public void autoSizeColumn(int column)
Adjusts the column width to fit the contents. This process can be relatively slow on large sheets, so this should normally only be called once per column, at the end of your processing.- Specified by:
autoSizeColumnin interfaceSheet- Parameters:
column- the column index
-
autoSizeColumn
public void autoSizeColumn(int column, boolean useMergedCells)Adjusts the column width to fit the contents.This process can be relatively slow on large sheets, so this should normally only be called once per column, at the end of your processing.
You can specify whether the content of merged cells should be considered or ignored. Default is to ignore merged cells.- Specified by:
autoSizeColumnin interfaceSheet- Parameters:
column- the column indexuseMergedCells- whether to use the contents of merged cells when calculating the width of the column
-
getDrawingPatriarch
public XSSFDrawing getDrawingPatriarch()
Return the sheet's existing drawing, or null if there isn't yet one. UsecreateDrawingPatriarch()to get or create- Specified by:
getDrawingPatriarchin interfaceSheet- Returns:
- a SpreadsheetML drawing
-
createDrawingPatriarch
public XSSFDrawing createDrawingPatriarch()
Create a new SpreadsheetML drawing. If this sheet already contains a drawing - return that.- Specified by:
createDrawingPatriarchin interfaceSheet- Returns:
- a SpreadsheetML drawing
-
getVMLDrawing
public XSSFVMLDrawing getVMLDrawing(boolean autoCreate)
Get VML drawing for this sheet (aka 'legacy' drawing).- Specified by:
getVMLDrawingin interfaceOoxmlSheetExtensions- Parameters:
autoCreate- if true, then a new VML drawing part is created- Returns:
- the VML drawing of
nullif the drawing was not found and autoCreate=false
-
getCTDrawing
protected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDrawing getCTDrawing()
-
getCTLegacyDrawing
protected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTLegacyDrawing getCTLegacyDrawing()
-
createFreezePane
public void createFreezePane(int colSplit, int rowSplit)Creates a split (freezepane). Any existing freezepane or split pane is overwritten.- Specified by:
createFreezePanein interfaceSheet- Parameters:
colSplit- Horizontal position of split.rowSplit- Vertical position of split.
-
createFreezePane
public void createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow)Creates a split (freezepane). Any existing freezepane or split pane is overwritten.If both colSplit and rowSplit are zero then the existing freeze pane is removed
- Specified by:
createFreezePanein interfaceSheet- Parameters:
colSplit- Horizontal position of split.rowSplit- Vertical position of split.leftmostColumn- Left column visible in right pane.topRow- Top row visible in bottom pane
-
createRow
public XSSFRow createRow(int rownum)
Create a new row within the sheet and return the high level representation Note: If a row already exists at this position, it is removed/overwritten and any existing cell is removed!- Specified by:
createRowin interfaceSheet- Parameters:
rownum- row number- Returns:
- High level
XSSFRowobject representing a row in the sheet - See Also:
removeRow(Row)
-
createSplitPane
public void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane)Creates a split pane. Any existing freezepane or split pane is overwritten.- Specified by:
createSplitPanein interfaceSheet- Parameters:
xSplitPos- Horizontal position of split (in 1/20th of a point).ySplitPos- Vertical position of split (in 1/20th of a point).topRow- Top row visible in bottom paneleftmostColumn- Left column visible in right pane.activePane- Active pane. One of: PANE_LOWER_RIGHT, PANE_UPPER_RIGHT, PANE_LOWER_LEFT, PANE_UPPER_LEFT- See Also:
Sheet.PANE_LOWER_LEFT,Sheet.PANE_LOWER_RIGHT,Sheet.PANE_UPPER_LEFT,Sheet.PANE_UPPER_RIGHT
-
getCellComment
public XSSFComment getCellComment(CellAddress address)
Return cell comment at row, column, if one exists. Otherwise returns null.- Specified by:
getCellCommentin interfaceSheet- Parameters:
address- the location of the cell comment- Returns:
- the cell comment, if one exists. Otherwise, return null.
-
getCellComments
public Map<CellAddress,XSSFComment> getCellComments()
Returns all cell comments on this sheet.- Specified by:
getCellCommentsin interfaceSheet- Returns:
- A map of each Comment in the sheet, keyed on the cell address where the comment is located.
-
getHyperlink
public XSSFHyperlink getHyperlink(int row, int column)
Get a Hyperlink in this sheet anchored at row, column- Specified by:
getHyperlinkin interfaceSheet- Parameters:
row- The row where the hyperlink is anchoredcolumn- The column where the hyperlink is anchored- Returns:
- hyperlink if there is a hyperlink anchored at row, column; otherwise returns null
-
getHyperlink
public XSSFHyperlink getHyperlink(CellAddress addr)
Get a Hyperlink in this sheet located in a cell specified by {code addr}- Specified by:
getHyperlinkin interfaceSheet- Parameters:
addr- The address of the cell containing the hyperlink- Returns:
- hyperlink if there is a hyperlink anchored at
addr; otherwise returnsnull - Since:
- POI 3.15 beta 3
-
getHyperlinkList
public List<XSSFHyperlink> getHyperlinkList()
Get a list of Hyperlinks in this sheet- Specified by:
getHyperlinkListin interfaceSheet- Returns:
- Hyperlinks for the sheet
-
getColumnBreaks
public int[] getColumnBreaks()
Vertical page break information used for print layout view, page layout view, drawing print breaks in normal view, and for printing the worksheet.- Specified by:
getColumnBreaksin interfaceSheet- Returns:
- column indexes of all the vertical page breaks, never
null
-
getColumnWidth
public int getColumnWidth(int columnIndex)
Get the actual column width (in units of 1/256th of a character width )Note, the returned value is always gerater that
getDefaultColumnWidth()because the latter does not include margins. Actual column width measured as the number of characters of the maximum digit width of the numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. There are 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines.- Specified by:
getColumnWidthin interfaceSheet- Parameters:
columnIndex- - the column to set (0-based)- Returns:
- width - the width in units of 1/256th of a character width
-
getColumnWidthInPixels
public float getColumnWidthInPixels(int columnIndex)
Get the actual column width in pixelsPlease note, that this method works correctly only for workbooks with the default font size (Calibri 11pt for .xlsx).
- Specified by:
getColumnWidthInPixelsin interfaceSheet
-
getDefaultColumnWidth
public int getDefaultColumnWidth()
Get the default column width for the sheet (if the columns do not define their own width) in characters.Note, this value is different from
getColumnWidth(int). The latter is always greater and includes 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines.- Specified by:
getDefaultColumnWidthin interfaceSheet- Returns:
- column width, default value is 8
-
getDefaultRowHeight
public short getDefaultRowHeight()
Get the default row height for the sheet (if the rows do not define their own height) in twips (1/20 of a point)- Specified by:
getDefaultRowHeightin interfaceSheet- Returns:
- default row height
-
getDefaultRowHeightInPoints
public float getDefaultRowHeightInPoints()
Get the default row height for the sheet measued in point size (if the rows do not define their own height).- Specified by:
getDefaultRowHeightInPointsin interfaceSheet- Returns:
- default row height in points
-
getColumnStyle
public CellStyle getColumnStyle(int column)
Returns the CellStyle that applies to the given (0 based) column, or null if no style has been set for that column- Specified by:
getColumnStylein interfaceSheet
-
setRightToLeft
public void setRightToLeft(boolean value)
Sets whether the worksheet is displayed from right to left instead of from left to right.- Specified by:
setRightToLeftin interfaceSheet- Parameters:
value- true for right to left, false otherwise.
-
isRightToLeft
public boolean isRightToLeft()
Whether the text is displayed in right-to-left mode in the window- Specified by:
isRightToLeftin interfaceSheet- Returns:
- whether the text is displayed in right-to-left mode in the window
-
getDisplayGuts
public boolean getDisplayGuts()
Get whether to display the guts or not, default value is true- Specified by:
getDisplayGutsin interfaceSheet- Returns:
- boolean - guts or no guts
-
setDisplayGuts
public void setDisplayGuts(boolean value)
Set whether to display the guts or not- Specified by:
setDisplayGutsin interfaceSheet- Parameters:
value- - guts or no guts
-
isDisplayZeros
public boolean isDisplayZeros()
Gets the flag indicating whether the window should show 0 (zero) in cells containing zero value. When false, cells with zero value appear blank instead of showing the number zero.- Specified by:
isDisplayZerosin interfaceSheet- Returns:
- whether all zero values on the worksheet are displayed (defaults to true)
-
setDisplayZeros
public void setDisplayZeros(boolean value)
Set whether the window should show 0 (zero) in cells containing zero value. When false, cells with zero value appear blank instead of showing the number zero.- Specified by:
setDisplayZerosin interfaceSheet- Parameters:
value- whether to display or hide all zero values on the worksheet
-
getFirstRowNum
public int getFirstRowNum()
Gets the first row on the sheet- Specified by:
getFirstRowNumin interfaceSheet- Returns:
- the number of the first logical row on the sheet, zero based
-
getFitToPage
public boolean getFitToPage()
Flag indicating whether the Fit to Page print option is enabled.- Specified by:
getFitToPagein interfaceSheet- Returns:
true
-
getFooter
public Footer getFooter()
Returns the default footer for the sheet, creating one as needed. You may also want to look atgetFirstFooter(),getOddFooter()andgetEvenFooter()
-
getHeader
public Header getHeader()
Returns the default header for the sheet, creating one as needed. You may also want to look atgetFirstHeader(),getOddHeader()andgetEvenHeader()
-
getOddFooter
public Footer getOddFooter()
Returns the odd footer. Used on all pages unless other footers also present, when used on only odd pages.
-
getEvenFooter
public Footer getEvenFooter()
Returns the even footer. Not there by default, but when set, used on even pages.
-
getFirstFooter
public Footer getFirstFooter()
Returns the first page footer. Not there by default, but when set, used on the first page.
-
getOddHeader
public Header getOddHeader()
Returns the odd header. Used on all pages unless other headers also present, when used on only odd pages.
-
getEvenHeader
public Header getEvenHeader()
Returns the even header. Not there by default, but when set, used on even pages.
-
getFirstHeader
public Header getFirstHeader()
Returns the first page header. Not there by default, but when set, used on the first page.
-
getHorizontallyCenter
public boolean getHorizontallyCenter()
Determine whether printed output for this sheet will be horizontally centered.- Specified by:
getHorizontallyCenterin interfaceSheet
-
getLastRowNum
public int getLastRowNum()
- Specified by:
getLastRowNumin interfaceSheet
-
getLeftCol
public short getLeftCol()
- Specified by:
getLeftColin interfaceSheet
-
getMargin
public double getMargin(short margin)
Gets the size of the margin in inches.- Specified by:
getMarginin interfaceSheet- Parameters:
margin- which margin to get- Returns:
- the size of the margin
- See Also:
Sheet.LeftMargin,Sheet.RightMargin,Sheet.TopMargin,Sheet.BottomMargin,Sheet.HeaderMargin,Sheet.FooterMargin
-
setMargin
public void setMargin(short margin, double size)Sets the size of the margin in inches.- Specified by:
setMarginin interfaceSheet- Parameters:
margin- which margin to getsize- the size of the margin- See Also:
Sheet.LeftMargin,Sheet.RightMargin,Sheet.TopMargin,Sheet.BottomMargin,Sheet.HeaderMargin,Sheet.FooterMargin
-
getMergedRegion
public CellRangeAddress getMergedRegion(int index)
Returns the merged region at the specified index. If you want multiple regions, it is faster to callgetMergedRegions()than to call this each time.- Specified by:
getMergedRegionin interfaceSheet- Returns:
- the merged region at the specified index
-
getMergedRegions
public List<CellRangeAddress> getMergedRegions()
Returns the list of merged regions. If you want multiple regions, this is faster than callinggetMergedRegion(int)each time.- Specified by:
getMergedRegionsin interfaceSheet- Returns:
- the list of merged regions
-
getNumMergedRegions
public int getNumMergedRegions()
Returns the number of merged regions defined in this worksheet- Specified by:
getNumMergedRegionsin interfaceSheet- Returns:
- number of merged regions in this worksheet
-
getNumHyperlinks
public int getNumHyperlinks()
-
getPaneInformation
public PaneInformation getPaneInformation()
Returns the information regarding the currently configured pane (split or freeze).- Specified by:
getPaneInformationin interfaceSheet- Returns:
- null if no pane configured, or the pane information.
-
getPhysicalNumberOfRows
public int getPhysicalNumberOfRows()
Returns the number of physically defined rows (NOT the number of rows in the sheet)- Specified by:
getPhysicalNumberOfRowsin interfaceSheet- Returns:
- the number of physically defined rows
-
getPrintSetup
public XSSFPrintSetup getPrintSetup()
Gets the print setup object.- Specified by:
getPrintSetupin interfaceSheet- Returns:
- The user model for the print setup object.
-
getProtect
public boolean getProtect()
Answer whether protection is enabled or disabled- Specified by:
getProtectin interfaceSheet- Returns:
- true => protection enabled; false => protection disabled
-
protectSheet
public void protectSheet(String password)
Enables sheet protection and sets the password for the sheet. Also sets some attributes on theCTSheetProtectionthat correspond to the default values used by Excel- Specified by:
protectSheetin interfaceSheet- Parameters:
password- to set for protection. Passnullto remove protection
-
setSheetPassword
public void setSheetPassword(String password, HashAlgorithm hashAlgo)
Sets the sheet password.- Parameters:
password- if null, the password will be removedhashAlgo- if null, the password will be set as XOR password (Excel 2010 and earlier) otherwise the given algorithm is used for calculating the hash password (Excel 2013)
-
validateSheetPassword
public boolean validateSheetPassword(String password)
Validate the password against the stored hash, the hashing method will be determined by the existing password attributes- Returns:
- true, if the hashes match (... though original password may differ ...)
-
getRow
public XSSFRow getRow(int rownum)
Returns the logical row ( 0-based). If you ask for a row that is not defined you get a null. This is to say row 4 represents the fifth row on a sheet.
-
getRowBreaks
public int[] getRowBreaks()
Horizontal page break information used for print layout view, page layout view, drawing print breaks in normal view, and for printing the worksheet.- Specified by:
getRowBreaksin interfaceSheet- Returns:
- row indexes of all the horizontal page breaks, never
null
-
getRowSumsBelow
public boolean getRowSumsBelow()
Flag indicating whether summary rows appear below detail in an outline, when applying an outline.When true a summary row is inserted below the detailed data being summarized and a new outline level is established on that row.
When false a summary row is inserted above the detailed data being summarized and a new outline level is established on that row.
- Specified by:
getRowSumsBelowin interfaceSheet- Returns:
trueif row summaries appear below detail in the outline
-
setRowSumsBelow
public void setRowSumsBelow(boolean value)
Flag indicating whether summary rows appear below detail in an outline, when applying an outline.When true a summary row is inserted below the detailed data being summarized and a new outline level is established on that row.
When false a summary row is inserted above the detailed data being summarized and a new outline level is established on that row.
- Specified by:
setRowSumsBelowin interfaceSheet- Parameters:
value-trueif row summaries appear below detail in the outline
-
getRowSumsRight
public boolean getRowSumsRight()
Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline.When true a summary column is inserted to the right of the detailed data being summarized and a new outline level is established on that column.
When false a summary column is inserted to the left of the detailed data being summarized and a new outline level is established on that column.
- Specified by:
getRowSumsRightin interfaceSheet- Returns:
trueif col summaries appear right of the detail in the outline
-
setRowSumsRight
public void setRowSumsRight(boolean value)
Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline.When true a summary column is inserted to the right of the detailed data being summarized and a new outline level is established on that column.
When false a summary column is inserted to the left of the detailed data being summarized and a new outline level is established on that column.
- Specified by:
setRowSumsRightin interfaceSheet- Parameters:
value-trueif col summaries appear right of the detail in the outline
-
getScenarioProtect
public boolean getScenarioProtect()
A flag indicating whether scenarios are locked when the sheet is protected.- Specified by:
getScenarioProtectin interfaceSheet- Returns:
- true => protection enabled; false => protection disabled
-
getTopRow
public short getTopRow()
The top row in the visible view when the sheet is first viewed after opening it in a viewer
-
getVerticallyCenter
public boolean getVerticallyCenter()
Determine whether printed output for this sheet will be vertically centered.- Specified by:
getVerticallyCenterin interfaceSheet- Returns:
- whether printed output for this sheet will be vertically centered.
-
groupColumn
public void groupColumn(int fromColumn, int toColumn)Group between (0 based) columns- Specified by:
groupColumnin interfaceSheet
-
groupRow
public void groupRow(int fromRow, int toRow)Tie a range of cell together so that they can be collapsed or expanded
-
isColumnBroken
public boolean isColumnBroken(int column)
Determines if there is a page break at the indicated column- Specified by:
isColumnBrokenin interfaceSheet
-
isColumnHidden
public boolean isColumnHidden(int columnIndex)
Get the hidden state for a given column.- Specified by:
isColumnHiddenin interfaceSheet- Parameters:
columnIndex- - the column to set (0-based)- Returns:
- hidden -
falseif the column is visible
-
isDisplayFormulas
public boolean isDisplayFormulas()
Gets the flag indicating whether this sheet should display formulas.- Specified by:
isDisplayFormulasin interfaceSheet- Returns:
trueif this sheet should display formulas.
-
isDisplayGridlines
public boolean isDisplayGridlines()
Gets the flag indicating whether this sheet displays the lines between rows and columns to make editing and reading easier.- Specified by:
isDisplayGridlinesin interfaceSheet- Returns:
true(default) if this sheet displays gridlines.- See Also:
to check if printing of gridlines is turned on or off
-
setDisplayGridlines
public void setDisplayGridlines(boolean show)
Sets the flag indicating whether this sheet should display the lines between rows and columns to make editing and reading easier. To turn printing of gridlines usesetPrintGridlines(boolean)- Specified by:
setDisplayGridlinesin interfaceSheet- Parameters:
show-trueif this sheet should display gridlines.- See Also:
setPrintGridlines(boolean)
-
isDisplayRowColHeadings
public boolean isDisplayRowColHeadings()
Gets the flag indicating whether this sheet should display row and column headings.Row heading are the row numbers to the side of the sheet
Column heading are the letters or numbers that appear above the columns of the sheet
- Specified by:
isDisplayRowColHeadingsin interfaceSheet- Returns:
true(default) if this sheet should display row and column headings.
-
setDisplayRowColHeadings
public void setDisplayRowColHeadings(boolean show)
Sets the flag indicating whether this sheet should display row and column headings.Row heading are the row numbers to the side of the sheet
Column heading are the letters or numbers that appear above the columns of the sheet
- Specified by:
setDisplayRowColHeadingsin interfaceSheet- Parameters:
show-trueif this sheet should display row and column headings.
-
isPrintGridlines
public boolean isPrintGridlines()
Returns whether gridlines are printed.- Specified by:
isPrintGridlinesin interfaceSheet- Returns:
- whether gridlines are printed
-
setPrintGridlines
public void setPrintGridlines(boolean value)
Turns on or off the printing of gridlines.- Specified by:
setPrintGridlinesin interfaceSheet- Parameters:
value- boolean to turn on or off the printing of gridlines
-
isPrintRowAndColumnHeadings
public boolean isPrintRowAndColumnHeadings()
Returns whether row and column headings are printed.- Specified by:
isPrintRowAndColumnHeadingsin interfaceSheet- Returns:
- whether row and column headings are printed
-
setPrintRowAndColumnHeadings
public void setPrintRowAndColumnHeadings(boolean value)
Turns on or off the printing of row and column headings.- Specified by:
setPrintRowAndColumnHeadingsin interfaceSheet- Parameters:
value- boolean to turn on or off the printing of row and column headings
-
isRowBroken
public boolean isRowBroken(int row)
Tests if there is a page break at the indicated row- Specified by:
isRowBrokenin interfaceSheet- Parameters:
row- index of the row to test- Returns:
trueif there is a page break at the indicated row
-
setRowBreak
public void setRowBreak(int row)
Sets a page break at the indicated row Breaks occur above the specified row and left of the specified column inclusive. For example,sheet.setColumnBreak(2);breaks the sheet into two parts with columns A,B,C in the first and D,E,... in the second. Simuilar,sheet.setRowBreak(2);breaks the sheet into two parts with first three rows (rownum=1...3) in the first part and rows starting with rownum=4 in the second.- Specified by:
setRowBreakin interfaceSheet- Parameters:
row- the row to break, inclusive
-
removeColumnBreak
public void removeColumnBreak(int column)
Removes a page break at the indicated column- Specified by:
removeColumnBreakin interfaceSheet
-
removeMergedRegion
public void removeMergedRegion(int index)
Removes a merged region of cells (hence letting them free)- Specified by:
removeMergedRegionin interfaceSheet- Parameters:
index- of the region to unmerge
-
removeMergedRegions
public void removeMergedRegions(Collection<Integer> indices)
Removes a number of merged regions of cells (hence letting them free) This method can be used to bulk-remove merged regions in a way much faster than calling removeMergedRegion() for every single merged region.- Specified by:
removeMergedRegionsin interfaceSheet- Parameters:
indices- A set of the regions to unmerge
-
removeRow
public void removeRow(Row row)
Remove a row from this sheet. All cells contained in the row are removed as well
-
removeRowBreak
public void removeRowBreak(int row)
Removes the page break at the indicated row- Specified by:
removeRowBreakin interfaceSheet
-
setForceFormulaRecalculation
public void setForceFormulaRecalculation(boolean value)
Control if Excel should be asked to recalculate all formulas on this sheet when the workbook is opened.Calculating the formula values with
FormulaEvaluatoris the recommended solution, but this may be used for certain cases where evaluation in POI is not possible.It is recommended to force recalcuation of formulas on workbook level using
Workbook.setForceFormulaRecalculation(boolean)to ensure that all cross-worksheet formuals and external dependencies are updated.- Specified by:
setForceFormulaRecalculationin interfaceSheet- Parameters:
value- true if the application will perform a full recalculation of this worksheet values when the workbook is opened- See Also:
Workbook.setForceFormulaRecalculation(boolean)
-
getForceFormulaRecalculation
public boolean getForceFormulaRecalculation()
Whether Excel will be asked to recalculate all formulas of this sheet when the workbook is opened. Note: This just returns if the sheet has the recalculate flag set and will still return false even if recalculation is enabled on workbook-level.- Specified by:
getForceFormulaRecalculationin interfaceSheet- Returns:
- true if the Sheet has the recalculate-flag set.
-
rowIterator
public Iterator<Row> rowIterator()
- Specified by:
rowIteratorin interfaceSheet- Returns:
- an iterator of the PHYSICAL rows. Meaning the 3rd element may not be the third row if say for instance the second row is undefined. Call getRowNum() on each row if you care which one it is.
-
spliterator
public Spliterator<Row> spliterator()
- Specified by:
spliteratorin interfaceIterable<Row>- Specified by:
spliteratorin interfaceSheet- Returns:
- a spliterator of the PHYSICAL rows. Meaning the 3rd element may not be the third row if say for instance the second row is undefined. Call getRowNum() on each row if you care which one it is.
- Since:
- POI 5.2.0
-
getAutobreaks
public boolean getAutobreaks()
Flag indicating whether the sheet displays Automatic Page Breaks.- Specified by:
getAutobreaksin interfaceSheet- Returns:
trueif the sheet displays Automatic Page Breaks.
-
setAutobreaks
public void setAutobreaks(boolean value)
Flag indicating whether the sheet displays Automatic Page Breaks.- Specified by:
setAutobreaksin interfaceSheet- Parameters:
value-trueif the sheet displays Automatic Page Breaks.
-
setColumnBreak
public void setColumnBreak(int column)
Sets a page break at the indicated column. Breaks occur above the specified row and left of the specified column inclusive. For example,sheet.setColumnBreak(2);breaks the sheet into two parts with columns A,B,C in the first and D,E,... in the second. Simuilar,sheet.setRowBreak(2);breaks the sheet into two parts with first three rows (rownum=1...3) in the first part and rows starting with rownum=4 in the second.- Specified by:
setColumnBreakin interfaceSheet- Parameters:
column- the column to break, inclusive
-
setColumnGroupCollapsed
public void setColumnGroupCollapsed(int columnNumber, boolean collapsed)- Specified by:
setColumnGroupCollapsedin interfaceSheet
-
setColumnHidden
public void setColumnHidden(int columnIndex, boolean hidden)Get the visibility state for a given column.- Specified by:
setColumnHiddenin interfaceSheet- Parameters:
columnIndex- - the column to get (0-based)hidden- - the visiblity state of the column
-
setColumnWidth
public void setColumnWidth(int columnIndex, int width)Set the width (in units of 1/256th of a character width)The maximum column width for an individual cell is 255 characters. This value represents the number of characters that can be displayed in a cell that is formatted with the standard font (first font in the workbook).
Character width is defined as the maximum digit width of the numbers
0, 1, 2, ... 9as rendered using the default font (first font in the workbook).
Unless you are using a very special font, the default character is '0' (zero), this is true for Arial (default font font in HSSF) and Calibri (default font in XSSF)Please note, that the width set by this method includes 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines (Section 3.3.1.12 of the OOXML spec). This results is a slightly less value of visible characters than passed to this method (approx. 1/2 of a character).
To compute the actual number of visible characters, Excel uses the following formula (Section 3.3.1.12 of the OOXML spec):
width = Truncate([{Number of Visible Characters} * {Maximum Digit Width} + {5 pixel padding}]/{Maximum Digit Width}*256)/256Using the Calibri font as an example, the maximum digit width of 11 point font size is 7 pixels (at 96 dpi). If you set a column width to be eight characters wide, e.g.
setColumnWidth(columnIndex, 8*256), then the actual value of visible characters (the value shown in Excel) is derived from the following equation:Truncate([numChars*7+5]/7*256)/256 = 8;which gives7.29.- Specified by:
setColumnWidthin interfaceSheet- Parameters:
columnIndex- - the column to set (0-based)width- - the width in units of 1/256th of a character width- Throws:
IllegalArgumentException- if width > 255*256 (the maximum column width in Excel is 255 characters)
-
setDefaultColumnStyle
public void setDefaultColumnStyle(int column, CellStyle style)- Specified by:
setDefaultColumnStylein interfaceSheet
-
setDefaultColumnWidth
public void setDefaultColumnWidth(int width)
Specifies the number of characters of the maximum digit width of the normal style's font. This value does not include margin padding or extra padding for gridlines. It is only the number of characters.- Specified by:
setDefaultColumnWidthin interfaceSheet- Parameters:
width- the number of characters. Default value is8.
-
setDefaultRowHeight
public void setDefaultRowHeight(short height)
Set the default row height for the sheet (if the rows do not define their own height) in twips (1/20 of a point)- Specified by:
setDefaultRowHeightin interfaceSheet- Parameters:
height- default row height in twips (1/20 of a point)
-
setDefaultRowHeightInPoints
public void setDefaultRowHeightInPoints(float height)
Sets default row height measured in point size.- Specified by:
setDefaultRowHeightInPointsin interfaceSheet- Parameters:
height- default row height measured in point size.
-
setDisplayFormulas
public void setDisplayFormulas(boolean show)
Sets the flag indicating whether this sheet should display formulas.- Specified by:
setDisplayFormulasin interfaceSheet- Parameters:
show-trueif this sheet should display formulas.
-
setFitToPage
public void setFitToPage(boolean b)
Flag indicating whether the Fit to Page print option is enabled.- Specified by:
setFitToPagein interfaceSheet- Parameters:
b-trueif the Fit to Page print option is enabled.
-
setHorizontallyCenter
public void setHorizontallyCenter(boolean value)
Center on page horizontally when printing.- Specified by:
setHorizontallyCenterin interfaceSheet- Parameters:
value- whether to center on page horizontally when printing.
-
setVerticallyCenter
public void setVerticallyCenter(boolean value)
Whether the output is vertically centered on the page.- Specified by:
setVerticallyCenterin interfaceSheet- Parameters:
value- true to vertically center, false otherwise.
-
setRowGroupCollapsed
public void setRowGroupCollapsed(int rowIndex, boolean collapse)group the row It is possible for collapsed to be false and yet still have the rows in question hidden. This can be achieved by having a lower outline level collapsed, thus hiding all the child rows. Note that in this case, if the lowest level were expanded, the middle level would remain collapsed.- Specified by:
setRowGroupCollapsedin interfaceSheet- Parameters:
rowIndex- - the row involved, 0 basedcollapse- - boolean value for collapse
-
findEndOfRowOutlineGroup
public int findEndOfRowOutlineGroup(int row)
- Parameters:
row- the zero based row index to find from
-
setZoom
public void setZoom(int scale)
Window zoom magnification for current view representing percent values. Valid values range from 10 to 400. Horizontal & Vertical scale together. For example:10 - 10% 20 - 20% ... 100 - 100% ... 400 - 400%
Current view can be Normal, Page Layout, or Page Break Preview.- Specified by:
setZoomin interfaceSheet- Parameters:
scale- window zoom magnification- Throws:
IllegalArgumentException- if scale is invalid
-
copyRows
@Beta public void copyRows(List<? extends Row> srcRows, int destStartRow, CellCopyPolicy policy)
copyRows rows from srcRows to this sheet starting at destStartRow Additionally copies merged regions that are completely defined in these rows (ie. merged 2 cells on a row to be shifted).- Parameters:
srcRows- the rows to copy. Formulas will be offset by the difference in the row number of the first row in srcRows and destStartRow (even if srcRows are from a different sheet).destStartRow- the row in this sheet to paste the first row of srcRows the remainder of srcRows will be pasted below destStartRow per the cell copy policypolicy- is the cell copy policy, which can be used to merge the source and destination when the source is blank, copy styles only, paste as value, etc
-
copyRows
@Beta public void copyRows(int srcStartRow, int srcEndRow, int destStartRow, CellCopyPolicy cellCopyPolicy)
Copies rows between srcStartRow and srcEndRow to the same sheet, starting at destStartRow Convenience function forcopyRows(List, int, CellCopyPolicy)Equivalent to copyRows(getRows(srcStartRow, srcEndRow, false), destStartRow, cellCopyPolicy)- Parameters:
srcStartRow- the index of the first row to copy the cells from in this sheetsrcEndRow- the index of the last row to copy the cells from in this sheetdestStartRow- the index of the first row to copy the cells to in this sheetcellCopyPolicy- the policy to use to determine how cells are copied
-
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, it will shift rows up. Code ensures that rows don't wrap around. Calls shiftRows(startRow, endRow, n, false, false);Additionally, shifts merged regions that are completely defined in these rows (i.e. merged 2 cells on a row to be shifted).
-
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, it will shift rows up. Code ensures that rows don't wrap aroundAdditionally, shifts merged regions that are completely defined in these rows (i.e. merged 2 cells on a row to be shifted). All merged regions that are completely overlaid by shifting will be deleted.
- Specified by:
shiftRowsin interfaceSheet- Parameters:
startRow- the row to start shiftingendRow- the row to end shiftingn- the number of rows to shiftcopyRowHeight- whether to copy the row height during the shiftresetOriginalRowHeight- whether to set the original row's height to the default
-
shiftColumns
public void shiftColumns(int startColumn, int endColumn, int n)Shifts columns between startColumn and endColumn n number of columns. If you use a negative number, it will shift columns left. Code ensures that columns don't wrap around- Specified by:
shiftColumnsin interfaceSheet- Parameters:
startColumn- the column to start shiftingendColumn- the column to end shiftingn- length of the shifting step
-
showInPane
public void showInPane(int topRow, int leftCol)Location of the top left visible cell Location of the top left visible cell in the bottom right pane (when in Left-to-Right mode).- Specified by:
showInPanein interfaceSheet- Parameters:
topRow- the top row to show in desktop window paneleftCol- the left column to show in desktop window pane
-
ungroupColumn
public void ungroupColumn(int fromColumn, int toColumn)- Specified by:
ungroupColumnin interfaceSheet
-
ungroupRow
public void ungroupRow(int fromRow, int toRow)Ungroup a range of rows that were previously groupped- Specified by:
ungroupRowin interfaceSheet- Parameters:
fromRow- start row (0-based)toRow- end row (0-based)
-
getSheetTypeSheetViews
protected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews getSheetTypeSheetViews(boolean create)
-
isSelected
public boolean isSelected()
Returns a flag indicating whether this sheet is selected.When only 1 sheet is selected and active, this value should be in synch with the activeTab value. In case of a conflict, the Start Part setting wins and sets the active sheet tab.
Note: multiple sheets can be selected, but only one sheet can be active at one time.- Specified by:
isSelectedin interfaceSheet- Returns:
trueif this sheet is selected
-
setSelected
public void setSelected(boolean value)
Sets a flag indicating whether this sheet is selected.When only 1 sheet is selected and active, this value should be in synch with the activeTab value. In case of a conflict, the Start Part setting wins and sets the active sheet tab.
Note: multiple sheets can be selected, but only one sheet can be active at one time.- Specified by:
setSelectedin interfaceSheet- Parameters:
value-trueif this sheet is selected
-
addHyperlink
public void addHyperlink(XSSFHyperlink hyperlink)
Register a hyperlink in the collection of hyperlinks on this sheet. UseXSSFCell.setHyperlink(Hyperlink)if the hyperlink is just for that one cell. Use this method if you want to add a Hyperlink that covers a range of sells. If you use this method, you will need to callXSSFHyperlink.setCellReference(String)to explicitly cell the value, eg B2 or B2:C3 (the 4 cells with B2 at top left and C3 at bottom right)- Parameters:
hyperlink- the link to add
-
removeHyperlink
public void removeHyperlink(XSSFHyperlink hyperlink)
Remove a hyperlink in the collection of hyperlinks on this sheet.XSSFCell.removeHyperlink()can be used if the hyperlink is just for that one cell.- Parameters:
hyperlink- the link to remove- Since:
- POI 5.1.0
-
removeHyperlink
@Internal public void removeHyperlink(int row, int column)
Removes a hyperlink in the collection of hyperlinks on this sheet- Parameters:
row- row indexcolumn- column index
-
getActiveCell
public CellAddress getActiveCell()
Return location of the active cell, e.g.A1.- Specified by:
getActiveCellin interfaceSheet- Returns:
- the location of the active cell.
-
setActiveCell
public void setActiveCell(CellAddress address)
- Specified by:
setActiveCellin interfaceSheet
-
hasComments
public boolean hasComments()
Does this sheet have any comments on it? We need to know, so we can decide about writing it to disk or not
-
getNumberOfComments
protected int getNumberOfComments()
-
getCommentsTable
protected Comments getCommentsTable(boolean create)
Returns the sheet's comments object if there is one, or null if not- Parameters:
create- create a new comments table if it does not exist
-
getSharedFormula
@Internal public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula getSharedFormula(int sid)
Return a master shared formula by index- Parameters:
sid- shared group index- Returns:
- a CTCellFormula bean holding shared formula or
nullif not found
-
commit
protected void commit() throws IOExceptionDescription copied from class:POIXMLDocumentPartSave the content in the underlying package part. Default implementation is empty meaning that the package part is left unmodified.Sub-classes should override and add logic to marshal the "model" into Ooxml4J.
For example, the code saving a generic XML entry may look as follows:
protected void commit() throws IOException { PackagePart part = getPackagePart(); try (OutputStream out = part.getOutputStream()) { XmlObject bean = getXmlBean(); //the "model" which holds changes in memory bean.save(out, DEFAULT_XML_OPTIONS); } }- Overrides:
commitin classPOIXMLDocumentPart- Throws:
IOException- a subclass may throw an IOException if the changes can't be committed
-
write
protected void write(OutputStream out) throws IOException
- Throws:
IOException
-
isAutoFilterLocked
public boolean isAutoFilterLocked()
- Returns:
- true when Autofilters are locked and the sheet is protected.
-
isDeleteColumnsLocked
public boolean isDeleteColumnsLocked()
- Returns:
- true when Deleting columns is locked and the sheet is protected.
-
isDeleteRowsLocked
public boolean isDeleteRowsLocked()
- Returns:
- true when Deleting rows is locked and the sheet is protected.
-
isFormatCellsLocked
public boolean isFormatCellsLocked()
- Returns:
- true when Formatting cells is locked and the sheet is protected.
-
isFormatColumnsLocked
public boolean isFormatColumnsLocked()
- Returns:
- true when Formatting columns is locked and the sheet is protected.
-
isFormatRowsLocked
public boolean isFormatRowsLocked()
- Returns:
- true when Formatting rows is locked and the sheet is protected.
-
isInsertColumnsLocked
public boolean isInsertColumnsLocked()
- Returns:
- true when Inserting columns is locked and the sheet is protected.
-
isInsertHyperlinksLocked
public boolean isInsertHyperlinksLocked()
- Returns:
- true when Inserting hyperlinks is locked and the sheet is protected.
-
isInsertRowsLocked
public boolean isInsertRowsLocked()
- Returns:
- true when Inserting rows is locked and the sheet is protected.
-
isPivotTablesLocked
public boolean isPivotTablesLocked()
- Returns:
- true when Pivot tables are locked and the sheet is protected.
-
isSortLocked
public boolean isSortLocked()
- Returns:
- true when Sorting is locked and the sheet is protected.
-
isObjectsLocked
public boolean isObjectsLocked()
- Returns:
- true when Objects are locked and the sheet is protected.
-
isScenariosLocked
public boolean isScenariosLocked()
- Returns:
- true when Scenarios are locked and the sheet is protected.
-
isSelectLockedCellsLocked
public boolean isSelectLockedCellsLocked()
- Returns:
- true when Selection of locked cells is locked and the sheet is protected.
-
isSelectUnlockedCellsLocked
public boolean isSelectUnlockedCellsLocked()
- Returns:
- true when Selection of unlocked cells is locked and the sheet is protected.
-
isSheetLocked
public boolean isSheetLocked()
- Returns:
- true when Sheet is Protected.
-
enableLocking
public void enableLocking()
Enable sheet protection
-
disableLocking
public void disableLocking()
Disable sheet protection
-
lockAutoFilter
public void lockAutoFilter(boolean enabled)
Enable or disable Autofilters locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockDeleteColumns
public void lockDeleteColumns(boolean enabled)
Enable or disable Deleting columns locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockDeleteRows
public void lockDeleteRows(boolean enabled)
Enable or disable Deleting rows locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockFormatCells
public void lockFormatCells(boolean enabled)
Enable or disable Formatting cells locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockFormatColumns
public void lockFormatColumns(boolean enabled)
Enable or disable Formatting columns locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockFormatRows
public void lockFormatRows(boolean enabled)
Enable or disable Formatting rows locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockInsertColumns
public void lockInsertColumns(boolean enabled)
Enable or disable Inserting columns locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockInsertHyperlinks
public void lockInsertHyperlinks(boolean enabled)
Enable or disable Inserting hyperlinks locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockInsertRows
public void lockInsertRows(boolean enabled)
Enable or disable Inserting rows locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockPivotTables
public void lockPivotTables(boolean enabled)
Enable or disable Pivot Tables locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockSort
public void lockSort(boolean enabled)
Enable or disable Sort locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockObjects
public void lockObjects(boolean enabled)
Enable or disable Objects locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockScenarios
public void lockScenarios(boolean enabled)
Enable or disable Scenarios locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockSelectLockedCells
public void lockSelectLockedCells(boolean enabled)
Enable or disable Selection of locked cells locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
lockSelectUnlockedCells
public void lockSelectUnlockedCells(boolean enabled)
Enable or disable Selection of unlocked cells locking. This does not modify sheet protection status. To enforce this un-/locking, calldisableLocking()orenableLocking()
-
setArrayFormula
public CellRange<XSSFCell> setArrayFormula(String formula, CellRangeAddress range)
- Specified by:
setArrayFormulain interfaceSheet
-
removeArrayFormula
public CellRange<XSSFCell> removeArrayFormula(Cell cell)
- Specified by:
removeArrayFormulain interfaceSheet
-
getDataValidationHelper
public DataValidationHelper getDataValidationHelper()
- Specified by:
getDataValidationHelperin interfaceSheet
-
getDataValidations
public List<XSSFDataValidation> getDataValidations()
- Specified by:
getDataValidationsin interfaceSheet
-
addValidationData
public void addValidationData(DataValidation dataValidation)
- Specified by:
addValidationDatain interfaceSheet
-
setAutoFilter
public XSSFAutoFilter setAutoFilter(CellRangeAddress range)
- Specified by:
setAutoFilterin interfaceSheet
-
createTable
public XSSFTable createTable(AreaReference tableArea)
Creates a new Table, and associates it with this Sheet.The table is assigned a default display name (since 4.1.1) which can be overridden by calling
setDisplayName. The default display name is guaranteed to not conflict with the names of anyXSSFNameorXSSFTablein the workbook.- Parameters:
tableArea- the area that the table should cover, should not be null- Returns:
- the created table
- Since:
- 4.0.0
-
removeTable
public void removeTable(XSSFTable t)
Remove table references and relations- Parameters:
t- table to remove
-
getSheetConditionalFormatting
public XSSFSheetConditionalFormatting getSheetConditionalFormatting()
- Specified by:
getSheetConditionalFormattingin interfaceSheet
-
getTabColor
public XSSFColor getTabColor()
Get background color of the sheet tab. Returnsnullif no sheet tab color is set.- Returns:
- the background color of the sheet tab
-
setTabColor
public void setTabColor(XSSFColor color)
Set background color of the sheet tab- Parameters:
color- the color to set
-
getRepeatingRows
public CellRangeAddress getRepeatingRows()
- Specified by:
getRepeatingRowsin interfaceSheet
-
getRepeatingColumns
public CellRangeAddress getRepeatingColumns()
- Specified by:
getRepeatingColumnsin interfaceSheet
-
setRepeatingRows
public void setRepeatingRows(CellRangeAddress rowRangeRef)
- Specified by:
setRepeatingRowsin interfaceSheet
-
setRepeatingColumns
public void setRepeatingColumns(CellRangeAddress columnRangeRef)
- Specified by:
setRepeatingColumnsin interfaceSheet
-
createPivotTable
@Beta public XSSFPivotTable createPivotTable(AreaReference source, CellReference position, Sheet sourceSheet)
Create a pivot table using the AreaReference range on sourceSheet, at the given position. If the source reference contains a sheet name, it must match the sourceSheet- Parameters:
source- location of pivot dataposition- A reference to the top left cell where the pivot table will startsourceSheet- The sheet containing the source data, if the source reference doesn't contain a sheet name- Returns:
- The pivot table
- Throws:
IllegalArgumentException- if source references a sheet different than sourceSheet
-
createPivotTable
@Beta public XSSFPivotTable createPivotTable(AreaReference source, CellReference position)
Create a pivot table using the AreaReference range, at the given position. If the source reference contains a sheet name, that sheet is used, otherwise this sheet is assumed as the source sheet.- Parameters:
source- location of pivot dataposition- A reference to the top left cell where the pivot table will start- Returns:
- The pivot table
-
createPivotTable
@Beta public XSSFPivotTable createPivotTable(Name source, CellReference position, Sheet sourceSheet)
Create a pivot table using the Name range reference on sourceSheet, at the given position. If the source reference contains a sheet name, it must match the sourceSheet- Parameters:
source- location of pivot dataposition- A reference to the top left cell where the pivot table will startsourceSheet- The sheet containing the source data, if the source reference doesn't contain a sheet name- Returns:
- The pivot table
- Throws:
IllegalArgumentException- if source references a sheet different than sourceSheet
-
createPivotTable
@Beta public XSSFPivotTable createPivotTable(Name source, CellReference position)
Create a pivot table using the Name range, at the given position. If the source reference contains a sheet name, that sheet is used, otherwise this sheet is assumed as the source sheet.- Parameters:
source- location of pivot dataposition- A reference to the top left cell where the pivot table will start- Returns:
- The pivot table
-
createPivotTable
@Beta public XSSFPivotTable createPivotTable(Table source, CellReference position)
Create a pivot table using the Table, at the given position. Tables are required to have a sheet reference, so no additional logic around reference sheet is needed.- Parameters:
source- location of pivot dataposition- A reference to the top left cell where the pivot table will start- Returns:
- The pivot table
-
getPivotTables
@Beta public List<XSSFPivotTable> getPivotTables()
Returns all the pivot tables for this Sheet
-
getColumnOutlineLevel
public int getColumnOutlineLevel(int columnIndex)
- Specified by:
getColumnOutlineLevelin interfaceSheet
-
addIgnoredErrors
public void addIgnoredErrors(CellReference cell, IgnoredErrorType... ignoredErrorTypes)
Add ignored errors (usually to suppress them in the UI of a consuming application).- Parameters:
cell- Cell.ignoredErrorTypes- Types of error to ignore there.
-
addIgnoredErrors
public void addIgnoredErrors(CellRangeAddress region, IgnoredErrorType... ignoredErrorTypes)
Ignore errors across a range of cells.- Parameters:
region- Range of cells.ignoredErrorTypes- Types of error to ignore there.
-
getIgnoredErrors
public Map<IgnoredErrorType,Set<CellRangeAddress>> getIgnoredErrors()
Returns the errors currently being ignored and the ranges where they are ignored.- Returns:
- Map of error type to the range(s) where they are ignored.
-
onSheetDelete
protected void onSheetDelete()
called when a sheet is being deleted/removed from a workbook, to clean up relations and other document pieces tied to the sheet
-
onDeleteFormula
protected void onDeleteFormula(XSSFCell cell, BaseXSSFEvaluationWorkbook evalWb)
when a cell with a 'master' shared formula is removed, the next cell in the range becomes the master- Parameters:
cell- The cell that is removedevalWb- BaseXSSFEvaluationWorkbook in use, if one exists
-
readOleObject
protected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOleObject readOleObject(long shapeId)
Determine the OleObject which links shapes with embedded resources- Parameters:
shapeId- the shape id- Returns:
- the CTOleObject of the shape
-
getHeaderFooterProperties
public XSSFHeaderFooterProperties getHeaderFooterProperties()
-
-