Replace a Data Table
Replace the contents of an existing table with a CSV or Excel file.
Permissions Required
You must have Edit permissions to the data table for this request to succeed
Method Signature
replace(id: string, filePath: string): Promise<DataTable>;
replace(id: string, filePath: string, headerRow: number): Promise<DataTable>;
replace(id: string, filePath: string, headerRow: number, sheetNumber: number): Promise<DataTable>;
replace(id: string, filePath: string, callback: ClientMethodCallback<DataTable>): void;
replace(id: string, filePath: string, headerRow: number, callback: ClientMethodCallback<DataTable>): void;
replace(id: string, filePath: string, headerRow: number, sheetNumber: number, callback: ClientMethodCallback<DataTable>): void;
Parameter
Parameter | Type | Description |
---|---|---|
id | string | The id of the Data Table whose contents will be replaced |
filePath | string | The local path of the CSV, XLS or XLSX file whose contents will replace the existing Data Table |
tableName | string | Optional The name of the table to create. Defaults to the uploaded file name. |
headerRow | number | Optional The index of row containing column headers. Row counting starts at 1. |
sheetNumber | number | Optional The index of the worksheet to import for Excel files. Sheet counting starts at 1. Defaults to 1. |
returns | DataTable | The newly created Data Table |
Example
/*
* This example demonstrates replacing a Data Table in Cataltyic
* with a file.
*/
const { CatalyticClient } = require('@catalytic/sdk');
const catalytic = new CatalyticClient();
const existingTableId = '10000000-0000-0000-0000-000000000001';
const filePath = '/path/to/local/file.xlsx';
const tableName = 'New Data Table';
const headerRow = 1;
const sheetNumber = 1;
const dataTable = await catalytic.files.replace(existingTableId, filePath, tableName, headerRow, sheetNumber);
console.log(`Replaced Data Table "${dataTable.name}" with "${filePath}"`);
Updated about 3 years ago