Package ortus.boxlang.spreadsheet
Class SpreadsheetUtil
java.lang.Object
ortus.boxlang.spreadsheet.SpreadsheetUtil
This class provides spreadsheet utilities for the BoxLang runtime using Apache POI
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidaddImage(org.apache.poi.ss.usermodel.Sheet sheet, String filepath, int startRow, int startCol, int endRow, int endCol, org.apache.poi.ss.usermodel.Workbook workbook) Adds an image with custom anchor coordinatesstatic voidaddImage(org.apache.poi.ss.usermodel.Sheet sheet, String filepath, int row, int col, org.apache.poi.ss.usermodel.Workbook workbook) Adds an image to a sheet at a specified cell locationstatic voidaddPrintGridlines(org.apache.poi.ss.usermodel.Sheet sheet) Adds print gridlines to the sheet (gridlines will print when document is printed).static voidautoSizeColumn(org.apache.poi.ss.usermodel.Sheet sheet, int column) Auto-sizes a specific column in the specified sheetstatic voidautoSizeColumn(org.apache.poi.ss.usermodel.Workbook workbook, int column) Auto-sizes a specific column in the active sheetstatic voidautoSizeColumns(org.apache.poi.ss.usermodel.Sheet sheet) Auto-sizes all columns in the specified sheetstatic voidautoSizeColumns(org.apache.poi.ss.usermodel.Workbook workbook) Auto-sizes all columns in the active sheetstatic voidclearCell(org.apache.poi.ss.usermodel.Sheet sheet, int row, int col) Clears the specified cell of all styles and valuesstatic voidclearCellRange(org.apache.poi.ss.usermodel.Sheet sheet, int startRow, int startCol, int endRow, int endCol) Clears a range of cells of all styles and valuesstatic voidcreateSplitPane(org.apache.poi.ss.usermodel.Sheet sheet, int xSplitPos, int ySplitPos, int leftmostColumn, int topRow) Creates a split pane in a sheet with default active panestatic voidcreateSplitPane(org.apache.poi.ss.usermodel.Sheet sheet, int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane) Creates a split pane in a sheetstatic org.apache.poi.ss.usermodel.WorkbookcreateWorkbook(boolean xmlFormat, String sheetName) Creates a new workbook based on the specified formatstatic org.apache.poi.ss.usermodel.WorkbookcreateXlsWorkbook(String sheetName) Creates a new .xls workbookstatic org.apache.poi.ss.usermodel.WorkbookcreateXlsxWorkbook(String sheetName) Creates a new .xlsx workbookstatic voiddeleteColumn(org.apache.poi.ss.usermodel.Sheet sheet, int column) Deletes a column by clearing all cells in that column Note: Apache POI doesn't support true column deletion, so we clear the column contentstatic voiddeleteColumns(org.apache.poi.ss.usermodel.Sheet sheet, int startColumn, int endColumn) Deletes multiple columns by clearing all cells in those columnsstatic voidformatCell(org.apache.poi.ss.usermodel.Cell cell, ortus.boxlang.runtime.types.IStruct format) Applies formatting to a specific cell based on a format structurestatic voidformatCellRange(org.apache.poi.ss.usermodel.Sheet sheet, ortus.boxlang.runtime.types.IStruct format, int startRow, int startCol, int endRow, int endCol, org.apache.poi.ss.usermodel.Workbook workbook) Formats a range of cells with a single format structstatic voidformatColumn(org.apache.poi.ss.usermodel.Sheet sheet, int column, ortus.boxlang.runtime.types.IStruct format) Formats all cells in a single columnstatic voidformatColumns(org.apache.poi.ss.usermodel.Sheet sheet, String columns, ortus.boxlang.runtime.types.IStruct format) Formats all cells in multiple columns specified by a comma-separated string or range Format: "1,3,5" or "1-5,7-10" or combinations like "1-3,5,7-10"static voidformatRow(org.apache.poi.ss.usermodel.Sheet sheet, int row, ortus.boxlang.runtime.types.IStruct format) Formats all cells in a single rowstatic voidformatRows(org.apache.poi.ss.usermodel.Sheet sheet, String rows, ortus.boxlang.runtime.types.IStruct format) Formats all cells in multiple rows specified by a comma-separated string or range Format: "1,3,5" or "1-5,7-10" or combinations like "1-3,5,7-10"static ortus.boxlang.runtime.types.IStructgetActiveCell(org.apache.poi.ss.usermodel.Sheet sheet) Gets the currently active/selected cell in a sheetstatic org.apache.poi.ss.usermodel.SheetgetActiveSheet(org.apache.poi.ss.usermodel.Workbook workbook) Gets the active sheet from the workbookstatic ortus.boxlang.runtime.types.ArraygetAllCellComments(org.apache.poi.ss.usermodel.Sheet sheet) Get all cell comments from a sheet as an array of structsstatic booleangetAutoCalculate(org.apache.poi.ss.usermodel.Workbook workbook) Gets whether formulas automatically calculatestatic org.apache.poi.ss.usermodel.CellgetCell(org.apache.poi.ss.usermodel.Sheet sheet, int row, int col) Gets a cell at the specified row and column, returning null if it doesn't existstatic StringgetCellAddress(org.apache.poi.ss.usermodel.Workbook workbook, int row, int column) Gets the cell address (e.g., "A1", "B5") for a given row and columnstatic StringgetCellComment(org.apache.poi.ss.usermodel.Cell cell) Gets a comment from a cellstatic ortus.boxlang.runtime.types.IStructgetCellCommentAsStruct(org.apache.poi.ss.usermodel.Cell cell) Get cell comment as a struct with Author, Column, Comment, Row keysstatic ortus.boxlang.runtime.types.IStructgetCellFormat(org.apache.poi.ss.usermodel.Cell cell) Gets the formatting information of a cellstatic ortus.boxlang.runtime.types.IStructgetCellHyperlink(org.apache.poi.ss.usermodel.Sheet sheet, int row, int column) Gets the hyperlink from a cellstatic StringgetCellType(org.apache.poi.ss.usermodel.Cell cell) Gets the Excel cell type of a cellstatic ObjectgetCellValue(org.apache.poi.ss.usermodel.Cell cell) Gets the cell value as an Object, handling different cell typesstatic intgetColumnCount(org.apache.poi.ss.usermodel.Sheet sheet) Gets the number of columns that contain data in the specified sheetstatic intgetColumnCount(org.apache.poi.ss.usermodel.Workbook workbook) Gets the number of columns that contain data in the active sheetstatic doublegetColumnWidth(org.apache.poi.ss.usermodel.Sheet sheet, int column, boolean returnWidthInPixels) Gets the width of a column.static ortus.boxlang.runtime.types.IStructgetInfo(org.apache.poi.ss.usermodel.Workbook workbook) Gets information about the spreadsheet as a structstatic intgetLastRowNumber(org.apache.poi.ss.usermodel.Sheet sheet) Gets the last row number with data in the sheet.static org.apache.poi.ss.usermodel.CellgetOrCreateCell(org.apache.poi.ss.usermodel.Sheet sheet, int row, int col) Gets a cell at the specified row and column, creating it if it doesn't existstatic StringgetPrintOrientation(org.apache.poi.ss.usermodel.Sheet sheet) Gets the print orientation of the sheet.static booleangetRecalculateFormulasOnNextOpen(org.apache.poi.ss.usermodel.Workbook workbook) Gets whether formulas will be recalculated when the file is openedstatic intgetRowCount(org.apache.poi.ss.usermodel.Sheet sheet) Gets the number of rows that contain data in the specified sheetstatic intgetRowCount(org.apache.poi.ss.usermodel.Workbook workbook) Gets the number of rows that contain data in the active sheetstatic ortus.boxlang.runtime.types.ArraygetSheetNames(org.apache.poi.ss.usermodel.Workbook workbook) Gets the names of all sheets in the workbookstatic ortus.boxlang.runtime.types.IStructgetSheetsVisibility(org.apache.poi.ss.usermodel.Workbook workbook) Gets the visibility status of all sheets in the workbookstatic voidgroupColumns(org.apache.poi.ss.usermodel.Sheet sheet, int startColumn, int endColumn, Boolean isCollapsed) Groups columns together in the active sheetstatic voidGroups rows together in the active sheetstatic booleanChecks if a sheet with the given name exists in the workbookstatic voidHides a sheet from viewstatic booleanisBinaryFormat(org.apache.poi.ss.usermodel.Workbook workbook) Determines if a workbook is in binary format (.xls)static booleanisColumnHidden(org.apache.poi.ss.usermodel.Sheet sheet, int column) Gets the hidden state of a columnstatic booleanisRowHidden(org.apache.poi.ss.usermodel.Sheet sheet, int row) Gets the hidden state of a rowstatic booleanisSpreadsheetFile(String filePath) Determines if a file is a valid spreadsheet filestatic booleanisXmlFormat(org.apache.poi.ss.usermodel.Workbook workbook) Determines if a workbook is in XML format (.xlsx)static voidmoveSheet(org.apache.poi.ss.usermodel.Workbook workbook, int fromIndex, int toIndex) Moves a sheet to a new position by sheet indexstatic voidMoves a sheet to a new position by sheet namestatic org.apache.poi.ss.usermodel.WorkbookreadWorkbook(String filePath) Reads a spreadsheet file from the given pathstatic org.apache.poi.ss.usermodel.WorkbookreadWorkbook(String filePath, String password) Reads a spreadsheet file from the given path with optional passwordstatic voidrecalculateAllFormulas(org.apache.poi.ss.usermodel.Workbook workbook) Recalculates all formulas in the workbookstatic voidremoveColumnBreak(org.apache.poi.ss.usermodel.Sheet sheet, int zeroBasedCol) Removes a page (column) break on the specified 0-based column index on the sheet.static voidremovePrintGridlines(org.apache.poi.ss.usermodel.Sheet sheet) Removes print gridlines from the sheet (gridlines will not print when document is printed).static voidremoveRowBreak(org.apache.poi.ss.usermodel.Sheet sheet, int zeroBasedRow) Removes a page (row) break on the specified 0-based row index on the sheet.static voidremoveSheetByNumber(org.apache.poi.ss.usermodel.Workbook workbook, int sheetNumber) Removes a sheet by index (1-based)static voidrenameSheet(org.apache.poi.ss.usermodel.Workbook workbook, String oldName, String newName) Renames an existing sheetstatic voidsetActiveCell(org.apache.poi.ss.usermodel.Sheet sheet, int row, int col) Sets the active/selected cell in a sheetstatic voidsetActiveSheet(org.apache.poi.ss.usermodel.Workbook workbook, int sheetIndex) Sets the active sheet by index (0-based)static voidsetActiveSheet(org.apache.poi.ss.usermodel.Workbook workbook, String sheetName) Sets the active sheet by namestatic voidsetAutoCalculate(org.apache.poi.ss.usermodel.Workbook workbook, boolean autoCalculate) Sets whether formulas automatically calculatestatic voidsetCellComment(org.apache.poi.ss.usermodel.Cell cell, Object commentObj, String author) Sets a comment on a cell with optional formattingstatic voidsetCellHyperlink(org.apache.poi.ss.usermodel.Sheet sheet, int row, int column, String hyperlink, String label, org.apache.poi.ss.usermodel.Workbook workbook) Sets a hyperlink on a cellstatic voidsetCellRangeValue(org.apache.poi.ss.usermodel.Sheet sheet, Object value, int startRow, int startCol, int endRow, int endCol) Sets the same value to a range of cellsstatic voidsetCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value) Sets a cell value, automatically determining the appropriate cell typestatic voidsetColumnBreak(org.apache.poi.ss.usermodel.Sheet sheet, int zeroBasedCol) Sets a page (column) break on the specified 0-based column index on the sheet.static voidsetColumnHidden(org.apache.poi.ss.usermodel.Sheet sheet, int column, boolean hidden) Sets the hidden state of a columnstatic voidsetDocumentProperties(org.apache.poi.ss.usermodel.Workbook workbook, ortus.boxlang.runtime.types.IStruct properties) Sets document properties/metadata for a workbookstatic voidsetFitToPage(org.apache.poi.ss.usermodel.Sheet sheet, boolean fitToPage, int pagesWide, int pagesHigh) Sets the fit-to-page print option for a sheetstatic voidsetFooter(org.apache.poi.ss.usermodel.Sheet sheet, ortus.boxlang.runtime.types.IStruct footer) Sets the footer text for the specified sheet.static voidsetFooterImage(org.apache.poi.ss.usermodel.Sheet sheet, String alignment, String imagePath, org.apache.poi.ss.usermodel.Workbook workbook) Sets an image in the footer of the specified sheetstatic voidsetHeader(org.apache.poi.ss.usermodel.Sheet sheet, ortus.boxlang.runtime.types.IStruct header) Sets the header text for the specified sheet.static voidsetHeaderImage(org.apache.poi.ss.usermodel.Sheet sheet, String alignment, String imagePath, org.apache.poi.ss.usermodel.Workbook workbook) Sets an image in the header of the specified sheetstatic voidsetRecalculateFormulasOnNextOpen(org.apache.poi.ss.usermodel.Workbook workbook, boolean recalculate) Sets whether formulas should be recalculated when the file is openedstatic voidsetRepeatingColumns(org.apache.poi.ss.usermodel.Workbook workbook, org.apache.poi.ss.usermodel.Sheet sheet, int startCol, int endCol) Sets columns to repeat on every printed pagestatic voidsetRepeatingRows(org.apache.poi.ss.usermodel.Workbook workbook, org.apache.poi.ss.usermodel.Sheet sheet, int startRow, int endRow) Sets rows to repeat on every printed pagestatic voidsetRowBreak(org.apache.poi.ss.usermodel.Sheet sheet, int zeroBasedRow) Sets a page (row) break on the specified 0-based row index on the sheet.static voidsetRowHidden(org.apache.poi.ss.usermodel.Sheet sheet, int row, boolean hidden) Sets the hidden state of a rowstatic voidsetSheetPrintOrientation(org.apache.poi.ss.usermodel.Sheet sheet, String orientation) Sets the sheet print orientationstatic voidshiftColumns(org.apache.poi.ss.usermodel.Sheet sheet, int start, int end, int n) Shifts columns left or right in a sheet Note: Apache POI doesn't provide a native column shift operation, so we implement it manually by copying cell data from the source columns to the destination columns.static voidungroupColumns(org.apache.poi.ss.usermodel.Sheet sheet, int startColumn, int endColumn) Ungroups columns in the active sheetstatic voidungroupRows(org.apache.poi.ss.usermodel.Sheet sheet, int startRow, int endRow) Ungroups rows in the active sheetstatic voidunhideSheet(org.apache.poi.ss.usermodel.Workbook workbook, String sheetName) Unhides a sheet to make it visiblestatic voidwriteWorkbook(org.apache.poi.ss.usermodel.Workbook workbook, String filePath, boolean overwrite) Writes a workbook to the specified file pathstatic voidwriteWorkbook(org.apache.poi.ss.usermodel.Workbook workbook, String filePath, boolean overwrite, String password) Writes a workbook to the specified file path with optional password protection
- 
Constructor Details- 
SpreadsheetUtilpublic SpreadsheetUtil()
 
