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.


📋 Quick Navigation


Creating & Loading

Spreadsheet()

Creates a new empty spreadsheet in XLSX format with a default sheet named "Sheet1".

Arguments

None

Example


Spreadsheet( path )

Creates or loads a spreadsheet from the specified path.

Arguments

Name
Type
Required
Description

path

String

Yes

Path to the spreadsheet file

Example


Spreadsheet( path, load )

Loads an existing spreadsheet file or creates a new one.

Arguments

Name
Type
Required
Description

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 )

Loads a spreadsheet file from the specified path.

Arguments

Name
Type
Required
Description

path

String

Yes

Fully qualified path to spreadsheet file

Example


load( path, password )

Loads a password-protected spreadsheet file.

Arguments

Name
Type
Required
Description

path

String

Yes

Fully qualified path to spreadsheet file

password

String

Yes

Password to decrypt the file

Example


fromJson( json )

Creates a spreadsheet from JSON string data (array of objects).

Arguments

Name
Type
Required
Description

json

String

Yes

JSON string containing array of objects

Example


fromArray( data )

Creates a spreadsheet from an array of structs.

Arguments

Name
Type
Required
Description

data

Array

Yes

Array of structs where each struct is a row

Example


fromQuery( query )

Creates a spreadsheet from a BoxLang query.

Arguments

Name
Type
Required
Description

query

Query

Yes

A BoxLang query object

Example


Saving

save()

Saves the spreadsheet to the currently loaded path.

Arguments

None

Example


save( path )

Saves the spreadsheet to the specified path.

Arguments

Name
Type
Required
Description

path

String

Yes

Path where file should be saved

Example


save( path, password )

Saves the spreadsheet with password protection.

Arguments

Name
Type
Required
Description

path

String

Yes

Path where file should be saved

password

String

Yes

Password to protect the file

Example


saveAndClose()

Saves the spreadsheet and closes the workbook.

Arguments

None

Example


Sheet Management

createSheet( sheetName )

Creates a new sheet with the specified name.

Arguments

Name
Type
Required
Description

sheetName

String

Yes

Name of the new sheet

Example


createSheet( sheetName, overwrite )

Creates a new sheet with optional overwrite.

Arguments

Name
Type
Required
Description

sheetName

String

Yes

Name of the new sheet

overwrite

Boolean

Yes

Whether to overwrite existing sheet

Example


selectSheet( sheetName )

Selects (activates) a sheet by name for subsequent operations.

Arguments

Name
Type
Required
Description

sheetName

String

Yes

Name of sheet to activate

Example


selectSheet( sheetIndex )

Selects (activates) a sheet by index (1-based).

Arguments

Name
Type
Required
Description

sheetIndex

Integer

Yes

Index of sheet to activate (1-based)

Example


removeSheet( sheetName )

Removes a sheet by name.

Arguments

Name
Type
Required
Description

sheetName

String

Yes

Name of sheet to remove

Example


renameSheet( oldName, newName )

Renames an existing sheet.

Arguments

Name
Type
Required
Description

oldName

String

Yes

Current name of the sheet

newName

String

Yes

New name for the sheet

Example


copySheet( fromName, toName )

Copies a sheet with a new name.

Arguments

Name
Type
Required
Description

fromName

String

Yes

Name of sheet to copy from

toName

String

Yes

Name of new sheet

Example


hideSheet( sheetName )

Hides a sheet from view.

Arguments

Name
Type
Required
Description

sheetName

String

Yes

Name of sheet to hide

Example


unhideSheet( sheetName )

Unhides a sheet to make it visible.

Arguments

Name
Type
Required
Description

sheetName

String

Yes

Name of sheet to unhide

Example


moveSheet( sheetName, toIndex )

Moves a sheet to a new position.

Arguments

Name
Type
Required
Description

sheetName

String

Yes

Name of sheet to move

toIndex

Integer

Yes

Target position (0-based)

Example


Cell Operations

setCellValue( row, col, value )

Sets a cell value at the specified row and column.

Arguments

Name
Type
Required
Description

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 )

Gets a cell value at the specified row and column.

Arguments

Name
Type
Required
Description

row

Integer

Yes

Row number (1-based)

col

Integer

Yes

Column number (1-based)

Example


formatCell( row, col, format )

Formats a single cell.

Arguments

Name
Type
Required
Description

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 )

Adds a new row at the end of the sheet.

Arguments

Name
Type
Required
Description

values

Array

Yes

Array of cell values for the row

Example


setRowData( row, values )

Sets multiple cell values in a row.

Arguments

Name
Type
Required
Description

row

Integer

Yes

Row number (1-based)

values

Array

Yes

Array of values starting from column 1

Example


getRowData( row )

Gets all cell values from a row.

Arguments

Name
Type
Required
Description

row

Integer

Yes

Row number (1-based)

Example


formatRow( row, format )

Formats all cells in a single row.

Arguments

Name
Type
Required
Description

row

Integer

Yes

Row number (1-based)

format

Struct

Yes

Formatting options

Example


formatRows( rows, format )

