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.
Parameter | Type | Description |
---|---|---|
options | ReadCsvWorkBookOptions | ReadCsvWorkBook Options. |
ReadCsvWorkBookOptions
Parameter | Type | Description |
---|---|---|
filePath | string | Path to the CSV file. |
includeEmptyHeaders | boolean (optional) | Include empty headers in the result. |
includeEmptyRows | boolean (optional) | Include empty rows in the result. |
includeEmptyColumns | boolean (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.
Parameter | Type | Description |
---|---|---|
options | DeleteCsvWorkBookOptions | DeleteCsvWorkBook Options. |
DeleteCsvWorkBookOptions
Parameter | Type | Description |
---|---|---|
filePath | string | Path 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.
Parameter | Type | Description |
---|---|---|
options | EditCsvOptions | EditCsvWorkBook Options. |
EditCsvOptions
Parameter | Type | Description |
---|---|---|
filePath | string | Path 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
Parameter | Type | Description |
---|---|---|
sheet | string | Sheet name or index where the cell is located. |
row | number | Row index of the cell. |
column | number | Column index of the cell. |
ref | string | Reference of the cell. |
value | any | New 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.
Parameter | Type | Description |
---|---|---|
options | GetCsvWorkBookColumnsOptions | GetCsvWorkBookColumns Options. |
GetCsvWorkBookColumnsOptions
Parameter | Type | Description |
---|---|---|
filePath | string | Path 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.
Parameter | Type | Description |
---|---|---|
options | GetCsvWorkBookRowsOptions | GetCsvWorkBookRows Options. |
GetCsvWorkBookRowsOptions
Parameter | Type | Description |
---|---|---|
filePath | string | Path to the CSV file. |
rows | number[] | 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.
Parameter | Type | Description |
---|---|---|
options | GetCsvWorkBookCellsOptions | GetCsvWorkBookCells Options. |
GetCsvWorkBookCellsOptions
Parameter | Type | Description |
---|---|---|
filePath | string | Path 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.
Parameter | Type | Description |
---|---|---|
options | GetCsvWorkBookRange | GetCsvWorkBookRange Options. |
GetCsvWorkBookRange
Parameter | Type | Description |
---|---|---|
options.filePath | string | Path to the CSV file. |
options.sheet | number or string | Sheet index or name. (Optional) |
options.includeEmptyHeaders | boolean | Include empty headers. (Optional) |
options.includeEmptyRows | boolean | Include empty rows. (Optional) |
options.includeEmptyColumns | boolean | Include empty columns. (Optional) |
options.startColumn | number | Starting column index of the range. |
options.endColumn | number | Ending column index of the range. |
options.startRow | number | Starting row index of the range. |
options.endRow | number | Ending 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);