- 
- 
Method Details- 
createWorkbookpublic static org.apache.poi.ss.usermodel.Workbook createWorkbook(boolean xmlFormat, String sheetName) Creates a new workbook based on the specified format- Parameters:
- xmlFormat- True for .xlsx format, false for .xls format
- sheetName- The name of the initial sheet (defaults to "Sheet1")
- Returns:
- A new workbook instance
 
- 
createXlsxWorkbookCreates a new .xlsx workbook- Parameters:
- sheetName- The name of the initial sheet
- Returns:
- A new XLSX workbook
 
- 
createXlsWorkbookCreates a new .xls workbook- Parameters:
- sheetName- The name of the initial sheet
- Returns:
- A new XLS workbook
 
- 
readWorkbookReads a spreadsheet file from the given path- Parameters:
- filePath- The absolute path to the spreadsheet file
- Returns:
- A workbook object
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxIOException- If the file cannot be read or doesn't exist
 
- 
readWorkbookReads a spreadsheet file from the given path with optional password- Parameters:
- filePath- The absolute path to the spreadsheet file
- password- Optional password for encrypted files
- Returns:
- A workbook object
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxIOException- If the file cannot be read or doesn't exist
 
- 
writeWorkbookpublic static void writeWorkbook(org.apache.poi.ss.usermodel.Workbook workbook, String filePath, boolean overwrite) Writes a workbook to the specified file path- Parameters:
- workbook- The workbook to write
- filePath- The absolute path where to save the file
- overwrite- Whether to overwrite existing files
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxIOException- If the file cannot be written
 
