Estoy escribiendo un programa que toma los datos de una gran hoja de cálculo de Google, los trata y los manipula y los conecta con otras hojas en el mismo archivo. Para mejorar mi tiempo de ejecución y hacer una base de datos de respaldo.
Me gustaría almacenar los datos en un archivo JSON en algún lugar que pueda usar fácilmente en el script de Google Apps nuevamente (creo que Google Drive es la mejor opción gratuita). ¿Cómo logro esto?
Le agradecería que pudiera mostrar los códigos exactos que guardan el siguiente archivo en Google Drive y luego lo vuelven a leer en el script.
let listA = [{id: 34, performance: 200, supervisor: 'A', name: 'Aethelwich'}, {id: 35, performance: 300, supervisor: 'B', name: 'Aethelram'}, {id: 36, performance: 400, supervisor: 'A', name: 'Aethelham'}, {id: 41, performance: 500, supervisor: 'A', name: 'Aethelfred'}]; let jsonObject = JSON.stringify(listA); // 1. code to save this jsonObject to Google Drive // 2. code to retrieve the same saved JSON file back from google drivePara lograr su objetivo, ¿qué le parece el siguiente script de muestra?
let listA = [{ id: 34, performance: 200, supervisor: 'A', name: 'Aethelwich' }, { id: 35, performance: 300, supervisor: 'B', name: 'Aethelram' }, { id: 36, performance: 400, supervisor: 'A', name: 'Aethelham' }, { id: 41, performance: 500, supervisor: 'A', name: 'Aethelfred' }]; let jsonObject = JSON.stringify(listA); // Save the data as a file. const file = DriveApp.createFile("sample.txt", jsonObject); // Or, if you want to put the file to the specific folder, please use DriveApp.getFolderById("folderID").createFile("sample.txt", jsonObject) const fileId = file.getId(); console.log(fileId) // Retrieve the data from the file. const text = DriveApp.getFileById(fileId).getBlob().getDataAsString(); // please set the file ID of the saved file. const array = JSON.parse(text); console.log(array)