Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

310
Views
Download Google Sheets file and read data using SheetJS on Node

I have a spreadsheet on Google Sheets that contains some data. I have published it publicly, so that I can download the data as an .xlsx file using a URL. What I want to do is the following in Node:

  • Download the file from the URL
  • Prepare the contents as ArrayBuffer
  • Read it using SheetJS

The following is the URL for the file: Google Sheets link.

Going by SheetJS library, I know I need to use XLSX.read(data, opts), but I can't seem to figure out how to do it exactly. I have the following code so far:

var https = require('https');
var fs = require('fs');
var XLSX = require("xlsx");

var fileURL = "https://docs.google.com/spreadsheets/d/e/2PACX-1vR9jv7gj6o0dtL0QoeHxW7Ux2fk0Br6slV3mg-uzZY6hc17Zw-_cXRz0-pilCeZx_lDzaRAo0tNfueT/pub?output=xlsx"

// Somehow use the url to read the file using XLSX.read(data, opts) and store it in a variable called workbook

var sheet1 = workbook.Sheets[workbook.SheetNames[0]]
var sheet2 = workbook.Sheets[workbook.SheetNames[1]]
        
console.log(XLSX.utils.sheet_to_json(sheet1));
console.log(XLSX.utils.sheet_to_json(sheet2));

How do I actually do this? I can work with a file locally perfectly fine, but with the URL approach, I'm pretty lost. Any help is appreciated!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In your situation, how about the following modification?

Modified script:

const request = require("request");
const XLSX = require("xlsx");

const fileURL =
  "https://docs.google.com/spreadsheets/d/e/2PACX-1vR9jv7gj6o0dtL0QoeHxW7Ux2fk0Br6slV3mg-uzZY6hc17Zw-_cXRz0-pilCeZx_lDzaRAo0tNfueT/pub?output=xlsx";

request.get(fileURL, { encoding: null }, function (err, res, data) {
  if (err || res.statusCode != 200) {
    console.log(res.statusCode);
    return;
  }
  const buf = Buffer.from(data);
  const workbook = XLSX.read(buf);

  var sheet1 = workbook.Sheets[workbook.SheetNames[0]];
  var sheet2 = workbook.Sheets[workbook.SheetNames[1]];
  console.log(XLSX.utils.sheet_to_json(sheet1));
  console.log(XLSX.utils.sheet_to_json(sheet2));
});
  • In this modification, the module of request is used.

Result:

When this script is run, the following result is obtained.

[
  { Team: 'Manchester United' },
  { Team: 'PSG' },
  { Team: 'Barcelona' },
  { Team: 'Real Madrid' },
  { Team: 'Juventus' }
]
[
  { Name: 'Ronaldo', Age: 37 },
  { Name: 'Messi', Age: 34 },
  { Name: 'Neymar', Age: 30 }
]
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!