- 
writeWorkbookpublic static void writeWorkbook(org.apache.poi.ss.usermodel.Workbook workbook, String filePath, boolean overwrite, String password) Writes a workbook to the specified file path with optional password protection- Parameters:
- workbook- The workbook to write
- filePath- The absolute path where to save the file
- overwrite- Whether to overwrite existing files
- password- Optional password to protect the file (only works with .xlsx format)
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxIOException- If the file cannot be written
 
- 
getCellValueGets the cell value as an Object, handling different cell types- Parameters:
- cell- The cell to get the value from
- Returns:
- The cell value as an appropriate Java object
 
- 
setCellValueSets a cell value, automatically determining the appropriate cell type- Parameters:
- cell- The cell to set the value for
- value- The value to set
 
- 
clearCellpublic static void clearCell(org.apache.poi.ss.usermodel.Sheet sheet, int row, int col) Clears the specified cell of all styles and values- Parameters:
- sheet- The sheet containing the cell
- row- The 1-based row number
- col- The 1-based column number
 
- 
clearCellRangepublic static void clearCellRange(org.apache.poi.ss.usermodel.Sheet sheet, int startRow, int startCol, int endRow, int endCol) Clears a range of cells of all styles and values- Parameters:
- sheet- The sheet containing the cells
- startRow- The 1-based starting row (inclusive)
- startCol- The 1-based starting column (inclusive)
- endRow- The 1-based ending row (inclusive)
- endCol- The 1-based ending column (inclusive)
 
