Excel Actions
readExcelWorkBook
Description: Reads an Excel workbook based on the provided options.
Parameter | Type | Description |
---|---|---|
options | ReadExcelWorkBookOptions | ReadExcelWorkBook Options. |
ReadExcelWorkBookOptions
Parameter | Type | Description |
---|---|---|
filePath | string | Path to the Excel file. |
sheet | number | string | Sheet name or index to read from (optional, default: 0). |
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 options = {
filePath: './relative-file-path.xlsx',
sheet: 'Sheet1',
includeEmptyHeaders: true
};
const result = await Excel.readExcelWorkBook(options);
console.log(result);
deleteExcelWorkBook
Description: Deletes an Excel workbook based on the provided options.
Parameter | Type | Description |
---|---|---|
options | DeleteExcelWorkBookOptions | DeleteExcelWorkBook Options. |
DeleteExcelWorkBookOptions
Parameter | Type | Description |
---|---|---|
filePath | string | Path to the Excel file to delete. |
Basic Usage
await Excel.deleteExcelWorkBook({
filePath: './relative-file-path.xlsx'
});
editExcelWorkBook
Description: Edits an Excel workbook based on the provided options.
Parameter | Type | Description |
---|---|---|
filePath | string | Path to the Excel file. |
add | object (optional) | Add new elements to the Excel workbook. |
edit | object (optional) | Edit existing elements in the Excel workbook. |
delete | object (optional) | Delete elements from the Excel workbook. |
add
Parameter | Type | Description |
---|---|---|
sheets | string[] (optional) | Array of sheet names or numbers to add. |
columns | { sheet, index, header, key, width? }[] | Array of columns to add. |
rows | { sheet, index, values[] }[] | Array of rows to add. |
cells | EditCellOptions[] | Array of cells to add. |
edit
Parameter | Type | Description |
---|---|---|
cells | EditCellOptions[] | Array of cells to edit. |
delete
Parameter | Type | Description |
---|---|---|
sheets | (string | number)[] | Array of sheet names or numbers to delete. |
columns | { sheet, index }[] | Array of columns to delete. |
rows | { sheet, index }[] | Array of rows to delete. |
cells | Omit<EditCellOptions, 'value'>[] | Array of cells to delete. |
Basic Usage
const options: EditExcelWorkBookOptions = {
filePath: "./path/to/excel-file.xlsx",
add: {
sheets: ["Sheet1"],
columns: [{ sheet: "Sheet1", index: 1, header: "Column1", key: "key1", width: 100 }],
rows: [{ sheet: "Sheet1", index: 1, values: ["Value1", "Value2"] }],
cells: [{ sheet: "Sheet1", row: 1, column: 1, value: "New Value" }],
},
edit: {
cells: [{ sheet: "Sheet1", row: 1, column: 1, value: "Edited Value" }],
},
delete: {
sheets: ["Sheet1"],
columns: [{ sheet: "Sheet1", index: 1 }],
rows: [{ sheet: "Sheet1", index: 1 }],
cells: [{ sheet: "Sheet1", row: 1, column: 1 }],
},
};
await Excel.editExcelWorkBook(options);
getExcelWorkBookColumns
Description: Gets columns from an Excel workbook.
Parameter | Type | Description |
---|---|---|
filePath | string | Path to the Excel file. |
sheet | number | string (optional) | Sheet number or name. |
columns | (number | string)[] | Columns to retrieve. |
Basic Usage
// Example 1: Retrieve all columns from the default sheet
const columns1 = await Excel.getExcelWorkBookColumns({ filePath: "./path/to/excel-file.xlsx" });
console.log(columns1);
// Example 2: Retrieve columns from a specific sheet
const columns2 = await Excel.getExcelWorkBookColumns({ filePath: "./path/to/excel-file.xlsx", sheet: "Sheet1" });
console.log(columns2);
// Example 3: Retrieve specific columns from the default sheet
const columns3 = await Excel.getExcelWorkBookColumns({ filePath: "./path/to/excel-file.xlsx", columns: [1, "Column2"] });
console.log(columns3);
getExcelWorkBookRows
Description: Gets rows from an Excel workbook.
Parameter | Type | Description |
---|---|---|
filePath | string | Path to the Excel file. |
sheet | number | string (optional) | Sheet number or name. |
rows | number[] | Rows to retrieve. |
Basic Usage
// Example 1: Retrieve all rows from the default sheet
const rows1 = await Excel.getExcelWorkBookRows({ filePath: "./path/to/excel-file.xlsx" });
console.log(rows1);
// Example 2: Retrieve rows from a specific sheet
const rows2 = await Excel.getExcelWorkBookRows({ filePath: "./path/to/excel-file.xlsx", sheet: "Sheet1" });
console.log(rows2);
// Example 3: Retrieve specific rows from the default sheet
const rows3 = await Excel.getExcelWorkBookRows({ filePath: "./path/to/excel-file.xlsx", rows: [1, 3, 5] });
console.log(rows3);
getExcelWorkBookCells
Description: Gets cells from an Excel workbook.
Parameter | Type | Description |
---|---|---|
filePath | string | Path to the Excel file. |
sheet | number | string (optional) | Sheet number or name. |
cells | {row?: number, column?: number, ref?: string}[] | Cells to retrieve. |
Basic Usage
const cells = await Excel.getExcelWorkBookCells(options);
console.log(cells);
getExcelWorkBookRange
Description: Gets a specific range from an Excel workbook.
Parameter | Type | Description |
---|---|---|
filePath | string | Path to the Excel file. |
sheet | number / string (optional) | Sheet number or name. |
startColumn | number | Starting column index. |
endColumn | number | Ending column index. |
startRow | number | Starting row index. |
endRow | number | Ending row index. |
Basic Usage
const range = await Excel.getExcelWorkBookRange(options);
console.log(range);