I can get all data from tab spreadsheet using sheet=Jan24_12pm, but can't find out how to get all tab names or gid's of a spreadsheets? In this example there is 11 tabs/sheets
function drawChart() {
var query = new google.visualization.Query('https://docs.google.com/spreadsheets/d/169AP3oaJZSMTquxtrkgFYMSp4gTApLTTWqo25qCpjL0/gviz/tq?sheet=Jan24_12pm&tq=select%20*');
query.send(drawTable);
}
UPD: I am not the owner and the document is not published "We're sorry. This document is not published.". But I can access it with google.visualization.Query
Thanks
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
In this pattern, the sheet names are retrieved by Web Apps. Web Apps is used as the wrapper. At the client side, you can retrieve the sheet names from the Spreadsheet using the Web Apps.
Sample script of Web Apps is a Google Apps Script. So please create a project of Google Apps Script.
If you want to directly create it, please access to https://script.new/. In this case, if you are not logged in Google, the log in screen is opened. So please log in to Google. By this, the script editor of Google Apps Script is opened.
Please copy and paste the following script.
function doGet(e) {
var spreadsheetId = e.parameter.id;
var sheets = SpreadsheetApp.openById(spreadsheetId).getSheets();
var sheetNames = sheets.map(function(e) {return e.getSheetName()});
return ContentService.createTextOutput(JSON.stringify({sheetNames: sheetNames})).setMimeType(ContentService.MimeType.JSON);
}
https://script.google.com/macros/s/###/exec.
In order to retrieve the sheet names from Web Apps at the client side, please use the following script.
var url = "https://script.google.com/macros/s/###/exec?id=169AP3oaJZSMTquxtrkgFYMSp4gTApLTTWqo25qCpjL0";
fetch(url)
.then(function(response) {
return response.json();
})
.then(function(obj) {
console.log(obj.sheetNames) // You can see the sheet names as an array.
});
In this pattern, the sheet names are retrieved by publishing the Spreadsheet to Web.
Please publish the Spreadsheet to Web. Ref
var url = "https://spreadsheets.google.com/feeds/worksheets/169AP3oaJZSMTquxtrkgFYMSp4gTApLTTWqo25qCpjL0/public/basic?alt=json";
fetch(url)
.then(function(response) {
return response.json();
})
.then(function(obj) {
const sheetNames = obj.feed.entry.map( e => e.title["$t"]);
console.log(sheetNames) // You can see the sheet names as an array.
});
If I misunderstood your question and this was not the direction you want, I apologize.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With