function main(workbook: ExcelScript.Workbook): TableData[] { const table = workbook.getWorksheet('Planilha1').getTables()[0]; const texts = table.getRange().getTexts(); let returnObjects: TableData[] = []; if (table.getRowCount() > 0) { returnObjects = returnObjectFromValues(texts); } // Adicione o objeto JSON inicial let initialObject = { "Cns": 991000, "quinzena": { "anoReferencia": 2024, "mesReferencia": 9, "quinzenaReferencia": 1 }, "Testamentos": returnObjects }; // Use JSON.stringify com um argumento de espaço para formatar a saÃda console.log(JSON.stringify(initialObject, null, 2)); return initialObject; } function returnObjectFromValues(values: string[][]): TableData[] { let objectArray: TableData[] = []; let objectKeys: string[] = []; for (let i = 0; i < values.length; i++) { if (i === 0) { objectKeys = values[i] continue; } let object: { [key: string]: string } = {} for (let j = 0; j < values[i].length; j++) { if (values[i][j] !== "") { // Verifique se a chave é uma data if (objectKeys[j].toLowerCase().includes("date")) { // Converta a data para o formato aaaa-mm-dd let date = new Date(values[i][j]); object[objectKeys[j]] = date.toISOString().split('T')[0]; } else if (objectKeys[j] === "revogacaoCartorioCns") { // Converta revogacaoCartorioCns para número inteiro object[objectKeys[j]] = parseInt(values[i][j], 10); } else { object[objectKeys[j]] = values[i][j] } } } objectArray.push(object as unknown as TableData); } return objectArray; } interface TableData { "Event ID": string Date: string Location: string Capacity: string Speakers: string }