- 
getCellTypeGets the Excel cell type of a cell- Parameters:
- cell- The cell to check
- Returns:
- Cell type as a string: "BLANK", "BOOLEAN", "ERROR", "FORMULA", "NUMERIC", or "STRING"
 
- 
getCellFormatpublic static ortus.boxlang.runtime.types.IStruct getCellFormat(org.apache.poi.ss.usermodel.Cell cell) Gets the formatting information of a cell- Parameters:
- cell- The cell to get formatting from
- Returns:
- A struct containing all formatting attributes
 
- 
setCellRangeValuepublic static void setCellRangeValue(org.apache.poi.ss.usermodel.Sheet sheet, Object value, int startRow, int startCol, int endRow, int endCol) Sets the same value to a range of cells- Parameters:
- sheet- The sheet containing the cells
- value- The value to set for all cells in the range
- startRow- The 1-based starting row (inclusive)
- startCol- The 1-based starting column (inclusive)
- endRow- The 1-based ending row (inclusive)
- endCol- The 1-based ending column (inclusive)
 
- 
getActiveCellpublic static ortus.boxlang.runtime.types.IStruct getActiveCell(org.apache.poi.ss.usermodel.Sheet sheet) Gets the currently active/selected cell in a sheet- Parameters:
- sheet- The sheet
- Returns:
- A struct with keys "row" and "column" (both 1-based), or with 1,1 as default
 
- 
setActiveCellpublic static void setActiveCell(org.apache.poi.ss.usermodel.Sheet sheet, int row, int col) Sets the active/selected cell in a sheet- Parameters:
- sheet- The sheet
- row- The 1-based row number
- col- The 1-based column number
 
- 
setRowBreakpublic static void setRowBreak(org.apache.poi.ss.usermodel.Sheet sheet, int zeroBasedRow) Sets a page (row) break on the specified 0-based row index on the sheet.- Parameters:
- sheet- the sheet
- zeroBasedRow- the 0-based row index
 
- 
removeRowBreakpublic static void removeRowBreak(org.apache.poi.ss.usermodel.Sheet sheet, int zeroBasedRow) Removes a page (row) break on the specified 0-based row index on the sheet.- Parameters:
- sheet- the sheet
- zeroBasedRow- the 0-based row index
 
- 
setColumnBreakpublic static void setColumnBreak(org.apache.poi.ss.usermodel.Sheet sheet, int zeroBasedCol) Sets a page (column) break on the specified 0-based column index on the sheet.- Parameters:
- sheet- the sheet
- zeroBasedCol- the 0-based column index
 
- 
removeColumnBreakpublic static void removeColumnBreak(org.apache.poi.ss.usermodel.Sheet sheet, int zeroBasedCol) Removes a page (column) break on the specified 0-based column index on the sheet.- Parameters:
- sheet- the sheet
- zeroBasedCol- the 0-based column index
 
- 
setFitToPagepublic static void setFitToPage(org.apache.poi.ss.usermodel.Sheet sheet, boolean fitToPage, int pagesWide, int pagesHigh) Sets the fit-to-page print option for a sheet- Parameters:
- sheet- The sheet to configure
- fitToPage- Whether to enable fit-to-page
- pagesWide- Number of pages to fit columns into (0 = no horizontal fit)
- pagesHigh- Number of pages to fit rows into (0 = no vertical fit)
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- if sheet is null
 
- 
addPrintGridlinespublic static void addPrintGridlines(org.apache.poi.ss.usermodel.Sheet sheet) Adds print gridlines to the sheet (gridlines will print when document is printed).- Parameters:
- sheet- The sheet to modify
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- if sheet is null
 
- 
removePrintGridlinespublic static void removePrintGridlines(org.apache.poi.ss.usermodel.Sheet sheet) Removes print gridlines from the sheet (gridlines will not print when document is printed).- Parameters:
- sheet- The sheet to modify
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- if sheet is null
 
- 
getColumnWidthpublic static double getColumnWidth(org.apache.poi.ss.usermodel.Sheet sheet, int column, boolean returnWidthInPixels) Gets the width of a column.- Parameters:
- sheet- The sheet containing the column
- column- The column number (0-based)
- returnWidthInPixels- If true, returns width in pixels; if false, returns width in points
- Returns:
- Column width as a double value
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- if sheet is null or column is invalid
 
