Skip to content

Instantly share code, notes, and snippets.

@RaniAgus
Last active October 14, 2022 21:00
Show Gist options
  • Select an option

  • Save RaniAgus/08c862d34e505c8a7d5921450b5c22f4 to your computer and use it in GitHub Desktop.

Select an option

Save RaniAgus/08c862d34e505c8a7d5921450b5c22f4 to your computer and use it in GitHub Desktop.
Convertir Google Sheet a JSON
const axios = require('axios').default;
const { read, utils } = require('xlsx');
require('dotenv').config();
const getSpreadsheet = async({ id, gid = 0, index = 0 }) => {
const { data } = await axios({
method: 'get',
url: `https://docs.google.com/spreadsheets/d/${id}/export`,
responseType: 'arraybuffer',
params: { format: 'xlsx', id, gid },
});
const workbook = read(data);
return utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[index]], { raw: false })
}
getSpreadsheet({ id: process.env.GROUPS_SHEETS_ID }).then(console.log);
{
"dependencies": {
"axios": "^0.27.2",
"dotenv": "^16.0.1",
"xlsx": "^0.18.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment