n8n-nodes-base
Version:
Base nodes of n8n
98 lines • 3.75 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: 'Select Range',
name: 'selectRange',
type: 'options',
options: [
{
name: 'Automatically',
value: 'auto',
description: 'The whole used range on the selected sheet will be converted into a table',
},
{
name: 'Manually',
value: 'manual',
description: 'Select a range that will be converted into a table',
},
],
default: 'auto',
},
{
displayName: 'Range',
name: 'range',
type: 'string',
default: '',
placeholder: 'A1:B2',
description: 'The range of cells that will be converted to a table',
displayOptions: {
show: {
selectRange: ['manual'],
},
},
},
{
displayName: 'Has Headers',
name: 'hasHeaders',
type: 'boolean',
default: true,
description: 'Whether the range has column labels. When this property set to false Excel will automatically generate header shifting the data down by one row.',
},
];
const displayOptions = {
show: {
resource: ['table'],
operation: ['addTable'],
},
};
exports.description = (0, utilities_1.updateDisplayOptions)(displayOptions, properties);
async function execute(items) {
//https://learn.microsoft.com/en-us/graph/api/worksheet-post-tables?view=graph-rest-1.0
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 selectRange = this.getNodeParameter('selectRange', i);
const hasHeaders = this.getNodeParameter('hasHeaders', i);
let range = '';
if (selectRange === 'auto') {
const { address } = await transport_1.microsoftApiRequest.call(this, 'GET', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/usedRange`, undefined, {
select: 'address',
});
range = address.split('!')[1];
}
else {
range = this.getNodeParameter('range', i);
}
const responseData = await transport_1.microsoftApiRequest.call(this, 'POST', `/drive/items/${workbookId}/workbook/worksheets/${worksheetId}/tables/add`, {
address: range,
hasHeaders,
});
const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { 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=addTable.operation.js.map