Formats multiple rows specified by range or list.

Arguments

Name
Type
Required
Description

rows

String

Yes

Row specification: "1,3,5" or "1-5" or combinations

format

Struct

Yes

Formatting options

Example


removeRow( rowIndex )

Removes a row from the sheet.

Arguments

Name
Type
Required
Description

rowIndex

Integer

Yes

Row number to remove (1-based)

Example


addRows( data )

Adds multiple rows from a 2D array.

Arguments

Name
Type
Required
Description

data

Array

Yes

Array of arrays representing rows

Example


Column Operations

formatColumn( column, format )

Formats all cells in a single column.

Arguments

Name
Type
Required
Description

column

Integer

Yes

Column number (1-based)

format

Struct

Yes

Formatting options

Example


formatColumns( columns, format )

Formats multiple columns specified by range or list.

Arguments

Name
Type
Required
Description

columns

String

Yes

Column specification: "1,3,5" or "1-5"

format

Struct

Yes

Formatting options

Example


deleteColumn( column )

Deletes a column by clearing all cells.

Arguments

Name
Type
Required
Description

column

Integer

Yes

Column number (1-based)

Example


autoSizeColumn( column )

Auto-sizes a specific column to fit content.

Arguments

Name
Type
Required
Description

column

Integer

Yes

Column number (1-based)

Example


autoSizeColumns()

Auto-sizes all columns in the active sheet.

Arguments

None

Example


Data Conversion

toArray()

Converts sheet data to array of structs (first row as headers).

Arguments

None

Example


toQuery()

Converts sheet data to query format (array of structs).

Arguments

None

Example


toJson()

Converts sheet data to JSON string.

Arguments

None

Example


toJson( pretty )

Converts sheet data to JSON string with optional formatting.

Arguments

Name
Type
Required
Description

pretty

Boolean

Yes

Whether to pretty-print the JSON

Example


toMatrix()

Converts sheet to 2D array matrix (including headers).

Arguments

None

Example


toCSV()

Converts sheet data to CSV format.

Arguments

None

Example


toCSV( options )

Converts sheet data to CSV with custom options.

Arguments

Name
Type
Required
Description

options

Struct

Yes

CSV options: delimiter, includeHeaders, lineSeparator

Example


Formatting

formatCell( row, col, format )

Formats a cell with multiple style options.

Arguments

Name
Type
Required
Description

row

Integer

Yes

Row number (1-based)

col

Integer

Yes

Column number (1-based)

format

Struct

Yes

Style options

Format Options:

  • bold (Boolean) - Bold text

  • italic (Boolean) - Italic text

  • underline (Boolean) - Underline text

  • fontsize (Integer) - Font size in points

  • font (String) - Font name

  • fontColor (String) - Font color

  • fgcolor (String) - Background color

  • alignment (String) - Horizontal alignment

  • verticalalignment (String) - Vertical alignment

  • dataformat (String) - Number/date format

Example


Advanced Features

addFreezePane( column, row )

Freezes columns and rows for scrolling.

Arguments

Name
Type
Required
Description

column

Integer

Yes

Columns to left are frozen

row

Integer

Yes

Rows above are frozen

Example


addSplitPane( xSplitPos, ySplitPos, leftmostColumn, topRow )

Adds a split pane to the sheet.

Arguments

Name
Type
Required
Description

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 )

Sets a page break at the specified row.

Arguments

Name
Type
Required
Description

row

Integer

Yes

Row number (1-based)

Example


setFitToPage( fitToPage, pagesWide, pagesHigh )

Sets fit-to-page print options.

Arguments

Name
Type
Required
Description

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()

Recalculates all formulas in the workbook.

Arguments

None

Example


Large File Streaming

process( path, consumer )

Streams rows from a file using memory-efficient processing.

Arguments

Name
Type
Required
Description

path

String

Yes

Path to spreadsheet file

consumer

Consumer

Yes

Callback receiving each row as Array

Example


process( path, sheetName, consumer )

Streams rows from a specific sheet.

Arguments

Name
Type
Required
Description

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 )

Streams rows from currently loaded workbook.

Arguments

Name
Type
Required
Description

consumer

Consumer

Yes

Callback receiving each row as Array

Example

Memory Efficient: Streaming keeps only ~100 rows in memory at a time. See the Large File Streaming Guide for complete details.


Information & Accessors

getSheetNames()

Gets all sheet names in the workbook.

Arguments

None

Example


getRowCount()

Gets the number of rows in the active sheet.

Arguments

None

Example


getColumnCount()

Gets the number of columns in the active sheet.

Arguments

None

Example


getColumnNames()

Gets column names from the first row.

Arguments

None

Example


info()

Returns properties of the spreadsheet as a struct.

Arguments

None

Example


hasSheet( sheetName )

Checks if a sheet exists.

Arguments

Name
Type
Required
Description

sheetName

String

Yes

Name of sheet to check

Example


🔗 Method Chaining

Most Fluent API methods return the SpreadsheetFile object, enabling method chaining:


📚 See Also


🔗 External Resources

Last updated

Was this helpful?