n8n-nodes-base
Version:
Base nodes of n8n
96 lines • 3.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.description = void 0;
exports.execute = execute;
const utilities_1 = require("../../../../../../utils/utilities");
const transport_1 = require("../../transport");
const common_descriptions_1 = require("../common.descriptions");
const properties = [
common_descriptions_1.workbookRLC,
common_descriptions_1.worksheetRLC,
{
displayName: 'Apply To',
name: 'applyTo',
type: 'options',
//values in capital case as required by api
options: [
{
name: 'All',
value: 'All',
description: 'Clear data in cells and remove all formatting',
},
{
name: 'Formats',
value: 'Formats',
description: 'Clear formatting(e.g. font size, color) of cells',
},
{
name: 'Contents',
value: 'Contents',
description: 'Clear data contained in cells',
},
],
default: 'All',
},
{
displayName: 'Select a Range',
name: 'useRange',
type: 'boolean',
default: false,
},
{
displayName: 'Range',
name: 'range',
type: 'string',
displayOptions: {
show: {
useRange: [true],
},
},
placeholder: 'e.g. A1:B2',
default: '',
description: 'The sheet range that would be cleared, specified using a A1-style notation',
hint: 'Leave blank for entire worksheet',
},
];
const displayOptions = {
show: {
resource: ['worksheet'],
operation: ['clear'],
},
};
exports.description = (0, utilities_1.updateDisplayOptions)(displayOptions, properties);
async function execute(items) {
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
const workbookId = this.getNodeParameter('workbook', i, undefined, {
extractValue: true,
});
const worksheetId = this.getNodeParameter('worksheet', i, undefined, {
extractValue: true,
});
const applyTo = this.getNodeParameter('applyTo', i);
const useRange = this.getNodeParameter('useRange', i, false);
if (!useRange) {
await transport_1.microsoftApiRequest.call(this, 'POST', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/range/clear`, { applyTo });
}
else {
const range = this.getNodeParameter('range', i, '');
await transport_1.microsoftApiRequest.call(this, 'POST', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/range(address='${range}')/clear`, { applyTo });
}
const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ success: true }), { itemData: { item: i } });
returnData.push(...executionData);
}
catch (error) {
if (this.continueOnFail()) {
const executionErrorData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: error.message }), { itemData: { item: i } });
returnData.push(...executionErrorData);
continue;
}
throw error;
}
}
return returnData;
}
//# sourceMappingURL=clear.operation.js.map