- 
getLastRowNumberpublic static int getLastRowNumber(org.apache.poi.ss.usermodel.Sheet sheet) Gets the last row number with data in the sheet.- Parameters:
- sheet- The sheet to query
- Returns:
- The last row number (0-based), or -1 if sheet is empty
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- if sheet is null
 
- 
getPrintOrientationGets the print orientation of the sheet.- Parameters:
- sheet- The sheet to query
- Returns:
- "portrait" or "landscape"
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- if sheet is null
 
- 
setColumnHiddenpublic static void setColumnHidden(org.apache.poi.ss.usermodel.Sheet sheet, int column, boolean hidden) Sets the hidden state of a column- Parameters:
- sheet- The sheet containing the column
- column- The column number (1-based)
- hidden- True to hide, false to show
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- if sheet is null or column is invalid
 
- 
isColumnHiddenpublic static boolean isColumnHidden(org.apache.poi.ss.usermodel.Sheet sheet, int column) Gets the hidden state of a column- Parameters:
- sheet- The sheet containing the column
- column- The column number (1-based)
- Returns:
- true if column is hidden, false otherwise
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- if sheet is null or column is invalid
 
- 
setRowHiddenpublic static void setRowHidden(org.apache.poi.ss.usermodel.Sheet sheet, int row, boolean hidden) Sets the hidden state of a row- Parameters:
- sheet- The sheet containing the row
- row- The row number (1-based)
- hidden- True to hide, false to show
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- if sheet is null or row is invalid
 
- 
isRowHiddenpublic static boolean isRowHidden(org.apache.poi.ss.usermodel.Sheet sheet, int row) Gets the hidden state of a row- Parameters:
- sheet- The sheet containing the row
- row- The row number (1-based)
- Returns:
- true if row is hidden, false otherwise
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- if sheet is null or row is invalid
 
- 
getActiveSheetpublic static org.apache.poi.ss.usermodel.Sheet getActiveSheet(org.apache.poi.ss.usermodel.Workbook workbook) Gets the active sheet from the workbook- Parameters:
- workbook- The workbook
- Returns:
- The active sheet
 
- 
setActiveSheetSets the active sheet by name- Parameters:
- workbook- The workbook
- sheetName- The name of the sheet to make active
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- If the sheet doesn't exist
 
- 
setActiveSheetpublic static void setActiveSheet(org.apache.poi.ss.usermodel.Workbook workbook, int sheetIndex) Sets the active sheet by index (0-based)- Parameters:
- workbook- The workbook
- sheetIndex- The index of the sheet to make active (0-based)
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- If the sheet index is invalid
 
- 
renameSheetpublic static void renameSheet(org.apache.poi.ss.usermodel.Workbook workbook, String oldName, String newName) Renames an existing sheet- Parameters:
- workbook- The workbook
- oldName- The current name of the sheet
- newName- The new name for the sheet
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- If the sheet doesn't exist or new name is invalid
 
- 
removeSheetByNumberpublic static void removeSheetByNumber(org.apache.poi.ss.usermodel.Workbook workbook, int sheetNumber) Removes a sheet by index (1-based)- Parameters:
- workbook- The workbook
- sheetNumber- The sheet index (1-based)
- Throws:
- ortus.boxlang.runtime.types.exceptions.BoxRuntimeException- If the sheet index is invalid
 
- 
getOrCreateCellpublic static org.apache.poi.ss.usermodel.Cell getOrCreateCell(org.apache.poi.ss.usermodel.Sheet sheet, int row, int col) Gets a cell at the specified row and column, creating it if it doesn't exist- Parameters:
- sheet- The sheet containing the cell
- row- The row number (1-based)
- col- The column number (1-based)
- Returns:
- The cell object
 
- 
getCellpublic static org.apache.poi.ss.usermodel.Cell getCell(org.apache.poi.ss.usermodel.Sheet sheet, int row, int col) Gets a cell at the specified row and column, returning null if it doesn't exist- Parameters:
- sheet- The sheet containing the cell
- row- The row number (1-based)
- col- The column number (1-based)
- Returns:
- The cell object or null if it doesn't exist
 
- 
isSpreadsheetFileDetermines if a file is a valid spreadsheet file- Parameters:
- filePath- The absolute path to the file
- Returns:
- True if the file is a valid spreadsheet, false otherwise
 
- 
isXmlFormatpublic static boolean isXmlFormat(org.apache.poi.ss.usermodel.Workbook workbook) Determines if a workbook is in XML format (.xlsx)- Parameters:
- workbook- The workbook to check
- Returns:
- True if the workbook is in XML format, false if binary format
 
- 
isBinaryFormatpublic static boolean isBinaryFormat(org.apache.poi.ss.usermodel.Workbook workbook) Determines if a workbook is in binary format (.xls)- Parameters:
- workbook- The workbook to check
- Returns:
- True if the workbook is in binary format, false if XML format
 
- 
getRowCountpublic static int getRowCount(org.apache.poi.ss.usermodel.Workbook workbook) Gets the number of rows that contain data in the active sheet- Parameters:
- workbook- The workbook
- Returns:
- The number of rows with data
 
- 
getRowCountpublic static int getRowCount(org.apache.poi.ss.usermodel.Sheet sheet) Gets the number of rows that contain data in the specified sheet- Parameters:
- sheet- The sheet
- Returns:
- The number of rows with data
 
