|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Sheet
High level representation of a Excel 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.
Field Summary | |
---|---|
static short |
BottomMargin
|
static short |
FooterMargin
|
static short |
HeaderMargin
|
static short |
LeftMargin
|
static byte |
PANE_LOWER_LEFT
|
static byte |
PANE_LOWER_RIGHT
|
static byte |
PANE_UPPER_LEFT
|
static byte |
PANE_UPPER_RIGHT
|
static short |
RightMargin
|
static short |
TopMargin
|
Method Summary | |
---|---|
int |
addMergedRegion(CellRangeAddress region)
Adds a merged region of cells (hence those cells form one) |
void |
addValidationData(DataValidation dataValidation)
Creates a data validation object |
void |
autoSizeColumn(int column)
Adjusts the column width to fit the contents. |
void |
autoSizeColumn(int column,
boolean useMergedCells)
Adjusts the column width to fit the contents. |
Drawing |
createDrawingPatriarch()
Creates the top-level drawing patriarch. |
void |
createFreezePane(int colSplit,
int rowSplit)
Creates a split (freezepane). |
void |
createFreezePane(int colSplit,
int rowSplit,
int leftmostColumn,
int topRow)
Creates a split (freezepane). |
Row |
createRow(int rownum)
Create a new row within the sheet and return the high level representation |
void |
createSplitPane(int xSplitPos,
int ySplitPos,
int leftmostColumn,
int topRow,
int activePane)
Creates a split pane. |
boolean |
getAutobreaks()
Flag indicating whether the sheet displays Automatic Page Breaks. |
Comment |
getCellComment(int row,
int column)
Returns cell comment for the specified row and column |
int[] |
getColumnBreaks()
Retrieves all the vertical page breaks |
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 |
int |
getColumnWidth(int columnIndex)
get the width (in units of 1/256th of a character width ) |
DataValidationHelper |
getDataValidationHelper()
|
int |
getDefaultColumnWidth()
Get the default column width for the sheet (if the columns do not define their own width) in characters |
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) |
float |
getDefaultRowHeightInPoints()
Get the default row height for the sheet (if the rows do not define their own height) in points. |
boolean |
getDisplayGuts()
Get whether to display the guts or not, default value is true |
int |
getFirstRowNum()
Gets the first row on the sheet |
boolean |
getFitToPage()
Flag indicating whether the Fit to Page print option is enabled. |
Footer |
getFooter()
Gets the user model for the default document footer. |
boolean |
getForceFormulaRecalculation()
Whether Excel will be asked to recalculate all formulas in this sheet when the workbook is opened. |
Header |
getHeader()
Gets the user model for the default document header. |
boolean |
getHorizontallyCenter()
Determine whether printed output for this sheet will be horizontally centered. |
int |
getLastRowNum()
Gets the last row on the sheet |
short |
getLeftCol()
The left col in the visible view when the sheet is first viewed after opening it in a viewer |
double |
getMargin(short margin)
Gets the size of the margin in inches. |
CellRangeAddress |
getMergedRegion(int index)
Returns the merged region at the specified index |
int |
getNumMergedRegions()
Returns the number of merged regions |
PaneInformation |
getPaneInformation()
Returns the information regarding the currently configured pane (split or freeze) |
int |
getPhysicalNumberOfRows()
Returns the number of physically defined rows (NOT the number of rows in the sheet) |
PrintSetup |
getPrintSetup()
Gets the print setup object. |
boolean |
getProtect()
Answer whether protection is enabled or disabled |
Row |
getRow(int rownum)
Returns the logical row (not physical) 0-based. |
int[] |
getRowBreaks()
Retrieves all the horizontal page breaks |
boolean |
getRowSumsBelow()
Flag indicating whether summary rows appear below detail in an outline, when applying an outline. |
boolean |
getRowSumsRight()
Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline. |
boolean |
getScenarioProtect()
Answer whether scenario protection is enabled or disabled |
SheetConditionalFormatting |
getSheetConditionalFormatting()
The 'Conditional Formatting' facet for this Sheet |
java.lang.String |
getSheetName()
Returns the name of this sheet |
short |
getTopRow()
The top row in the visible view when the sheet is first viewed after opening it in a viewer |
boolean |
getVerticallyCenter()
Determine whether printed output for this sheet will be vertically centered. |
Workbook |
getWorkbook()
Return the parent workbook |
void |
groupColumn(int fromColumn,
int toColumn)
Create an outline for the provided column range. |
void |
groupRow(int fromRow,
int toRow)
Tie a range of rows together so that they can be collapsed or expanded |
boolean |
isColumnBroken(int column)
Determines if there is a page break at the indicated column |
boolean |
isColumnHidden(int columnIndex)
Get the hidden state for a given column |
boolean |
isDisplayFormulas()
Returns if formulas are displayed |
boolean |
isDisplayGridlines()
Returns if gridlines are displayed |
boolean |
isDisplayRowColHeadings()
Returns if RowColHeadings are displayed. |
boolean |
isDisplayZeros()
Gets the flag indicating whether the window should show 0 (zero) in cells containing zero value. |
boolean |
isPrintGridlines()
Gets the flag indicating whether this sheet displays the lines between rows and columns to make editing and reading easier. |
boolean |
isRightToLeft()
Whether the text is displayed in right-to-left mode in the window |
boolean |
isRowBroken(int row)
Determines if there is a page break at the indicated row |
boolean |
isSelected()
Note - this is not the same as whether the sheet is focused (isActive) |
void |
protectSheet(java.lang.String password)
Sets the protection enabled as well as the password |
CellRange<? extends Cell> |
removeArrayFormula(Cell cell)
Remove a Array Formula from this sheet. |
void |
removeColumnBreak(int column)
Removes a page break at the indicated column |
void |
removeMergedRegion(int index)
Removes a merged region of cells (hence letting them free) |
void |
removeRow(Row row)
Remove a row from this sheet. |
void |
removeRowBreak(int row)
Removes the page break at the indicated row |
java.util.Iterator<Row> |
rowIterator()
Returns an iterator of the physical rows |
CellRange<? extends Cell> |
setArrayFormula(java.lang.String formula,
CellRangeAddress range)
Sets array formula to specified region for result. |
void |
setAutobreaks(boolean value)
Flag indicating whether the sheet displays Automatic Page Breaks. |
AutoFilter |
setAutoFilter(CellRangeAddress range)
Enable filtering for a range of cells |
void |
setColumnBreak(int column)
Sets a page break at the indicated column. |
void |
setColumnGroupCollapsed(int columnNumber,
boolean collapsed)
Expands or collapses a column group. |
void |
setColumnHidden(int columnIndex,
boolean hidden)
Get the visibility state for a given column |
void |
setColumnWidth(int columnIndex,
int width)
Set the width (in units of 1/256th of a character width) |
void |
setDefaultColumnStyle(int column,
CellStyle style)
Sets the default column style for a given column. |
void |
setDefaultColumnWidth(int width)
Set the default column width for the sheet (if the columns do not define their own width) in characters |
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) |
void |
setDefaultRowHeightInPoints(float height)
Set the default row height for the sheet (if the rows do not define their own height) in points |
void |
setDisplayFormulas(boolean show)
Sets whether the formulas are shown in a viewer |
void |
setDisplayGridlines(boolean show)
Sets whether the gridlines are shown in a viewer |
void |
setDisplayGuts(boolean value)
Set whether to display the guts or not |
void |
setDisplayRowColHeadings(boolean show)
Sets whether the RowColHeadings are shown in a viewer |
void |
setDisplayZeros(boolean value)
Set whether the window should show 0 (zero) in cells containing zero value. |
void |
setFitToPage(boolean value)
Flag indicating whether the Fit to Page print option is enabled. |
void |
setForceFormulaRecalculation(boolean value)
Control if Excel should be asked to recalculate all formulas on this sheet when the workbook is opened. |
void |
setHorizontallyCenter(boolean value)
Determines whether the output is horizontally centered on the page. |
void |
setMargin(short margin,
double size)
Sets the size of the margin in inches. |
void |
setPrintGridlines(boolean show)
Sets the flag indicating whether this sheet should display the lines between rows and columns to make editing and reading easier. |
void |
setRightToLeft(boolean value)
Sets whether the worksheet is displayed from right to left instead of from left to right. |
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. |
void |
setRowGroupCollapsed(int row,
boolean collapse)
Set view state of a groupped range of rows |
void |
setRowSumsBelow(boolean value)
Flag indicating whether summary rows appear below detail in an outline, when applying an outline. |
void |
setRowSumsRight(boolean value)
Flag indicating whether summary columns appear to the right of detail in an outline, when applying an outline. |
void |
setSelected(boolean value)
Sets a flag indicating whether this sheet is selected. |
void |
setVerticallyCenter(boolean value)
Determines whether the output is vertically centered on the page. |
void |
setZoom(int numerator,
int denominator)
Sets the zoom magnication for the sheet. |
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 |
showInPane(short toprow,
short leftcol)
Sets desktop window pane display area, when the file is first opened in a viewer. |
void |
ungroupColumn(int fromColumn,
int toColumn)
Ungroup a range of columns that were previously groupped |
void |
ungroupRow(int fromRow,
int toRow)
Ungroup a range of rows that were previously groupped |
Methods inherited from interface java.lang.Iterable |
---|
iterator |
Field Detail |
---|
static final short LeftMargin
static final short RightMargin
static final short TopMargin
static final short BottomMargin
static final short HeaderMargin
static final short FooterMargin
static final byte PANE_LOWER_RIGHT
static final byte PANE_UPPER_RIGHT
static final byte PANE_LOWER_LEFT
static final byte PANE_UPPER_LEFT
Method Detail |
---|
Row createRow(int rownum)
rownum
- row number
removeRow(Row)
void removeRow(Row row)
row
- representing a row to remove.Row getRow(int rownum)
rownum
- row to get (0-based)
int getPhysicalNumberOfRows()
int getFirstRowNum()
int getLastRowNum()
void setColumnHidden(int columnIndex, boolean hidden)
columnIndex
- - the column to get (0-based)hidden
- - the visiblity state of the columnboolean isColumnHidden(int columnIndex)
columnIndex
- - the column to set (0-based)
false
if the column is visiblevoid setRightToLeft(boolean value)
value
- true for right to left, false otherwise.boolean isRightToLeft()
void setColumnWidth(int columnIndex, int 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, ... 9
as 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)/256
Using 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 gives 7.29
.
columnIndex
- - the column to set (0-based)width
- - the width in units of 1/256th of a character width
java.lang.IllegalArgumentException
- if width > 255*256 (the maximum column width in Excel is 255 characters)int getColumnWidth(int columnIndex)
Character width is defined as the maximum digit width
of the numbers 0, 1, 2, ... 9
as rendered
using the default font (first font in the workbook)
columnIndex
- - the column to set (0-based)
void setDefaultColumnWidth(int width)
width
- default column width measured in charactersint getDefaultColumnWidth()
short getDefaultRowHeight()
float getDefaultRowHeightInPoints()
void setDefaultRowHeight(short height)
height
- default row height measured in twips (1/20 of a point)void setDefaultRowHeightInPoints(float height)
height
- default row heightCellStyle getColumnStyle(int column)
int addMergedRegion(CellRangeAddress region)
region
- (rowfrom/colfrom-rowto/colto) to merge
void setVerticallyCenter(boolean value)
value
- true to vertically center, false otherwise.void setHorizontallyCenter(boolean value)
value
- true to horizontally center, false otherwise.boolean getHorizontallyCenter()
boolean getVerticallyCenter()
void removeMergedRegion(int index)
index
- of the region to unmergeint getNumMergedRegions()
CellRangeAddress getMergedRegion(int index)
java.util.Iterator<Row> rowIterator()
void setForceFormulaRecalculation(boolean value)
Calculating the formula values with FormulaEvaluator
is the
recommended solution, but this may be used for certain cases where
evaluation in POI is not possible.
Workbook.setForceFormulaRecalculation(boolean)
instead.
value
- true if the application will perform a full recalculation of
this worksheet values when the workbook is openedWorkbook.setForceFormulaRecalculation(boolean)
boolean getForceFormulaRecalculation()
void setAutobreaks(boolean value)
value
- true
if the sheet displays Automatic Page Breaks.void setDisplayGuts(boolean value)
value
- - guts or no gutsvoid setDisplayZeros(boolean value)
value
- whether to display or hide all zero values on the worksheetboolean isDisplayZeros()
void setFitToPage(boolean value)
value
- true
if the Fit to Page print option is enabled.void setRowSumsBelow(boolean value)
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.
value
- true
if row summaries appear below detail in the outlinevoid setRowSumsRight(boolean value)
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.
value
- true
if col summaries appear right of the detail in the outlineboolean getAutobreaks()
true
if the sheet displays Automatic Page Breaks.boolean getDisplayGuts()
boolean getFitToPage()
true
if the Fit to Page print option is enabled.boolean getRowSumsBelow()
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.
true
if row summaries appear below detail in the outlineboolean getRowSumsRight()
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.
true
if col summaries appear right of the detail in the outlineboolean isPrintGridlines()
true
if this sheet displays gridlines.to check if printing of gridlines is turned on or off
void setPrintGridlines(boolean show)
setPrintGridlines(boolean)
show
- true
if this sheet should display gridlines.setPrintGridlines(boolean)
PrintSetup getPrintSetup()
Header getHeader()
null
Footer getFooter()
null
void setSelected(boolean value)
Note: multiple sheets can be selected, but only one sheet can be active at one time.
value
- true
if this sheet is selectedWorkbook.setActiveSheet(int)
double getMargin(short margin)
margin
- which margin to get
void setMargin(short margin, double size)
margin
- which margin to getsize
- the size of the marginboolean getProtect()
void protectSheet(java.lang.String password)
password
- to set for protection. Pass null
to remove protectionboolean getScenarioProtect()
void setZoom(int numerator, int denominator)
numerator
- The numerator for the zoom magnification.denominator
- The denominator for the zoom magnification.short getTopRow()
short getLeftCol()
void showInPane(short toprow, short leftcol)
toprow
- the top row to show in desktop window paneleftcol
- the left column to show in desktop window panevoid shiftRows(int startRow, int endRow, int n)
Additionally shifts merged regions that are completely defined in these rows (ie. merged 2 cells on a row to be shifted).
startRow
- the row to start shiftingendRow
- the row to end shiftingn
- the number of rows to shiftvoid shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight)
Additionally shifts merged regions that are completely defined in these rows (ie. merged 2 cells on a row to be shifted).
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 defaultvoid createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow)
If both colSplit and rowSplit are zero then the existing freeze pane is removed
colSplit
- Horizonatal position of split.rowSplit
- Vertical position of split.leftmostColumn
- Left column visible in right pane.topRow
- Top row visible in bottom panevoid createFreezePane(int colSplit, int rowSplit)
If both colSplit and rowSplit are zero then the existing freeze pane is removed
colSplit
- Horizonatal position of split.rowSplit
- Vertical position of split.void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane)
xSplitPos
- Horizonatal 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_LEFTPANE_LOWER_LEFT
,
PANE_LOWER_RIGHT
,
PANE_UPPER_LEFT
,
PANE_UPPER_RIGHT
PaneInformation getPaneInformation()
void setDisplayGridlines(boolean show)
show
- whether to show gridlines or notboolean isDisplayGridlines()
void setDisplayFormulas(boolean show)
show
- whether to show formulas or notboolean isDisplayFormulas()
void setDisplayRowColHeadings(boolean show)
show
- whether to show RowColHeadings or notboolean isDisplayRowColHeadings()
void setRowBreak(int row)
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.
row
- the row to break, inclusiveboolean isRowBroken(int row)
row
- FIXME: Document this!
void removeRowBreak(int row)
row
- int[] getRowBreaks()
int[] getColumnBreaks()
void setColumnBreak(int column)
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.
column
- the column to break, inclusiveboolean isColumnBroken(int column)
column
- FIXME: Document this!
void removeColumnBreak(int column)
column
- void setColumnGroupCollapsed(int columnNumber, boolean collapsed)
columnNumber
- One of the columns in the group.collapsed
- true = collapse group, false = expand group.void groupColumn(int fromColumn, int toColumn)
fromColumn
- beginning of the column range.toColumn
- end of the column range.void ungroupColumn(int fromColumn, int toColumn)
fromColumn
- start column (0-based)toColumn
- end column (0-based)void groupRow(int fromRow, int toRow)
fromRow
- start row (0-based)toRow
- end row (0-based)void ungroupRow(int fromRow, int toRow)
fromRow
- start row (0-based)toRow
- end row (0-based)void setRowGroupCollapsed(int row, boolean collapse)
row
- start row of a groupped range of rows (0-based)collapse
- whether to expand/collapse the detail rowsvoid setDefaultColumnStyle(int column, CellStyle style)
column
- the column indexstyle
- the style to setvoid autoSizeColumn(int column)
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.
column
- the column indexvoid autoSizeColumn(int column, boolean useMergedCells)
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.
column
- the column indexuseMergedCells
- whether to use the contents of merged cells when calculating the width of the columnComment getCellComment(int row, int column)
null
if not foundDrawing createDrawingPatriarch()
Workbook getWorkbook()
java.lang.String getSheetName()
boolean isSelected()
true
if this sheet is currently selectedCellRange<? extends Cell> setArrayFormula(java.lang.String formula, CellRangeAddress range)
formula
- text representation of the formularange
- Region of array formula for result.
CellRange
of cells affected by this changeCellRange<? extends Cell> removeArrayFormula(Cell cell)
cell
- any cell within Array Formula range
CellRange
of cells affected by this changeDataValidationHelper getDataValidationHelper()
void addValidationData(DataValidation dataValidation)
dataValidation
- The Data validation object settingsAutoFilter setAutoFilter(CellRangeAddress range)
range
- the range of cells to filterSheetConditionalFormatting getSheetConditionalFormatting()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |