Fluent API
Complete reference for the SpreadsheetFile Fluent API - the recommended approach for working with spreadsheets in BoxLang
The Fluent API is the modern, recommended way to work with spreadsheets in BoxLang. It provides a chainable, intuitive interface centered around the SpreadsheetFile object.
Recommended Approach: The Fluent API is the preferred method for all spreadsheet operations. It's more intuitive, easier to read, and provides better code organization than traditional BIFs or component methods.
📋 Quick Navigation
Creating & Loading
Spreadsheet()
Spreadsheet()Creates a new empty spreadsheet in XLSX format with a default sheet named "Sheet1".
Arguments
None
Example
Spreadsheet( path )
Spreadsheet( path )Creates or loads a spreadsheet from the specified path.
Arguments
path
String
Yes
Path to the spreadsheet file
Example
Spreadsheet( path, load )
Spreadsheet( path, load )Loads an existing spreadsheet file or creates a new one.
Arguments
path
String
Yes
Path to the spreadsheet file
load
Boolean
Yes
If true, loads existing file; if false, creates new file reference
Example
load( path )
load( path )Loads a spreadsheet file from the specified path.
Arguments
path
String
Yes
Fully qualified path to spreadsheet file
Example
load( path, password )
load( path, password )Loads a password-protected spreadsheet file.
Arguments
path
String
Yes
Fully qualified path to spreadsheet file
password
String
Yes
Password to decrypt the file
Example
fromJson( json )
fromJson( json )Creates a spreadsheet from JSON string data (array of objects).
Arguments
json
String
Yes
JSON string containing array of objects
Example
fromArray( data )
fromArray( data )Creates a spreadsheet from an array of structs.
Arguments
data
Array
Yes
Array of structs where each struct is a row
Example
fromQuery( query )
fromQuery( query )Creates a spreadsheet from a BoxLang query.
Arguments
query
Query
Yes
A BoxLang query object
Example
Saving
save()
save()Saves the spreadsheet to the currently loaded path.
Arguments
None
Example
save( path )
save( path )Saves the spreadsheet to the specified path.
Arguments
path
String
Yes
Path where file should be saved
Example
save( path, password )
save( path, password )Saves the spreadsheet with password protection.
Arguments
path
String
Yes
Path where file should be saved
password
String
Yes
Password to protect the file
Example
saveAndClose()
saveAndClose()Saves the spreadsheet and closes the workbook.
Arguments
None
Example
Sheet Management
createSheet( sheetName )
createSheet( sheetName )Creates a new sheet with the specified name.
Arguments
sheetName
String
Yes
Name of the new sheet
Example
createSheet( sheetName, overwrite )
createSheet( sheetName, overwrite )Creates a new sheet with optional overwrite.
Arguments
sheetName
String
Yes
Name of the new sheet
overwrite
Boolean
Yes
Whether to overwrite existing sheet
Example
selectSheet( sheetName )
selectSheet( sheetName )Selects (activates) a sheet by name for subsequent operations.
Arguments
sheetName
String
Yes
Name of sheet to activate
Example
selectSheet( sheetIndex )
selectSheet( sheetIndex )Selects (activates) a sheet by index (1-based).
Arguments
sheetIndex
Integer
Yes
Index of sheet to activate (1-based)
Example
removeSheet( sheetName )
removeSheet( sheetName )Removes a sheet by name.
Arguments
sheetName
String
Yes
Name of sheet to remove
Example
renameSheet( oldName, newName )
renameSheet( oldName, newName )Renames an existing sheet.
Arguments
oldName
String
Yes
Current name of the sheet
newName
String
Yes
New name for the sheet
Example
copySheet( fromName, toName )
copySheet( fromName, toName )Copies a sheet with a new name.
Arguments
fromName
String
Yes
Name of sheet to copy from
toName
String
Yes
Name of new sheet
Example
hideSheet( sheetName )
hideSheet( sheetName )Hides a sheet from view.
Arguments
sheetName
String
Yes
Name of sheet to hide
Example
unhideSheet( sheetName )
unhideSheet( sheetName )Unhides a sheet to make it visible.
Arguments
sheetName
String
Yes
Name of sheet to unhide
Example
moveSheet( sheetName, toIndex )
moveSheet( sheetName, toIndex )Moves a sheet to a new position.
Arguments
sheetName
String
Yes
Name of sheet to move
toIndex
Integer
Yes
Target position (0-based)
Example
Cell Operations
setCellValue( row, col, value )
setCellValue( row, col, value )Sets a cell value at the specified row and column.
Arguments
row
Integer
Yes
Row number (1-based)
col
Integer
Yes
Column number (1-based)
value
Any
Yes
Value to set (String, Number, Date, Boolean)
Example
getCellValue( row, col )
getCellValue( row, col )Gets a cell value at the specified row and column.
Arguments
row
Integer
Yes
Row number (1-based)
col
Integer
Yes
Column number (1-based)
Example
formatCell( row, col, format )
formatCell( row, col, format )Formats a single cell.
Arguments
row
Integer
Yes
Row number (1-based)
col
Integer
Yes
Column number (1-based)
format
Struct
Yes
Formatting options (bold, italic, fontsize, fgcolor, etc.)
Example
Row Operations
addRow( values )
addRow( values )Adds a new row at the end of the sheet.
Arguments
values
Array
Yes
Array of cell values for the row
Example
setRowData( row, values )
setRowData( row, values )Sets multiple cell values in a row.
Arguments
row
Integer
Yes
Row number (1-based)
values
Array
Yes
Array of values starting from column 1
Example
getRowData( row )
getRowData( row )Gets all cell values from a row.
Arguments
row
Integer
Yes
Row number (1-based)
Example
formatRow( row, format )
formatRow( row, format )Formats all cells in a single row.
Arguments
row
Integer
Yes
Row number (1-based)
format
Struct
Yes
Formatting options
Example
formatRows( rows, format )
formatRows( rows, format )Formats multiple rows specified by range or list.
Arguments
rows
String
Yes
Row specification: "1,3,5" or "1-5" or combinations
format
Struct
Yes
Formatting options
Example
removeRow( rowIndex )
removeRow( rowIndex )Removes a row from the sheet.
Arguments
rowIndex
Integer
Yes
Row number to remove (1-based)
Example
addRows( data )
addRows( data )Adds multiple rows from a 2D array.
Arguments
data
Array
Yes
Array of arrays representing rows
Example
Column Operations
formatColumn( column, format )
formatColumn( column, format )Formats all cells in a single column.
Arguments
column
Integer
Yes
Column number (1-based)
format
Struct
Yes
Formatting options
Example
formatColumns( columns, format )
formatColumns( columns, format )Formats multiple columns specified by range or list.
Arguments
columns
String
Yes
Column specification: "1,3,5" or "1-5"
format
Struct
Yes
Formatting options
Example
deleteColumn( column )
deleteColumn( column )Deletes a column by clearing all cells.
Arguments
column
Integer
Yes
Column number (1-based)
Example
autoSizeColumn( column )
autoSizeColumn( column )Auto-sizes a specific column to fit content.
Arguments
column
Integer
Yes
Column number (1-based)
Example
autoSizeColumns()
autoSizeColumns()Auto-sizes all columns in the active sheet.
Arguments
None
Example
Data Conversion
toArray()
toArray()Converts sheet data to array of structs (first row as headers).
Arguments
None
Example
toQuery()
toQuery()Converts sheet data to query format (array of structs).
Arguments
None
Example
toJson()
toJson()Converts sheet data to JSON string.
Arguments
None
Example
toJson( pretty )
toJson( pretty )Converts sheet data to JSON string with optional formatting.
Arguments
pretty
Boolean
Yes
Whether to pretty-print the JSON
Example
toMatrix()
toMatrix()Converts sheet to 2D array matrix (including headers).
Arguments
None
Example
toCSV()
toCSV()Converts sheet data to CSV format.
Arguments
None
Example
toCSV( options )
toCSV( options )Converts sheet data to CSV with custom options.
Arguments
options
Struct
Yes
CSV options: delimiter, includeHeaders, lineSeparator
Example
Formatting
formatCell( row, col, format )
formatCell( row, col, format )Formats a cell with multiple style options.
Arguments
row
Integer
Yes
Row number (1-based)
col
Integer
Yes
Column number (1-based)
format
Struct
Yes
Style options
Format Options:
bold(Boolean) - Bold textitalic(Boolean) - Italic textunderline(Boolean) - Underline textfontsize(Integer) - Font size in pointsfont(String) - Font namefontColor(String) - Font colorfgcolor(String) - Background coloralignment(String) - Horizontal alignmentverticalalignment(String) - Vertical alignmentdataformat(String) - Number/date format
Example
Advanced Features
addFreezePane( column, row )
addFreezePane( column, row )Freezes columns and rows for scrolling.
Arguments
column
Integer
Yes
Columns to left are frozen
row
Integer
Yes
Rows above are frozen
Example
addSplitPane( xSplitPos, ySplitPos, leftmostColumn, topRow )
addSplitPane( xSplitPos, ySplitPos, leftmostColumn, topRow )Adds a split pane to the sheet.
Arguments
xSplitPos
Integer
Yes
Horizontal split position (1/20th pixel)
ySplitPos
Integer
Yes
Vertical split position (1/20th pixel)
leftmostColumn
Integer
Yes
Leftmost visible column in right pane
topRow
Integer
Yes
Top visible row in bottom pane
Example
setRowBreak( row )
setRowBreak( row )Sets a page break at the specified row.
Arguments
row
Integer
Yes
Row number (1-based)
Example
setFitToPage( fitToPage, pagesWide, pagesHigh )
setFitToPage( fitToPage, pagesWide, pagesHigh )Sets fit-to-page print options.
Arguments
fitToPage
Boolean
Yes
Enable fit-to-page
pagesWide
Integer
Yes
Pages wide (0 = no constraint)
pagesHigh
Integer
Yes
Pages high (0 = no constraint)
Example
recalculateAllFormulas()
recalculateAllFormulas()Recalculates all formulas in the workbook.
Arguments
None
Example
Large File Streaming
process( path, consumer )
process( path, consumer )Streams rows from a file using memory-efficient processing.
Arguments
path
String
Yes
Path to spreadsheet file
consumer
Consumer
Yes
Callback receiving each row as Array
Example
process( path, sheetName, consumer )
process( path, sheetName, consumer )Streams rows from a specific sheet.
Arguments
path
String
Yes
Path to spreadsheet file
sheetName
String
Yes
Name of sheet to process
consumer
Consumer
Yes
Callback receiving each row as Array
Example
process( consumer )
process( consumer )Streams rows from currently loaded workbook.
Arguments
consumer
Consumer
Yes
Callback receiving each row as Array
Example
Information & Accessors
getSheetNames()
getSheetNames()Gets all sheet names in the workbook.
Arguments
None
Example
getRowCount()
getRowCount()Gets the number of rows in the active sheet.
Arguments
None
Example
getColumnCount()
getColumnCount()Gets the number of columns in the active sheet.
Arguments
None
Example
getColumnNames()
getColumnNames()Gets column names from the first row.
Arguments
None
Example
info()
info()Returns properties of the spreadsheet as a struct.
Arguments
None
Example
hasSheet( sheetName )
hasSheet( sheetName )Checks if a sheet exists.
Arguments
sheetName
String
Yes
Name of sheet to check
Example
🔗 Method Chaining
Most Fluent API methods return the SpreadsheetFile object, enabling method chaining:
📚 See Also
Large File Streaming Guide - Memory-efficient processing
Quick Start Guide - Get started in 5 minutes
User Guide - Comprehensive usage guide
Examples - Real-world code samples
Built-In Functions - Traditional BIF reference
🔗 External Resources
Apache POI Documentation - Underlying library
Last updated
Was this helpful?
