Package io.github.dornol.excelkit.excel
Class SheetContext
java.lang.Object
io.github.dornol.excelkit.excel.SheetContext
Provides contextual information passed to
BeforeHeaderWriter and
AfterDataWriter callbacks, including the current sheet, workbook,
row position, and column metadata.
A new instance is created for each callback invocation so that the sheet reference is always up-to-date (e.g. after sheet rollover).
- Since:
- 0.3.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcolumnLetter(int colIndex) Converts a zero-based column index to an Excel column letter.intReturns the number of columns configured for this sheet.Returns an unmodifiable list of column header names, in order.intReturns the current row index available for writing.intReturns the header row index (zero-based) for this sheet.org.apache.poi.xssf.streaming.SXSSFSheetgetSheet()Returns the current sheet being written to.org.apache.poi.xssf.streaming.SXSSFWorkbookReturns the workbook (useful for creating CellStyles, etc.).groupRows(int firstRow, int lastRow) Groups (outlines) a range of rows so they can be collapsed/expanded in Excel.groupRows(int firstRow, int lastRow, boolean collapsed) Groups (outlines) a range of rows, optionally collapsing them.mergeCells(int firstRow, int lastRow, int firstCol, int lastCol) Merges a rectangular region of cells identified by zero-based row and column indices.mergeCells(String cellRange) Merges a rectangular region of cells identified by an Excel-style range string such as"A1:C3".namedRange(String name, int col, int firstRow, int lastRow) Creates a workbook-scoped named range for a column range on the current sheet.namedRange(String name, String reference) Creates a workbook-scoped named range with the given reference formula.
-
Method Details
-
getSheet
public org.apache.poi.xssf.streaming.SXSSFSheet getSheet()Returns the current sheet being written to.- Returns:
- the current sheet
-
getWorkbook
public org.apache.poi.xssf.streaming.SXSSFWorkbook getWorkbook()Returns the workbook (useful for creating CellStyles, etc.).- Returns:
- the workbook
-
getCurrentRow
public int getCurrentRow()Returns the current row index available for writing.- Returns:
- the current row index
-
getColumnCount
public int getColumnCount()Returns the number of columns configured for this sheet.- Returns:
- the column count
-
getHeaderRowIndex
public int getHeaderRowIndex()Returns the header row index (zero-based) for this sheet.- Returns:
- the header row index
-
getColumnNames
Returns an unmodifiable list of column header names, in order.- Returns:
- the column names
-
mergeCells
Merges a rectangular region of cells identified by zero-based row and column indices.Example – merge the first three columns of row 0:
ctx.mergeCells(0, 0, 0, 2);- Parameters:
firstRow- zero-based index of the first row in the regionlastRow- zero-based index of the last row in the regionfirstCol- zero-based index of the first column in the regionlastCol- zero-based index of the last column in the region- Returns:
- this
SheetContextfor method chaining
-
mergeCells
Merges a rectangular region of cells identified by an Excel-style range string such as"A1:C3".Example – merge cells A1 through C1:
ctx.mergeCells("A1:C1");- Parameters:
cellRange- an Excel-notation range (e.g."A1:C3")- Returns:
- this
SheetContextfor method chaining
-
groupRows
Groups (outlines) a range of rows so they can be collapsed/expanded in Excel.Typically called from an
AfterDataWritercallback.- Parameters:
firstRow- zero-based index of the first row to grouplastRow- zero-based index of the last row to group- Returns:
- this
SheetContextfor method chaining - Since:
- 0.7.0
-
groupRows
Groups (outlines) a range of rows, optionally collapsing them.- Parameters:
firstRow- zero-based index of the first row to grouplastRow- zero-based index of the last row to groupcollapsed- whether the group should be initially collapsed- Returns:
- this
SheetContextfor method chaining - Since:
- 0.7.0
-
namedRange
Creates a workbook-scoped named range with the given reference formula.- Parameters:
name- the name for the range (e.g., "Categories")reference- the reference formula (e.g., "Sheet1!$A$1:$A$10")- Returns:
- this
SheetContextfor method chaining
-
namedRange
Creates a workbook-scoped named range for a column range on the current sheet.- Parameters:
name- the name for the rangecol- zero-based column indexfirstRow- zero-based first row indexlastRow- zero-based last row index- Returns:
- this
SheetContextfor method chaining
-
columnLetter
Converts a zero-based column index to an Excel column letter.Examples:
- 0 → "A"
- 1 → "B"
- 25 → "Z"
- 26 → "AA"
- Parameters:
colIndex- zero-based column index- Returns:
- the Excel column letter(s)
-