Last active
October 14, 2022 21:00
-
-
Save RaniAgus/08c862d34e505c8a7d5921450b5c22f4 to your computer and use it in GitHub Desktop.
Convertir Google Sheet a JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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