Answer the question
In order to leave comments, you need to log in
Google Sheets - how to get a list of all sheets?
We have a table with 100 sheets (Sheet1, Sheet2, Sheet3 ...). How to get a vertical list of all sheets:
Sheet1
Sheet2
Sheet3
?
Answer the question
In order to leave comments, you need to log in
function getSheetsListOnSeparateSheet(){ // пример вывода на отдельный лист
let ss = SpreadsheetApp.getActiveSpreadsheet();
let listWithSheetsNames = ss.insertSheet(0); // или куда вам нужно выводить список листов. 0 - добавляет лист на первое место
for (let i = 1; i < ss.getNumSheets(); i++){ // если используете другой способ вывода - замените i = 0
listWithSheetsNames.getRange(listWithSheetsNames.getLastRow() + 1, 1).setValue(ss.getSheets()[i].getSheetName());
}
}
public class MySpreadsheetIntegration {
public static void main(String[] args)
throws AuthenticationException, MalformedURLException, IOException, ServiceException {
SpreadsheetService service =
new SpreadsheetService("MySpreadsheetIntegration-v1");
// TODO: Authorize the service object for a specific user (see other sections)
// Define the URL to request. This should never change.
URL SPREADSHEET_FEED_URL = new URL(
"https://spreadsheets.google.com/feeds/spreadsheets/private/full");
// Make a request to the API and get all spreadsheets.
SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL,
SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
if (spreadsheets.size() == 0) {
// TODO: There were no spreadsheets, act accordingly.
}
// TODO: Choose a spreadsheet more intelligently based on your
// app's needs.
SpreadsheetEntry spreadsheet = spreadsheets.get(0);
System.out.println(spreadsheet.getTitle().getPlainText());
// Make a request to the API to fetch information about all
// worksheets in the spreadsheet.
List<WorksheetEntry> worksheets = spreadsheet.getWorksheets();
// Iterate through each worksheet in the spreadsheet.
for (WorksheetEntry worksheet : worksheets) {
// Get the worksheet's title, row count, and column count.
String title = worksheet.getTitle().getPlainText();
int rowCount = worksheet.getRowCount();
int colCount = worksheet.getColCount();
// Print the fetched information to the screen for this worksheet.
System.out.println("\t" + title + "- rows:" + rowCount + " cols: " + colCount);
}
}
}
SpreadsheetEntry spreadsheet = spreadsheets.get(0);
List<WorksheetEntry> worksheets = spreadsheet.getWorksheets();
// Iterate through each worksheet in the spreadsheet.
for (WorksheetEntry worksheet : worksheets) {
// Get the worksheet's title, row count, and column count.
String title = worksheet.getTitle().getPlainText();
System.out.println("\t" + title);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question