English 中文(简体)
• 如何使每张URL,将其放在A1号系列中,自动使用所有电子表格的斜面书写方式?
原标题:How to get each sheet URL and set it in range A1 automatically using googlesheet script for all the sheets in spreadsheet?

我想利用谷歌字母逐个缩略语,在每张表格的A1号中贴出斜面,以便我能够稍后在一份MAIN表上收集。

请注意,“Main”的名字在文字上被忽略,因此该文字将不上“URL”号。

我试图在这里做文字,但给我留下错误。

function getUrl() {
  const urls = SpreadsheetApp.getActive().getSheets().map(s => s.getUrl());
  SpreadsheetApp.getActive().getSheets().forEach(s => {
    s.getRange( B3 ).setValue(s.getUrl());
  });
}
最佳回答

我认为你的目标如下。

  • You want to retrieve the URL of each sheet except for "Main" sheet.
  • You want to put the URL into cell "A1" of each sheet.

Modification points:

  • Unfortunately, Class Sheet has no method of getUrl.
  • You say I want to use Googlesheet script to exctract each sheet URL and paste it in range A1 of each sheet. But, in your scirpt, s.getRange( B3 ).setValue(s.getUrl()); is used.

如果这些要点反映在样本中,则如下。

Sample script:

function getUrl() {
  const ignoreSheet = "Main"; // This is from your question.

  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const baseUrl = ss.getUrl();
  const sheets = ss.getSheets();
  sheets.forEach(sheet => {
    if (sheet.getSheetName() != ignoreSheet) {
      sheet.getRange("A1").setValue(`${baseUrl}#gid=${sheet.getSheetId()}`);
    }
  });
}
  • In this case, the URL of each sheet is created by "getUrl() of Class Spreadsheet" and "getSheetId() of Class Sheet".
  • When this script is run, the URLs of each sheet except for "Main" sheet are retrieved and each URL is put into cell "A1" of each sheet.

References:

Added:

您的以下二点:

如果我想忽略多份说明,而不是只一份表格,例如“Main”和“CS”的表,那么我会做些什么?

In this case, how about the following sample script?

function getUrl() {
  const ignoreSheets = ["Main", "CS"]; // This is from your question.

  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const baseUrl = ss.getUrl();
  const sheets = ss.getSheets();
  sheets.forEach(sheet => {
    if (!ignoreSheets.includes(sheet.getSheetName())) {
      sheet.getRange("A1").setValue(`${baseUrl}#gid=${sheet.getSheetId()}`);
    }
  });
}
问题回答

暂无回答




相关问题
How to use year counter google app script?

I need an urgent help i have data as follows in a google sheet i need to add a year counter to the column d as follows using google apps script

Google Spreadsheet multiple column filter using OR

I have a Google Spreadsheet with 3 columns that are either blank or have a value. I want to get the count of the number of rows that has A and either B or C populated. If I were writing a SQL query ...

Run Google Apps Script on Google-Spreadsheet event?

If I create a Google apps script, can I hook it up to Google spreadsheet to run based on an event, or must I manually invoke it? I don t know if Google Sheets supports any events. For example: a ...

How do I insert a row in to a Google spreadsheet using c#

I ve seen; Accessing Google Spreadsheets with C# using Google Data API and http://code.google.com/apis/spreadsheets/data/2.0/developers_guide_dotnet.html#CreatingRows However i m still having ...

using Zend_Gdata_Spreadsheets for public spreadsheets?

I have this code which is working, to load a Google Spreadsheet and load some data from it. If the spreadsheet in question is public, how do i modify the code to not require a username/password? $key=...

Programatically updating a Google spreadsheet

I ve got a pre-existing Google spreadsheet. Each month I update this document. I ve got a template workseet in the spreadseet that I d like to clone and then update. I d prefer to clone the ...

热门标签