public class Worksheet extends Object implements Closeable
Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_COL_WIDTH
Default column width in Excel.
|
static int |
MAX_COL_WIDTH
Maximum column width in Excel.
|
static int |
MAX_COLS
Maximum number of columns in Excel.
|
static double |
MAX_ROW_HEIGHT
Maximum row height in Excel.
|
static int |
MAX_ROWS
Maximum number of rows in Excel.
|
Modifier and Type | Method and Description |
---|---|
void |
addNamedRange(Range range,
String name)
Add the given range to this sheet's
list of named ranges under the provided name.
|
void |
bottomMargin(float margin)
Set bottom margin.
|
void |
close() |
void |
comment(int r,
int c,
String comment)
Assign a note/comment to a cell.
|
void |
finish()
Finish the construction of this worksheet.
|
void |
firstPageNumber(int pageNumber) |
void |
fitToHeight(Short fitToHeight) |
void |
fitToWidth(Short fitToWidth) |
void |
flush()
Write all the rows currently in memory to the workbook's output stream.
|
void |
footer(String text,
Position position)
Set footer text.
|
void |
footer(String text,
Position position,
int fontSize)
Set footer text with specified font size.
|
void |
footer(String text,
Position position,
String fontName,
int fontSize)
Set footer text with specified font and size.
|
void |
footerMargin(float margin)
Set footer margin.
|
void |
formula(int r,
int c,
String expression)
Set the cell formula at the given coordinates.
|
void |
freezePane(int nLeftColumns,
int nTopRows)
Set freeze pane (rows and columns that remain when scrolling).
|
Range |
getAutoFilterRange()
Get cell range that autofilter is applied to.
|
String |
getName()
Get worksheet name.
|
Map<String,Range> |
getNamedRanges()
Get a list of named ranges.
|
org.dhatim.fastexcel.RepeatColRange |
getRepeatingCols()
Get repeating cols defined for the print setup.
|
org.dhatim.fastexcel.RepeatRowRange |
getRepeatingRows()
Get repeating rows defined for the print setup.
|
VisibilityState |
getVisibilityState() |
Workbook |
getWorkbook()
Get parent workbook.
|
void |
groupCols(int from,
int to) |
void |
groupRows(int from,
int to) |
void |
header(String text,
Position position)
Set header text with specified font and size.
|
void |
header(String text,
Position position,
int fontSize)
Set header text with specified font size.
|
void |
header(String text,
Position position,
String fontName,
int fontSize)
Set header text.
|
void |
headerMargin(float margin)
Set header margin.
|
void |
hideColumn(int column)
Hide the given column.
|
void |
hideGridLines()
Hide grid lines.
|
void |
hideRow(int row)
Hide the given row.
|
void |
hyperlink(int r,
int c,
HyperLink hyperLink) |
void |
inlineString(int r,
int c,
String value)
Set the cell value at the given coordinates.
|
void |
keepInActiveTab()
Keep this sheet in active tab.
|
void |
leftMargin(float margin)
Set left margin.
|
void |
pageOrientation(String orientation)
Set the page orientation.
|
void |
pageScale(int scale) |
void |
paperSize(PaperSize size)
Set the paper size.
|
void |
printInBlackAndWhite() |
void |
printInColor() |
void |
protect(String password)
Protects the sheet with a password.
|
void |
protect(String password,
Set<SheetProtectionOption> options)
Protects the sheet with a password.
|
void |
protect(String password,
SheetProtectionOption... options)
Protects the sheet with a password.
|
Range |
range(int top,
int left,
int bottom,
int right)
Create a new range of cells.
|
void |
removeAutoFilter()
Removes auto filter from sheet.
|
void |
repeatCols(int col) |
void |
repeatCols(int startCol,
int endCol) |
void |
repeatRows(int row) |
void |
repeatRows(int startRow,
int endRow) |
void |
rightMargin(float margin)
Set right margin.
|
void |
rowHeight(int r,
double height)
Specify the custom row height for a row
|
void |
setAutoFilter(int rowNumber,
int leftCellNumber,
int rightCellNumber)
Applies autofilter automatically based on provided header cells
|
void |
setAutoFilter(int topRowNumber,
int leftCellNumber,
int bottomRowNumber,
int rightCellNumber)
Applies autofilter specifically to the given cell range
|
void |
setAutoPageBreaks(Boolean autoPageBreaks) |
void |
setFitToPage(Boolean fitToPage) |
void |
setTabColor(String rgbColor) |
void |
setVisibilityState(VisibilityState visibilityState)
Sets the visibility state of the sheet
|
void |
setZoom(int zoomPercent)
Set sheet view zoom level in percent.
|
void |
showColumn(int column)
Show the given column.
|
void |
showRow(int row)
Show the given row.
|
ColumnStyleSetter |
style(int c)
Get a new style setter for a column.
|
StyleSetter |
style(int r,
int c)
Get a new style setter for a cell.
|
void |
topMargin(float margin)
Set top margin.
|
void |
unfreeze()
Unfreeze any frozen rows, or columns.
|
Object |
value(int r,
int c)
Get the cell value (or formula) at the given coordinates.
|
void |
value(int r,
int c,
Boolean value)
Set the cell value at the given coordinates.
|
void |
value(int r,
int c,
Date value)
Set the cell value at the given coordinates.
|
void |
value(int r,
int c,
LocalDate value)
Set the cell value at the given coordinates.
|
void |
value(int r,
int c,
LocalDateTime value)
Set the cell value at the given coordinates.
|
void |
value(int r,
int c,
Number value)
Set the cell value at the given coordinates.
|
void |
value(int r,
int c,
String value)
Set the cell value at the given coordinates.
|
void |
value(int r,
int c,
ZonedDateTime value)
Set the cell value at the given coordinates.
|
void |
width(int c,
double width)
Specify the width for the given column.
|
public static final int MAX_ROWS
public static final int MAX_COLS
public static final int MAX_COL_WIDTH
public static final double DEFAULT_COL_WIDTH
public static final double MAX_ROW_HEIGHT
public String getName()
public org.dhatim.fastexcel.RepeatRowRange getRepeatingRows()
public Range getAutoFilterRange()
public org.dhatim.fastexcel.RepeatColRange getRepeatingCols()
public Map<String,Range> getNamedRanges()
public Workbook getWorkbook()
public void setVisibilityState(VisibilityState visibilityState)
This is done by setting the state
attribute in the workbook.xml.
visibilityState
- New visibility state for this sheet.public VisibilityState getVisibilityState()
public void hideRow(int row)
row
- Zero-based row numberpublic void showRow(int row)
row
- Zero-based row numberpublic void hideColumn(int column)
column
- Zero-based column numberpublic void showColumn(int column)
column
- Zero-based column numberpublic void keepInActiveTab()
public void protect(String password)
SheetProtectionOption
s and
'sheet'. (Note that this is not very secure and only meant for discouraging changes.)password
- The password to use.public void protect(String password, SheetProtectionOption... options)
password
- The password to use.options
- An array of all the SheetProtectionOption
s to protect.public void protect(String password, Set<SheetProtectionOption> options)
password
- The password to use.options
- A Set
of all the SheetProtectionOption
s to protect.public void setAutoFilter(int topRowNumber, int leftCellNumber, int bottomRowNumber, int rightCellNumber)
topRowNumber
- The first row (header) where filter will be initializedleftCellNumber
- Left cell number where filter will be initializedbottomRowNumber
- The last row (containing values) that will be includedrightCellNumber
- Right cell number where filter will be initializedpublic void setAutoFilter(int rowNumber, int leftCellNumber, int rightCellNumber)
rowNumber
- Row numberleftCellNumber
- Left cell number where filter will be initializedrightCellNumber
- Right cell number where filter will be initializedpublic void removeAutoFilter()
public void width(int c, double width)
The maximum column width in excel is 255. The colum width in excel is the number of characters that can be displayed with the standard font (first font in the workbook).
Note: The xml spec specifies additional padding for each cell (Section 3.3.1.12 of the OOXML spec) which will result in slightly less characters being displayed then what is given here.
c
- Zero-based column numberwidth
- The width of the column in character widthspublic void rowHeight(int r, double height)
The maximum value for row height is 409.5
r
- Zero-based row numberheight
- New row heightpublic void value(int r, int c, String value)
r
- Zero-based row number.c
- Zero-based column number.value
- Cell value.public void value(int r, int c, Number value)
r
- Zero-based row number.c
- Zero-based column number.value
- Cell value.public void value(int r, int c, Boolean value)
r
- Zero-based row number.c
- Zero-based column number.value
- Cell value.public void value(int r, int c, Date value)
r
- Zero-based row number.c
- Zero-based column number.value
- Cell value. Note Excel timestamps do not carry
any timezone information; Date
values are converted to an Excel
serial number with the system timezone. If you need a specific timezone,
prefer passing a ZonedDateTime
.public void value(int r, int c, LocalDateTime value)
r
- Zero-based row number.c
- Zero-based column number.value
- Cell value. Note Excel timestamps do not carry
any timezone information; Date
values are converted to an Excel
serial number with the system timezone. If you need a specific timezone,
prefer passing a ZonedDateTime
.public void value(int r, int c, LocalDate value)
r
- Zero-based row number.c
- Zero-based column number.value
- Cell value. Note Excel timestamps do not carry
any timezone information; Date
values are converted to an Excel
serial number with the system timezone. If you need a specific timezone,
prefer passing a ZonedDateTime
.public void value(int r, int c, ZonedDateTime value)
r
- Zero-based row number.c
- Zero-based column number.value
- Cell value.public Object value(int r, int c)
r
- Zero-based row number.c
- Zero-based column number.Formula
).public void hyperlink(int r, int c, HyperLink hyperLink)
public void formula(int r, int c, String expression)
r
- Zero-based row number.c
- Zero-based column number.expression
- Cell formula expression.public void inlineString(int r, int c, String value)
r
- Zero-based row number.c
- Zero-based column number.value
- Cell value.public StyleSetter style(int r, int c)
r
- Zero-based row number.c
- Zero-based column number.public ColumnStyleSetter style(int c)
c
- Zero-based column number.public Range range(int top, int left, int bottom, int right)
top
<= bottom
and left
<=
right
.top
- Top row.left
- Left column.bottom
- Bottom row.right
- Right column.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void finish() throws IOException
IOException
- If an I/O error occurs.public void flush() throws IOException
flush()
, all the rows created so far become inaccessible.IOException
- If an I/O error occurs.public void comment(int r, int c, String comment)
Comments are stored in memory till call to close()
(or the old fashion way finish()
) - calling flush()
does not write them to output stream.
r
- Zero-based row number.c
- Zero-based column number.comment
- Note textpublic void hideGridLines()
public void setZoom(int zoomPercent)
zoomPercent
- - zoom level from 10 to 400public void setAutoPageBreaks(Boolean autoPageBreaks)
public void setFitToPage(Boolean fitToPage)
public void freezePane(int nLeftColumns, int nTopRows)
nLeftColumns
- - number of columns from the left that will remain frozennTopRows
- - number of rows from the top that will remain frozenpublic void unfreeze()
public void headerMargin(float margin)
margin
- - header margin in inchespublic void footerMargin(float margin)
margin
- - footer page margin in inchespublic void topMargin(float margin)
margin
- - top page margin in inchespublic void bottomMargin(float margin)
margin
- - bottom page margin in inchespublic void leftMargin(float margin)
margin
- - left page margin in inchespublic void rightMargin(float margin)
margin
- - right page margin in inchespublic void pageOrientation(String orientation)
orientation
- New page orientation for this worksheetpublic void paperSize(PaperSize size)
size
- New paper size for this worksheetpublic void pageScale(int scale)
scale
- = scaling factor for the print setup (between 1 and 100)public void firstPageNumber(int pageNumber)
pageNumber
- - first page number (default: 0)public void fitToHeight(Short fitToHeight)
public void fitToWidth(Short fitToWidth)
public void printInBlackAndWhite()
public void printInColor()
public void repeatRows(int startRow, int endRow)
public void repeatRows(int row)
public void repeatCols(int startCol, int endCol)
public void repeatCols(int col)
public void footer(String text, Position position)
text
- - text input form or custom textposition
- - Position.LEFT/RIGHT/CENTER enumpublic void footer(String text, Position position, int fontSize)
text
- - text input form or custom textposition
- - Position.LEFT/RIGHT/CENTER enumfontSize
- - integer describing font sizepublic void footer(String text, Position position, String fontName, int fontSize)
text
- - text input form or custom textposition
- - Position.LEFT/RIGHT/CENTER enumfontName
- - font name (e.g., "Arial")fontSize
- - integer describing font sizepublic void header(String text, Position position, String fontName, int fontSize)
text
- - text input form or custom textposition
- - Position.LEFT/RIGHT/CENTER enumfontName
- - font name (e.g., "Arial")fontSize
- - integer describing font sizepublic void header(String text, Position position, int fontSize)
text
- - text input form or custom textposition
- - Position.LEFT/RIGHT/CENTER enumfontSize
- - integer describing font sizepublic void header(String text, Position position)
text
- - text input form or custom textposition
- - Position.LEFT/RIGHT/CENTER enumpublic void addNamedRange(Range range, String name)
range
- Range of cells that needs to be named.name
- String representing the given cell range's name.public void groupCols(int from, int to)
public void groupRows(int from, int to)
public void setTabColor(String rgbColor)
rgbColor
- FFF381E0Copyright © 2023. All rights reserved.