writeExcel

fun <T> DataFrame<T>.writeExcel(path: String, columnsSelector: ColumnsSelector<T, *> = { all() }, sheetName: String? = null, writeHeader: Boolean = true, workBookType: WorkBookType = WorkBookType.XLSX, keepFile: Boolean = false)

Writes this DataFrame to an Excel file as a single sheet.

Implemented with Apache POI using HSSFWorkbook for XLS files, XSSFWorkbook for standard XLSX files, and SXSSFWorkbook for memory-efficient streaming when creating new XLSX files.

Parameters

path

The path to the file where the data will be written.

columnsSelector

A selector to determine which columns to include in the file. The default is all columns.

sheetName

The name of the sheet in the Excel file. If null, the default name will be used.

writeHeader

A flag indicating whether to write the header row in the Excel file. Defaults to true.

workBookType

The type of workbook to create (e.g., XLS or XLSX). Defaults to XLSX.

keepFile

If true and the file already exists, a new sheet will be appended instead of overwriting the file. This may result in higher memory usage and slower performance compared to creating a new file. Defaults to false.

Throws

if the sheetName is invalid or the workbook already contains a sheet with this name.


fun <T> DataFrame<T>.writeExcel(file: File, columnsSelector: ColumnsSelector<T, *> = { all() }, sheetName: String? = null, writeHeader: Boolean = true, workBookType: WorkBookType = WorkBookType.XLSX, keepFile: Boolean = false)

Writes this DataFrame to an Excel file as a single sheet.

Implemented with Apache POI using HSSFWorkbook for XLS files, XSSFWorkbook for standard XLSX files, and SXSSFWorkbook for memory-efficient streaming when creating new XLSX files.

Parameters

file

The file where the data will be written.

columnsSelector

A selector to determine which columns to include in the file. The default is all columns.

sheetName

The name of the sheet in the Excel file. If null, the default name will be used.

writeHeader

A flag indicating whether to write the header row in the Excel file. Defaults to true.

workBookType

The type of workbook to create (e.g., XLS or XLSX). Defaults to XLSX.

keepFile

If true and the file already exists, a new sheet will be appended instead of overwriting the file. This may result in higher memory usage and slower performance compared to creating a new file. Defaults to false.

Throws

if the sheetName is invalid or the workbook already contains a sheet with this name.


fun <T> DataFrame<T>.writeExcel(path: Path, columnsSelector: ColumnsSelector<T, *> = { all() }, sheetName: String? = null, writeHeader: Boolean = true, workBookType: WorkBookType = WorkBookType.XLSX, keepFile: Boolean = false)

Writes this DataFrame to an Excel file as a single sheet.

Implemented with Apache POI using HSSFWorkbook for XLS files, XSSFWorkbook for standard XLSX files, and SXSSFWorkbook for memory-efficient streaming when creating new XLSX files.

Parameters

path

The path to a file where the data will be written.

columnsSelector

A selector to determine which columns to include in the file. The default is all columns.

sheetName

The name of the sheet in the Excel file. If null, the default name will be used.

writeHeader

A flag indicating whether to write the header row in the Excel file. Defaults to true.

workBookType

The type of workbook to create (e.g., XLS or XLSX). Defaults to XLSX.

keepFile

If true and the file already exists, a new sheet will be appended instead of overwriting the file. This may result in higher memory usage and slower performance compared to creating a new file. Defaults to false.

Throws

if the sheetName is invalid or the workbook already contains a sheet with this name.


fun <T> DataFrame<T>.writeExcel(outputStream: OutputStream, columnsSelector: ColumnsSelector<T, *> = { all() }, sheetName: String? = null, writeHeader: Boolean = true, factory: Workbook)

Writes this DataFrame to an Excel file using an existing Workbook instance into given OutputStream.

Uses Apache POI. Supports XSSFWorkbook and SXSSFWorkbook for XLSX and HSSFWorkbook for XLS, and allows users to manage the workbook externally.

Parameters

outputStream

The output stream where the Excel data will be written.

columnsSelector

A selector to determine which columns to include in the file. The default is all columns.

sheetName

The name of the sheet in the Excel file. If null, the default name will be used.

writeHeader

A flag indicating whether to write the header row in the Excel file. Defaults to true.

factory

The Workbook instance, allowing integration with an existing workbook.

Throws

if the sheetName is invalid or the workbook already contains a sheet with this name.


fun <T> DataFrame<T>.writeExcel(wb: Workbook, columnsSelector: ColumnsSelector<T, *> = { all() }, sheetName: String? = null, writeHeader: Boolean = true): Sheet

Creates a new Sheet in the given Workbook and writes this DataFrame content into it.

Uses Apache POI. Supports XSSFWorkbook and SXSSFWorkbook for XLSX and HSSFWorkbook for XLS, and allows users to manage the workbook externally.

Automatically handles datetime types. Skips null values to prevent Apache POI from treating empty cells incorrectly.

Return

The created Sheet instance containing the DataFrame data.

Parameters

wb

The Workbook where the sheet will be created.

columnsSelector

A selector to determine which columns to include. Defaults to all columns.

sheetName

The name of the sheet. If null, a default sheet name is used.

writeHeader

Whether to include a header row with column names. Defaults to true.

Throws

if the sheetName is invalid or the workbook already contains a sheet with this name.