- 
getColumnCountpublic static int getColumnCount(org.apache.poi.ss.usermodel.Workbook workbook) Gets the number of columns that contain data in the active sheet- Parameters:
- workbook- The workbook
- Returns:
- The number of columns with data
 
- 
getColumnCountpublic static int getColumnCount(org.apache.poi.ss.usermodel.Sheet sheet) Gets the number of columns that contain data in the specified sheet- Parameters:
- sheet- The sheet
- Returns:
- The number of columns with data
 
- 
autoSizeColumnspublic static void autoSizeColumns(org.apache.poi.ss.usermodel.Workbook workbook) Auto-sizes all columns in the active sheet- Parameters:
- workbook- The workbook
 
- 
autoSizeColumnspublic static void autoSizeColumns(org.apache.poi.ss.usermodel.Sheet sheet) Auto-sizes all columns in the specified sheet- Parameters:
- sheet- The sheet
 
- 
autoSizeColumnpublic static void autoSizeColumn(org.apache.poi.ss.usermodel.Workbook workbook, int column) Auto-sizes a specific column in the active sheet- Parameters:
- workbook- The workbook
- column- The column number (1-based)
 
- 
autoSizeColumnpublic static void autoSizeColumn(org.apache.poi.ss.usermodel.Sheet sheet, int column) Auto-sizes a specific column in the specified sheet- Parameters:
- sheet- The sheet
- column- The column number (1-based)
 
- 
deleteColumnpublic static void deleteColumn(org.apache.poi.ss.usermodel.Sheet sheet, int column) Deletes a column by clearing all cells in that column Note: Apache POI doesn't support true column deletion, so we clear the column content- Parameters:
- sheet- The sheet
- column- The column number to delete (1-based)
 
- 
deleteColumnspublic static void deleteColumns(org.apache.poi.ss.usermodel.Sheet sheet, int startColumn, int endColumn) Deletes multiple columns by clearing all cells in those columns- Parameters:
- sheet- The sheet
- startColumn- The starting column number (1-based, inclusive)
- endColumn- The ending column number (1-based, inclusive)
 
- 
formatCellpublic static void formatCell(org.apache.poi.ss.usermodel.Cell cell, ortus.boxlang.runtime.types.IStruct format) Applies formatting to a specific cell based on a format structure- Parameters:
- cell- The cell to format
- format- A structure containing formatting options
 
- 
setHeaderpublic static void setHeader(org.apache.poi.ss.usermodel.Sheet sheet, ortus.boxlang.runtime.types.IStruct header) Sets the header text for the specified sheet. Expects a struct with optional keys: left, center, right- Parameters:
- sheet- The sheet to update
- header- The header struct containing left/center/right text
 
- 
setHeaderImagepublic static void setHeaderImage(org.apache.poi.ss.usermodel.Sheet sheet, String alignment, String imagePath, org.apache.poi.ss.usermodel.Workbook workbook) Sets an image in the header of the specified sheet- Parameters:
- sheet- The sheet to update
- alignment- The alignment: "left", "center", or "right"
- imagePath- The absolute path to the image file
- workbook- The workbook instance
 
- 
setCellCommentpublic static void setCellComment(org.apache.poi.ss.usermodel.Cell cell, Object commentObj, String author) Sets a comment on a cell with optional formatting- Parameters:
- cell- The cell to add comment to
- commentObj- The comment text (String) or struct with comment details
- author- The comment author (optional, used if commentObj is a String)
 
- 
getCellCommentGets a comment from a cell- Parameters:
- cell- The cell to get comment from
- Returns:
- The comment text, or null if no comment exists
 
- 
getCellCommentAsStructpublic static ortus.boxlang.runtime.types.IStruct getCellCommentAsStruct(org.apache.poi.ss.usermodel.Cell cell) Get cell comment as a struct with Author, Column, Comment, Row keys- Parameters:
- cell- The cell to get the comment from
- Returns:
- A struct with {Author, Column, Comment, Row} or null if no comment exists
 
- 
getAllCellCommentspublic static ortus.boxlang.runtime.types.Array getAllCellComments(org.apache.poi.ss.usermodel.Sheet sheet) Get all cell comments from a sheet as an array of structs- Parameters:
- sheet- The sheet to get comments from
- Returns:
- An array of structs with {Author, Column, Comment, Row} for each comment
 
- 
setDocumentPropertiespublic static void setDocumentProperties(org.apache.poi.ss.usermodel.Workbook workbook, ortus.boxlang.runtime.types.IStruct properties) Sets document properties/metadata for a workbook- Parameters:
- workbook- The workbook to set properties on
- properties- A struct containing metadata properties (AUTHOR, TITLE, SUBJECT, COMMENTS, KEYWORDS, CATEGORY, MANAGER, COMPANY, LASTAUTHOR)
 
- 
createSplitPanepublic static void createSplitPane(org.apache.poi.ss.usermodel.Sheet sheet, int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane) Creates a split pane in a sheet- Parameters:
- sheet- The sheet to add split pane to
- xSplitPos- The horizontal (x-axis) position of the split in 1/20th of a pixel units
- ySplitPos- The vertical (y-axis) position of the split in 1/20th of a pixel units
- leftmostColumn- The leftmost column visible in the right pane (1-based, will be converted to 0-based for POI)
- topRow- The top row visible in the bottom pane (1-based, will be converted to 0-based for POI)
- activePane- The active pane indicator (0=lower-left, 1=upper-right, 2=lower-right, 3=upper-left)
 
- 
createSplitPanepublic static void createSplitPane(org.apache.poi.ss.usermodel.Sheet sheet, int xSplitPos, int ySplitPos, int leftmostColumn, int topRow) Creates a split pane in a sheet with default active pane- Parameters:
- sheet- The sheet to add split pane to
- xSplitPos- The horizontal position of the split
- ySplitPos- The vertical position of the split
- leftmostColumn- The leftmost column visible in the right pane
- topRow- The top row visible in the bottom pane
 
