Skip to main content
Version: 9.0.0

CSV

The CSV API provides functionality for working with CSV files in your application. Below are the available methods and their usage.

readCsvWorkBook

Description: Reads a CSV workbook based on the provided options.

ParameterTypeDescription
optionsReadCsvWorkBookOptionsReadCsvWorkBook Options.

ReadCsvWorkBookOptions

ParameterTypeDescription
filePathstringPath to the CSV file.
includeEmptyHeadersboolean (optional)Include empty headers in the result.
includeEmptyRowsboolean (optional)Include empty rows in the result.
includeEmptyColumnsboolean (optional)Include empty columns in the result.

Basic Usage

const result = await I.readCsvWorkBook({
filePath:`./relative-file-path.csv`
});
console.log(result);

deleteCsvWorkBook

Description: Deletes a CSV workbook based on the provided options.

ParameterTypeDescription
optionsDeleteCsvWorkBookOptionsDeleteCsvWorkBook Options.

DeleteCsvWorkBookOptions

ParameterTypeDescription
filePathstringPath to the CSV file to delete.

Basic Usage

const options = {
filePath: './relative-file-path.csv'
};
await I.deleteCsvWorkBook(options);

editCsvWorkBook

Description: Edits a CSV workbook based on the provided options.

ParameterTypeDescription
optionsEditCsvOptionsEditCsvWorkBook Options.

EditCsvOptions

ParameterTypeDescription
filePathstringPath to the CSV file to edit.
add{ sheets?, columns?, rows?, cells? }Specify additions like sheets, columns, rows, or cells.
edit{ cells? }Specify edits to cells.
delete{ sheets?, columns?, rows?, cells? }Specify deletions like sheets, columns, rows, or cells.

EditCellOptions

ParameterTypeDescription
sheetstringSheet name or index where the cell is located.
rownumberRow index of the cell.
columnnumberColumn index of the cell.
refstringReference of the cell.
valueanyNew value for the cell.

Basic Usage

const options = {
filePath: './relative-file-path.csv',
add: {
sheets: ['Sheet1'],
columns: [{
sheet: 'Sheet1',
index: 0,
header: 'Column1',
key: 'col1'
}],
rows: [{
sheet: 'Sheet1',
index: 0,
values: [1, 2, 3]
}],
cells: [{
sheet: 'Sheet1',
row: 1,
column: 1,
value: 'New Value'
}]
},
edit: {
cells: [{
sheet: 'Sheet1',
row: 1,
column: 1,
value: 'Updated Value'
}]
},
delete: {
sheets: ['Sheet1'],
columns: [{
sheet: 'Sheet1',
index: 0
}],
rows: [{
sheet: 'Sheet1',
index: 0
}],
cells: [{
sheet: 'Sheet1',
row: 1,
column: 1
}]
}
};
await I.editCsvWorkBook(options);

getCsvWorkBookColumns

Description: Gets columns from a CSV workbook.

ParameterTypeDescription
optionsGetCsvWorkBookColumnsOptionsGetCsvWorkBookColumns Options.

GetCsvWorkBookColumnsOptions

ParameterTypeDescription
filePathstringPath to the CSV file.
columns(number | string)[]Array of column indices or names to retrieve.

Basic Usage

const options = {
filePath: './relative-file-path.csv',
columns: [0, 'Column1']
};
const columns = await I.getCsvWorkBookColumns(options);
console.log(columns);

getCsvWorkBookRows

Description: Gets rows from a CSV workbook.

ParameterTypeDescription
optionsGetCsvWorkBookRowsOptionsGetCsvWorkBookRows Options.

GetCsvWorkBookRowsOptions

ParameterTypeDescription
filePathstringPath to the CSV file.
rowsnumber[]Array of row indices to retrieve.

Basic Usage

const options = {
filePath: './relative-file-path.csv',
rows: [0, 1, 2]
};
const rows = await I.getCsvWorkBookRows(options);
console.log(rows);

getCsvWorkBookCells

Description: Gets cells from a CSV workbook.

ParameterTypeDescription
optionsGetCsvWorkBookCellsOptionsGetCsvWorkBookCells Options.

GetCsvWorkBookCellsOptions

ParameterTypeDescription
filePathstringPath to the CSV file.
cells{ row?, column?, ref? }[]Array of cell locations (row, column, or ref) to retrieve.

Basic Usage

const options = {
filePath: './relative-file-path.csv',
cells: [{ row: 1, column: 0 }, { ref: 'A2' }]
};
const cells = await I.getCsvWorkBookCells(options);
console.log(cells);

getCsvWorkBookRange

Description: Gets a specific range from a CSV workbook.

ParameterTypeDescription
optionsGetCsvWorkBookRangeGetCsvWorkBookRange Options.

GetCsvWorkBookRange

ParameterTypeDescription
options.filePathstringPath to the CSV file.
options.sheetnumber or stringSheet index or name. (Optional)
options.includeEmptyHeadersbooleanInclude empty headers. (Optional)
options.includeEmptyRowsbooleanInclude empty rows. (Optional)
options.includeEmptyColumnsbooleanInclude empty columns. (Optional)
options.startColumnnumberStarting column index of the range.
options.endColumnnumberEnding column index of the range.
options.startRownumberStarting row index of the range.
options.endRownumberEnding row index of the range.

Basic Usage

const options = {
filePath: './relative-file-path.csv',
sheet: 'Sheet1',
includeEmptyHeaders: true,
includeEmptyRows: false,
includeEmptyColumns: true,
startColumn: 0,
endColumn: 2,
startRow: 1,
endRow: 3
};
const range = await I.getCsvWorkBookRange(options);
console.log(range);