- 
formatRowpublic static void formatRow(org.apache.poi.ss.usermodel.Sheet sheet, int row, ortus.boxlang.runtime.types.IStruct format) Formats all cells in a single row- Parameters:
- sheet- The sheet containing the row
- row- The row number (1-based)
- format- A structure containing formatting options
 
- 
formatRowspublic static void formatRows(org.apache.poi.ss.usermodel.Sheet sheet, String rows, ortus.boxlang.runtime.types.IStruct format) Formats all cells in multiple rows specified by a comma-separated string or range Format: "1,3,5" or "1-5,7-10" or combinations like "1-3,5,7-10"- Parameters:
- sheet- The sheet containing the rows
- rows- A string specifying which rows to format
- format- A structure containing formatting options
 
- 
formatColumnpublic static void formatColumn(org.apache.poi.ss.usermodel.Sheet sheet, int column, ortus.boxlang.runtime.types.IStruct format) Formats all cells in a single column- Parameters:
- sheet- The sheet containing the column
- column- The column number (1-based)
- format- A structure containing formatting options
 
- 
formatColumnspublic static void formatColumns(org.apache.poi.ss.usermodel.Sheet sheet, String columns, ortus.boxlang.runtime.types.IStruct format) Formats all cells in multiple columns specified by a comma-separated string or range Format: "1,3,5" or "1-5,7-10" or combinations like "1-3,5,7-10"- Parameters:
- sheet- The sheet containing the columns
- columns- A string specifying which columns to format
- format- A structure containing formatting options
 
- 
shiftColumnspublic static void shiftColumns(org.apache.poi.ss.usermodel.Sheet sheet, int start, int end, int n) Shifts columns left or right in a sheet Note: Apache POI doesn't provide a native column shift operation, so we implement it manually by copying cell data from the source columns to the destination columns.- Parameters:
- sheet- The sheet containing the columns
- start- The starting column number (1-based)
- end- The ending column number (1-based)
- n- The number of columns to shift (positive for right, negative for left)
 
- 
addImagepublic static void addImage(org.apache.poi.ss.usermodel.Sheet sheet, String filepath, int row, int col, org.apache.poi.ss.usermodel.Workbook workbook) Adds an image to a sheet at a specified cell location- Parameters:
- sheet- The sheet to add the image to
- filepath- The absolute path to the image file
- row- The starting row index (1-based, converted to 0-based)
- col- The starting column index (1-based, converted to 0-based)
- workbook- The workbook instance (needed to get image bytes)
 
- 
addImagepublic static void addImage(org.apache.poi.ss.usermodel.Sheet sheet, String filepath, int startRow, int startCol, int endRow, int endCol, org.apache.poi.ss.usermodel.Workbook workbook) Adds an image with custom anchor coordinates- Parameters:
- sheet- The sheet to add the image to
- filepath- The absolute path to the image file
- startRow- The starting row (1-based)
- startCol- The starting column (1-based)
- endRow- The ending row (1-based)
- endCol- The ending column (1-based)
- workbook- The workbook instance
 
- 
setCellHyperlinkpublic static void setCellHyperlink(org.apache.poi.ss.usermodel.Sheet sheet, int row, int column, String hyperlink, String label, org.apache.poi.ss.usermodel.Workbook workbook) Sets a hyperlink on a cell- Parameters:
- sheet- The sheet containing the cell
- row- The row number (1-based)
- column- The column number (1-based)
- hyperlink- The hyperlink URL
- label- The optional display label for the hyperlink
- workbook- The workbook instance
 
- 
getCellHyperlinkpublic static ortus.boxlang.runtime.types.IStruct getCellHyperlink(org.apache.poi.ss.usermodel.Sheet sheet, int row, int column) Gets the hyperlink from a cell- Parameters:
- sheet- The sheet containing the cell
- row- The row number (1-based)
- column- The column number (1-based)
- Returns:
- A struct containing hyperlink information, or null if no hyperlink exists
 
- 
formatCellRangepublic static void formatCellRange(org.apache.poi.ss.usermodel.Sheet sheet, ortus.boxlang.runtime.types.IStruct format, int startRow, int startCol, int endRow, int endCol, org.apache.poi.ss.usermodel.Workbook workbook) Formats a range of cells with a single format struct- Parameters:
- sheet- The sheet containing the cells
- format- The format struct containing style properties
- startRow- The starting row (1-based)
- startCol- The starting column (1-based)
- endRow- The ending row (1-based)
- endCol- The ending column (1-based)
- workbook- The workbook instance
 
- 
setSheetPrintOrientationpublic static void setSheetPrintOrientation(org.apache.poi.ss.usermodel.Sheet sheet, String orientation) Sets the sheet print orientation- Parameters:
- sheet- The sheet to modify
- orientation- The orientation ("portrait" or "landscape")
 
- 
setRepeatingColumnspublic static void setRepeatingColumns(org.apache.poi.ss.usermodel.Workbook workbook, org.apache.poi.ss.usermodel.Sheet sheet, int startCol, int endCol) Sets columns to repeat on every printed page- Parameters:
- workbook- The workbook instance
- sheet- The sheet to modify
- startCol- The starting column (1-based)
- endCol- The ending column (1-based)
 
- 
setRepeatingRowspublic static void setRepeatingRows(org.apache.poi.ss.usermodel.Workbook workbook, org.apache.poi.ss.usermodel.Sheet sheet, int startRow, int endRow) Sets rows to repeat on every printed page- Parameters:
- workbook- The workbook instance
- sheet- The sheet to modify
- startRow- The starting row (1-based)
- endRow- The ending row (1-based)
 
- 
groupRowspublic static void groupRows(org.apache.poi.ss.usermodel.Sheet sheet, int startRow, int endRow, Boolean isCollapsed) Groups rows together in the active sheet- Parameters:
- sheet- The sheet to group rows in
- startRow- The starting row number (1-based)
- endRow- The ending row number (1-based)
- isCollapsed- Whether the group should be initially collapsed (optional)
 
- 
ungroupRowspublic static void ungroupRows(org.apache.poi.ss.usermodel.Sheet sheet, int startRow, int endRow) Ungroups rows in the active sheet- Parameters:
- sheet- The sheet to ungroup rows in
- startRow- The starting row number (1-based)
- endRow- The ending row number (1-based)
 
- 
groupColumnspublic static void groupColumns(org.apache.poi.ss.usermodel.Sheet sheet, int startColumn, int endColumn, Boolean isCollapsed) Groups columns together in the active sheet- Parameters:
- sheet- The sheet to group columns in
- startColumn- The starting column number (1-based)
- endColumn- The ending column number (1-based)
- isCollapsed- Whether the group should be initially collapsed (optional)
 
- 
ungroupColumnspublic static void ungroupColumns(org.apache.poi.ss.usermodel.Sheet sheet, int startColumn, int endColumn) Ungroups columns in the active sheet- Parameters:
- sheet- The sheet to ungroup columns in
- startColumn- The starting column number (1-based)
- endColumn- The ending column number (1-based)
 
- 
getAutoCalculatepublic static boolean getAutoCalculate(org.apache.poi.ss.usermodel.Workbook workbook) Gets whether formulas automatically calculate- Parameters:
- workbook- The workbook to check
- Returns:
- True if auto-calculation is enabled (XSSF only, always true for HSSF)
 
- 
setAutoCalculatepublic static void setAutoCalculate(org.apache.poi.ss.usermodel.Workbook workbook, boolean autoCalculate) Sets whether formulas automatically calculate- Parameters:
- workbook- The workbook to update
- autoCalculate- Whether to enable auto-calculation
 
- 
getRecalculateFormulasOnNextOpenpublic static boolean getRecalculateFormulasOnNextOpen(org.apache.poi.ss.usermodel.Workbook workbook) Gets whether formulas will be recalculated when the file is opened- Parameters:
- workbook- The workbook to check
- Returns:
- True if force recalculation is enabled, false otherwise
 
- 
setRecalculateFormulasOnNextOpenpublic static void setRecalculateFormulasOnNextOpen(org.apache.poi.ss.usermodel.Workbook workbook, boolean recalculate) Sets whether formulas should be recalculated when the file is opened- Parameters:
- workbook- The workbook to update
- recalculate- Whether to force recalculation on next open
 
- 
hideSheetHides a sheet from view- Parameters:
- workbook- The workbook containing the sheet
- sheetName- The name of the sheet to hide
 
- 
unhideSheetUnhides a sheet to make it visible- Parameters:
- workbook- The workbook containing the sheet
- sheetName- The name of the sheet to unhide
 
- 
moveSheetpublic static void moveSheet(org.apache.poi.ss.usermodel.Workbook workbook, int fromIndex, int toIndex) Moves a sheet to a new position by sheet index- Parameters:
- workbook- The workbook containing the sheet
- fromIndex- The current sheet index (0-based)
- toIndex- The target sheet index (0-based)
 
- 
moveSheetpublic static void moveSheet(org.apache.poi.ss.usermodel.Workbook workbook, String sheetName, int toIndex) Moves a sheet to a new position by sheet name- Parameters:
- workbook- The workbook containing the sheet
- sheetName- The name of the sheet to move
- toIndex- The target sheet index (0-based)
 
- 
getCellAddresspublic static String getCellAddress(org.apache.poi.ss.usermodel.Workbook workbook, int row, int column) Gets the cell address (e.g., "A1", "B5") for a given row and column- Parameters:
- workbook- The workbook containing the cell
- row- The row number (1-based)
- column- The column number (1-based)
- Returns:
- The cell address string (e.g., "A1")
 
- 
getInfopublic static ortus.boxlang.runtime.types.IStruct getInfo(org.apache.poi.ss.usermodel.Workbook workbook) Gets information about the spreadsheet as a struct- Parameters:
- workbook- The workbook containing the sheet
- Returns:
- A struct containing sheet properties
 
- 
getSheetsVisibilitypublic static ortus.boxlang.runtime.types.IStruct getSheetsVisibility(org.apache.poi.ss.usermodel.Workbook workbook) Gets the visibility status of all sheets in the workbook- Parameters:
- workbook- The workbook to get sheet visibility from
- Returns:
- A struct with sheet names as keys and visibility status ("visible", "hidden", "veryHidden") as values
 
- 
hasSheetChecks if a sheet with the given name exists in the workbook- Parameters:
- workbook- The workbook to check
- sheetName- The name of the sheet to look for
- Returns:
- True if the sheet exists, false otherwise
 
- 
getSheetNamespublic static ortus.boxlang.runtime.types.Array getSheetNames(org.apache.poi.ss.usermodel.Workbook workbook) Gets the names of all sheets in the workbook- Parameters:
- workbook- The workbook to get sheet names from
- Returns:
- An array of sheet names
 
- 
recalculateAllFormulaspublic static void recalculateAllFormulas(org.apache.poi.ss.usermodel.Workbook workbook) Recalculates all formulas in the workbook- Parameters:
- workbook- The workbook containing formulas to recalculate
 
 
-