Class SpreadsheetApp

גיליון אלקטרוניאפליקציה

לגשת לקבצים ב-Google Sheets וליצור קבצים חדשים. המחלקה הזו היא מחלקת האב של שירות הגיליון האלקטרוני.

מאפיינים

נכססוגתיאור
AutoFillSeriesAutoFillSeriesרשימה של סוגי הסדרות שמשמשות לחישוב ערכים במילוי אוטומטי.
BandingThemeBandingThemeרשימה של העיצובים האפשריים של פסים.
BooleanCriteriaBooleanCriteriaספירה של קריטריונים בוליאניים לעיצוב מותנה.
BorderStyleBorderStyleרשימה של הסגנונות התקפים להגדרת גבולות ב-Range.
ColorTypeColorTypeרשימה של סוגי צבעים אפשריים.
CopyPasteTypeCopyPasteTypeרשימה של סוגי ההדבקה האפשריים.
DataExecutionErrorCodeDataExecutionErrorCodeרשימה של קודי שגיאות אפשריים בהפעלת נתונים.
DataExecutionStateDataExecutionStateרשימה של מצבי הפעלה אפשריים של נתונים.
DataSourceParameterTypeDataSourceParameterTypeרשימה של סוגי הפרמטרים האפשריים של מקור הנתונים.
DataSourceRefreshScopeDataSourceRefreshScopeספירה של היקפי רענון אפשריים של מקורות נתונים.
DataSourceTypeDataSourceTypeרשימה של סוגי מקורות הנתונים האפשריים.
DataValidationCriteriaDataValidationCriteriaספירה שמייצגת את הקריטריונים לאימות הנתונים שאפשר להגדיר בטווח.
DateTimeGroupingRuleTypeDateTimeGroupingRuleTypeספירה של כלל קיבוץ לפי תאריך ושעה.
DeveloperMetadataLocationTypeDeveloperMetadataLocationTypeספירה של סוגי מיקומים אפשריים של מטא נתונים למפתחים.
DeveloperMetadataVisibilityDeveloperMetadataVisibilityרשימה של סטטוסי השיתוף האפשריים של המטא-נתונים של המפתח.
DimensionDimensionרשימה של המאפיינים האפשריים של גיליון אלקטרוני.
DirectionDirectionספירה של הכיוונים האפשריים שאפשר לנוע בהם בגיליון אלקטרוני באמצעות מקשי החיצים.
FrequencyTypeFrequencyTypeרשימה של סוגי תדירות אפשריים.
GroupControlTogglePositionGroupControlTogglePositionרשימה של המיקומים שבהם יכול להיות המתג של אמצעי הבקרה של הקבוצה.
InterpolationTypeInterpolationTypeספירה של סוגי אינטרפולציה של מעברי צבע בעיצוב מותנה.
PivotTableSummarizeFunctionPivotTableSummarizeFunctionרשימה של הפונקציות שאפשר להשתמש בהן לסיכום ערכים בטבלת צירים.
PivotValueDisplayTypePivotValueDisplayTypeרשימה של האפשרויות להצגת ערך בטבלת צירים.
ProtectionTypeProtectionTypeספירה שמייצגת את החלקים בגיליון האלקטרוני שאפשר להגן עליהם מפני עריכות.
RecalculationIntervalRecalculationIntervalרשימה של המרווחים האפשריים שאפשר להשתמש בהם בחישוב מחדש של גיליון אלקטרוני.
RelativeDateRelativeDateספירה של אפשרויות תאריכים יחסיים לחישוב ערך לשימוש ב-BooleanCriteria מבוסס-תאריך.
SheetTypeSheetTypeרשימה של הסוגים השונים של גיליונות שיכולים להיות בגיליון אלקטרוני.
SortOrderSortOrderספירה של סדר המיון.
TextDirectionTextDirectionרשימה של כיווני טקסט תקינים.
TextToColumnsDelimiterTextToColumnsDelimiterרשימה של תווי ההפרדה המוגדרים מראש לפיצול טקסט לעמודות.
ThemeColorTypeThemeColorTypeרשימה של סוגי צבעי עיצוב אפשריים.
ValueTypeValueTypeספירה של סוגי ערכים שמוחזרים על ידי Range.getValue() ו-Range.getValues() מהמחלקה Range של שירות הגיליון האלקטרוני. ערכי המספור שמפורטים בהמשך הם בנוסף לערכים Number,‏ Boolean,‏ Date או String.
WrapStrategyWrapStrategyרשימה של האסטרטגיות שמשמשות להוספת גלישת טקסט לתאים.

Methods

שיטהסוג הערך שמוחזרתיאור קצר
create(name)Spreadsheetיצירת גיליון אלקטרוני חדש עם השם שצוין.
create(name, rows, columns)Spreadsheetהפונקציה יוצרת גיליון אלקטרוני חדש עם השם שצוין ומספר השורות והעמודות שצוינו.
enableAllDataSourcesExecution()voidהפעלת ביצוע נתונים לכל סוגי מקורות הנתונים.
enableBigQueryExecution()voidהפעלה של הפעלות של נתונים במקורות נתונים של BigQuery.
enableLookerExecution()voidהפעלת הפעלות של נתונים במקורות נתונים של Looker.
flush()voidהשינוי יחול על כל הגיליון האלקטרוני.
getActive()Spreadsheetמחזירה את הגיליון האלקטרוני שפעיל כרגע, או null אם אין גיליון כזה.
getActiveRange()Rangeהפונקציה מחזירה את הטווח שנבחר בגיליון הפעיל, או null אם אין טווח פעיל.
getActiveRangeList()RangeList|nullמחזירה את רשימת הטווחים הפעילים בגיליון הפעיל או null אם לא נבחרו טווחים.
getActiveSheet()Sheetמחזירה את הגיליון הפעיל בגיליון אלקטרוני.
getActiveSpreadsheet()Spreadsheetמחזירה את הגיליון האלקטרוני שפעיל כרגע, או null אם אין גיליון כזה.
getCurrentCell()Range|nullהפונקציה מחזירה את התא הנוכחי (המסומן) שנבחר באחד מהטווחים הפעילים בגיליון הפעיל, או null אם אין תא נוכחי.
getSelection()Selectionהפונקציה מחזירה את התאריך הנוכחי Selection בגיליון האלקטרוני.
getUi()Uiהפונקציה מחזירה מופע של סביבת ממשק המשתמש של הגיליון האלקטרוני, שמאפשר לסקריפט להוסיף תכונות כמו תפריטים, תיבות דו-שיח וסרגלי צד.
newCellImage()CellImageBuilderיוצרת Builder ל-CellImage.
newColor()ColorBuilderיוצרת Builder ל-Color.
newConditionalFormatRule()ConditionalFormatRuleBuilderיוצר builder לכלל של עיצוב מותנה.
newDataSourceSpec()DataSourceSpecBuilderיוצרת Builder ל-DataSourceSpec.
newDataValidation()DataValidationBuilderיוצרת כלי ליצירת כלל לאימות נתונים.
newFilterCriteria()FilterCriteriaBuilderיוצרת Builder ל-FilterCriteria.
newRichTextValue()RichTextValueBuilderיוצרת כלי ליצירת ערך של טקסט עשיר.
newTextStyle()TextStyleBuilderיוצרת כלי ליצירת סגנון טקסט.
open(file)Spreadsheetפותח את הגיליון האלקטרוני שמתאים לאובייקט הקובץ שצוין.
openById(id)Spreadsheetפותח את הגיליון האלקטרוני עם המזהה שצוין.
openByUrl(url)Spreadsheetפותח את הגיליון האלקטרוני עם כתובת ה-URL שצוינה.
setActiveRange(range)Rangeמגדיר את הטווח שצוין כactive range, כשהתא העליון הימני בטווח הוא current cell.
setActiveRangeList(rangeList)RangeListהמדיניות הזו מגדירה את רשימת הטווחים שצוינה כ-active ranges.
setActiveSheet(sheet)Sheetהפונקציה מגדירה את הגיליון הפעיל בגיליון אלקטרוני.
setActiveSheet(sheet, restoreSelection)Sheetהפעולה מגדירה את הגיליון הפעיל בגיליון אלקטרוני, עם אפשרות לשחזור הבחירה האחרונה בגיליון הזה.
setActiveSpreadsheet(newActiveSpreadsheet)voidהגדרת הגיליון האלקטרוני הפעיל.
setCurrentCell(cell)Rangeהגדרת התא שצוין כcurrent cell.

תיעוד מפורט

create(name)

יצירת גיליון אלקטרוני חדש עם השם שצוין.

// The code below creates a new spreadsheet "Finances" and logs the URL for it
const ssNew = SpreadsheetApp.create('Finances');
Logger.log(ssNew.getUrl());

פרמטרים

שםסוגתיאור
nameStringהשם של הגיליון האלקטרוני.

חזרה

Spreadsheet — גיליון אלקטרוני חדש

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets

create(name, rows, columns)

הפונקציה יוצרת גיליון אלקטרוני חדש עם השם שצוין ומספר השורות והעמודות שצוינו.

// The code below creates a new spreadsheet "Finances" with 50 rows and 5
// columns and logs the URL for it
const ssNew = SpreadsheetApp.create('Finances', 50, 5);
Logger.log(ssNew.getUrl());

פרמטרים

שםסוגתיאור
nameStringהשם של הגיליון האלקטרוני.
rowsIntegerמספר השורות בגיליון האלקטרוני.
columnsIntegerמספר העמודות בגיליון האלקטרוני.

חזרה

Spreadsheet — גיליון אלקטרוני חדש

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets

enableAllDataSourcesExecution()

הפעלת ביצוע נתונים לכל סוגי מקורות הנתונים.

הפעלת הנתונים מעלה חריגה אם סוג מקור הנתונים לא מופעל. אפשר להשתמש בשיטה הזו כדי להפעיל את ההרצה של נתונים בכל סוגי מקורות הנתונים.

// Turns data execution on for all types of data sources.
SpreadsheetApp.enableAllDataSourcesExecution();

// Opens the spreadsheet file by its ID. If you created your script from a
// Google Sheets file, use SpreadsheetApp.getActiveSpreadsheet().
// TODO(developer): Replace the ID with your own.
const ss = SpreadsheetApp.openById('abc123456');

// Gets the first data source sheet in the spreadsheet and refreshes the data.
ss.getDataSourceSheets()[0].refreshData();

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/bigquery.readonly

enableBigQueryExecution()

הפעלה של הפעלות של נתונים במקורות נתונים של BigQuery.

אם האפשרות הזו לא מופעלת, מתקבל חריג בהרצת נתונים במקור נתונים של BigQuery.

// Turns data execution on for BigQuery data sources.
SpreadsheetApp.enableBigQueryExecution();

// Opens the spreadsheet file by its ID. If you created your script from a
// Google Sheets file, use SpreadsheetApp.getActiveSpreadsheet().
// TODO(developer): Replace the ID with your own.
const ss = SpreadsheetApp.openById('abc123456');

// Gets the first data source sheet in the spreadsheet and refreshes the
// BigQuery data.
ss.getDataSourceSheets()[0].refreshData();

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/bigquery.readonly

enableLookerExecution()

הפעלת הפעלות של נתונים במקורות נתונים של Looker.

אם לא מפעילים את האפשרות 'הפעלת נתונים' במקור נתונים של Looker, מוצג חריג.

// Turns data execution on for Looker data sources.
SpreadsheetApp.enableLookerExecution();

// Opens the spreadsheet file by its ID. If you created your script from a
// Google Sheets file, use SpreadsheetApp.getActiveSpreadsheet().
// TODO(developer): Replace the ID with your own.
const ss = SpreadsheetApp.openById('abc123456');

// Gets the first data source sheet in the spreadsheet and refreshes the
// associated Looker data.
ss.getDataSourceSheets()[0].refreshData();

flush()

השינוי יחול על כל הגיליון האלקטרוני.

לפעמים פעולות בגיליון אלקטרוני נארזות יחד כדי לשפר את הביצועים, למשל כשמבצעים כמה קריאות ל-Range.getValue(). עם זאת, לפעמים כדאי לוודא שכל השינויים בהמתנה יתבצעו באופן מיידי, למשל כדי להציג למשתמשים נתונים בזמן שהסקריפט פועל.

// The code below changes the background color of cells A1 and B1 twenty times.
// You should be able to see the updates live in the spreadsheet. If flush() is
// not called, the updates may be applied live or may all be applied at once
// when the script completes.
function colors() {
  const sheet = SpreadsheetApp.getActiveSheet();
  for (let i = 0; i < 20; i++) {
    if (i % 2 === 0) {
      sheet.getRange('A1').setBackground('green');
      sheet.getRange('B1').setBackground('red');
    } else {
      sheet.getRange('A1').setBackground('red');
      sheet.getRange('B1').setBackground('green');
    }
    SpreadsheetApp.flush();
  }
}

getActive()

מחזירה את הגיליון האלקטרוני שפעיל כרגע, או null אם אין גיליון כזה.

פונקציות שמופעלות בהקשר של גיליון אלקטרוני יכולות לקבל הפניה לאובייקט הגיליון האלקטרוני המתאים על ידי קריאה לפונקציה הזו.

// The code below logs the URL for the active spreadsheet.
Logger.log(SpreadsheetApp.getActive().getUrl());

חזרה

Spreadsheet – אובייקט הגיליון האלקטרוני הפעיל

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getActiveRange()

הפונקציה מחזירה את הטווח שנבחר בגיליון הפעיל, או null אם אין טווח פעיל. אם נבחרו כמה טווחים, השיטה הזו מחזירה רק את הטווח האחרון שנבחר.

בדרך כלל הכוונה היא לטווח שהמשתמש בחר בגיליון הפעיל, אבל בפונקציה מותאמת אישית הכוונה היא לתא שמתבצע בו חישוב מחדש באופן פעיל.

// The code below logs the background color for the active range.
const colorObject = SpreadsheetApp.getActiveRange().getBackgroundObject();
// Assume the color has ColorType.RGB.
Logger.log(colorObject.asRgbColor().asHexString());

חזרה

Range — הטווח הפעיל.

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getActiveRangeList()

מחזירה את רשימת הטווחים הפעילים בגיליון הפעיל או null אם לא נבחרו טווחים. הטווח הפעיל שמכיל את התא המודגש הנוכחי מופיע אחרון ברשימה.

אם נבחר טווח יחיד, הפעולה תהיה כמו getActiveRange().

// Returns the list of active ranges.
const rangeList = SpreadsheetApp.getActiveRangeList();

חזרה

RangeList|null — רשימת הטווחים הפעילים

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getActiveSheet()

מחזירה את הגיליון הפעיל בגיליון אלקטרוני.

הגיליון הפעיל בגיליון אלקטרוני הוא הגיליון שמוצג בממשק המשתמש של הגיליון האלקטרוני.

// The code below logs the name of the active sheet.
Logger.log(SpreadsheetApp.getActiveSheet().getName());

חזרה

Sheet — אובייקט הגיליון הפעיל

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getActiveSpreadsheet()

מחזירה את הגיליון האלקטרוני שפעיל כרגע, או null אם אין גיליון כזה.

פונקציות שמופעלות בהקשר של גיליון אלקטרוני יכולות לקבל הפניה לאובייקט Spreadsheet המתאים על ידי קריאה לפונקציה הזו.

// The code below logs the URL for the active spreadsheet.
Logger.log(SpreadsheetApp.getActiveSpreadsheet().getUrl());

חזרה

Spreadsheet – אובייקט הגיליון האלקטרוני הפעיל

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getCurrentCell()

הפונקציה מחזירה את התא הנוכחי (המסומן) שנבחר באחד מהטווחים הפעילים בגיליון הפעיל, או null אם אין תא נוכחי.

// Returns the current highlighted cell in the one of the active ranges.
const currentCell = SpreadsheetApp.getCurrentCell();

חזרה

Range|null – התא הנוכחי

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getSelection()

הפונקציה מחזירה את התאריך הנוכחי Selection בגיליון האלקטרוני.

const selection = SpreadsheetApp.getSelection();
const currentCell = selection.getCurrentCell();

חזרה

Selection – הבחירה הנוכחית

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getUi()

הפונקציה מחזירה מופע של סביבת ממשק המשתמש של הגיליון האלקטרוני, שמאפשר לסקריפט להוסיף תכונות כמו תפריטים, תיבות דו-שיח וסרגלי צד. סקריפט יכול לבצע אינטראקציה עם ממשק המשתמש רק עבור המופע הנוכחי של גיליון אלקטרוני פתוח, ורק אם הסקריפט מקשר לגיליון האלקטרוני. מידע נוסף זמין במדריכים בנושא תפריטים ותיבות דו-שיח וסרגלי צד.

// Add a custom menu to the active spreadsheet, including a separator and a
// sub-menu.
function onOpen(e) {
  SpreadsheetApp.getUi()
      .createMenu('My Menu')
      .addItem('My menu item', 'myFunction')
      .addSeparator()
      .addSubMenu(
          SpreadsheetApp.getUi()
              .createMenu('My sub-menu')
              .addItem('One sub-menu item', 'mySecondFunction')
              .addItem('Another sub-menu item', 'myThirdFunction'),
          )
      .addToUi();
}

חזרה

Ui – מופע של סביבת ממשק המשתמש של הגיליון האלקטרוני הזה


newCellImage()

יוצרת Builder ל-CellImage.

// Opens the spreadsheet file by its URL. If you created your script from within
// a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet()
// instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
    'https://docs.google.com/spreadsheets/d/abc123456/edit',
);

// Gets Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets cell A1 on Sheet1.
const range = sheet.getRange('A1');

// Builds an image using a source URL.
const cellImage =
    SpreadsheetApp.newCellImage()
        .setSourceUrl(
            'https://www.gstatic.com/images/branding/productlogos/apps_script/v10/web-64dp/logo_apps_script_color_1x_web_64dp.png',
            )
        .build();

// Sets the image in cell A1.
range.setValue(cellImage);

חזרה

CellImageBuilder – הכלי החדש ליצירת קהלים.


newColor()

יוצרת Builder ל-Color.

const rgbColor = SpreadsheetApp.newColor().setRgbColor('#FF0000').build();

חזרה

ColorBuilder – הכלי החדש ליצירת קהלים.


newConditionalFormatRule()

יוצר builder לכלל של עיצוב מותנה.

// Adds a conditional format rule to a sheet that causes all cells in range
// A1:B3 to turn red if they contain a number between 1 and 10.
const sheet = SpreadsheetApp.getActive().getActiveSheet();
const range = sheet.getRange('A1:B3');
const rule = SpreadsheetApp.newConditionalFormatRule()
                 .whenNumberBetween(1, 10)
                 .setBackground('#FF0000')
                 .setRanges([range])
                 .build();
const rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

חזרה

ConditionalFormatRuleBuilder – הכלי החדש ליצירת קהלים.


newDataSourceSpec()

יוצרת Builder ל-DataSourceSpec.

// Opens the spreadsheet file by its URL. If you created your script from within
// a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet()
// instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
    'https://docs.google.com/spreadsheets/d/abc123456/edit',
);

// Enables BigQuery.
SpreadsheetApp.enableBigQueryExecution();

// Builds a data source specification.
// TODO (developer): Update the project ID to your own Google Cloud project ID.
const dataSourceSpec = SpreadsheetApp.newDataSourceSpec()
                           .asBigQuery()
                           .setProjectId('project-id-1')
                           .setTableProjectId('bigquery-public-data')
                           .setDatasetId('ncaa_basketball')
                           .setTableId('mbb_historical_teams_games')
                           .build();

// Adds the data source and its data to the spreadsheet.
ss.insertDataSourceSheet(dataSourceSpec);

חזרה

DataSourceSpecBuilder – הכלי החדש ליצירת קהלים.


newDataValidation()

יוצרת כלי ליצירת כלל לאימות נתונים.

const cell = SpreadsheetApp.getActive().getRange('A1');
const rule = SpreadsheetApp.newDataValidation()
                 .requireNumberBetween(1, 100)
                 .setAllowInvalid(false)
                 .setHelpText('Number must be between 1 and 100.')
                 .build();
cell.setDataValidation(rule);

חזרה

DataValidationBuilder – הכלי החדש ליצירת קהלים.


newFilterCriteria()

יוצרת Builder ל-FilterCriteria.

// Opens the spreadsheet file by its URL. If you created your script from within
// a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet()
// instead.
// TODO(developer): Replace the URL with your own.
const ss = SpreadsheetApp.openByUrl(
    'https://docs.google.com/spreadsheets/d/abc123456/edit',
);

// Gets Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Sets the range to A1:D20.
const range = sheet.getRange('A1:D20');

// Creates a filter and applies it to the specified range.
range.createFilter();

// Gets the current filter for the range and creates filter criteria that only
// shows cells that aren't empty.
const filter = range.getFilter();
const criteria = SpreadsheetApp.newFilterCriteria().whenCellNotEmpty().build();

// Sets the criteria to  column C.
filter.setColumnFilterCriteria(3, criteria);

חזרה

FilterCriteriaBuilder — הכלי החדש ליצירת אתרים


newRichTextValue()

יוצרת כלי ליצירת ערך של טקסט עשיר.

// Sets cell A1 to have the text "Hello world", with "Hello" bolded.
const cell = SpreadsheetApp.getActive().getRange('A1');
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const value = SpreadsheetApp.newRichTextValue()
                  .setText('Hello world')
                  .setTextStyle(0, 5, bold)
                  .build();
cell.setRichTextValue(value);

חזרה

RichTextValueBuilder – הכלי החדש ליצירת קהלים.


newTextStyle()

יוצרת כלי ליצירת סגנון טקסט.

// Sets range A1:B3 to have red, size 22, bolded, underlined text.
const range = SpreadsheetApp.getActive().getRange('A1:B3');
const style = SpreadsheetApp.newTextStyle()
                  .setForegroundColor('red')
                  .setFontSize(22)
                  .setBold(true)
                  .setUnderline(true)
                  .build();
range.setTextStyle(style);

חזרה

TextStyleBuilder – הכלי החדש ליצירת קהלים.


open(file)

פותח את הגיליון האלקטרוני שמתאים לאובייקט הקובץ שצוין.

// Get any starred spreadsheets from Google Drive, then open the spreadsheets
// and log the name of the first sheet within each spreadsheet.
const files = DriveApp.searchFiles(
    `starred = true and mimeType = "${MimeType.GOOGLE_SHEETS}"`,
);
while (files.hasNext()) {
  const spreadsheet = SpreadsheetApp.open(files.next());
  const sheet = spreadsheet.getSheets()[0];
  Logger.log(sheet.getName());
}

פרמטרים

שםסוגתיאור
fileFileהקובץ שרוצים לפתוח.

חזרה

Spreadsheet — הגיליון האלקטרוני

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets

openById(id)

פותח את הגיליון האלקטרוני עם המזהה שצוין. אפשר לחלץ את המזהה של הגיליון האלקטרוני מכתובת ה-URL שלו. לדוגמה, המזהה של הגיליון האלקטרוני בכתובת ה-URL ‏https://docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 הוא abc1234567.

// The code below opens a spreadsheet using its ID and logs the name for it.
// Note that the spreadsheet is NOT physically opened on the client side.
// It is opened on the server only (for modification by the script).
const ss = SpreadsheetApp.openById('abc1234567');
Logger.log(ss.getName());

פרמטרים

שםסוגתיאור
idStringהמזהה הייחודי של הגיליון האלקטרוני.

חזרה

Spreadsheet — אובייקט הגיליון האלקטרוני עם המזהה הנתון

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets

openByUrl(url)

פותח את הגיליון האלקטרוני עם כתובת ה-URL שצוינה. מוצג חריג של סקריפט אם כתובת ה-URL לא קיימת או אם למשתמש אין הרשאה לגשת אליה.

// Opens a spreadsheet by its URL and logs its name.
// Note that the spreadsheet doesn't physically open on the client side.
// It opens on the server only (for modification by the script).
const ss = SpreadsheetApp.openByUrl(
    'https://docs.google.com/spreadsheets/d/abc1234567/edit',
);
console.log(ss.getName());

פרמטרים

שםסוגתיאור
urlStringכתובת ה-URL של הגיליון האלקטרוני.

חזרה

Spreadsheet — אובייקט הגיליון האלקטרוני עם כתובת ה-URL שצוינה.

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets

setActiveRange(range)

מגדיר את הטווח שצוין כactive range, כשהתא העליון הימני בטווח הוא current cell.

בממשק המשתמש של הגיליון האלקטרוני מוצג הגיליון שמכיל את הטווח שנבחר, והתאים שמוגדרים בטווח שנבחר מסומנים.

// The code below sets range C1:D4 in the first sheet as the active range.
const range =
    SpreadsheetApp.getActiveSpreadsheet().getSheets()[0].getRange('C1:D4');
SpreadsheetApp.setActiveRange(range);

const selection = SpreadsheetApp.getSelection();
// Current cell: C1
const currentCell = selection.getCurrentCell();
// Active Range: C1:D4
const activeRange = selection.getActiveRange();

פרמטרים

שםסוגתיאור
rangeRangeהטווח שרוצים להגדיר כטווח הפעיל.

חזרה

Range – הטווח הפעיל החדש


setActiveRangeList(rangeList)

המדיניות הזו מגדירה את רשימת הטווחים שצוינה כ-active ranges. הטווח האחרון ברשימה מוגדר כ-active range.

// The code below sets ranges [D4, B2:C4] in the active sheet as the active
// ranges.
const rangeList = SpreadsheetApp.getActiveSheet().getRanges(['D4', 'B2:C4']);
SpreadsheetApp.setActiveRangeList(rangeList);

const selection = SpreadsheetApp.getSelection();
// Current cell: B2
const currentCell = selection.getCurrentCell();
// Active range: B2:C4
const activeRange = selection.getActiveRange();
// Active range list: [D4, B2:C4]
const activeRangeList = selection.getActiveRangeList();

פרמטרים

שםסוגתיאור
rangeListRangeListרשימת הטווחים לבחירה.

חזרה

RangeList – רשימת הטווחים החדשה שנבחרה

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setActiveSheet(sheet)

הפונקציה מגדירה את הגיליון הפעיל בגיליון אלקטרוני. ממשק המשתמש של Google Sheets מציג את הגיליון שנבחר, אלא אם הגיליון שייך לגיליון אלקטרוני אחר.

// The code below makes the 2nd sheet active in the active spreadsheet.
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[1]);

פרמטרים

שםסוגתיאור
sheetSheetהגיליון הפעיל החדש.

חזרה

Sheet – הגיליון שהוגדר כגיליון הפעיל החדש


setActiveSheet(sheet, restoreSelection)

הפעולה מגדירה את הגיליון הפעיל בגיליון אלקטרוני, עם אפשרות לשחזור הבחירה האחרונה בגיליון הזה. ממשק המשתמש של Google Sheets מציג את הגיליון שנבחר, אלא אם הגיליון שייך לגיליון אלקטרוני אחר.

const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const firstSheet = spreadsheet.getSheets()[0];
const secondSheet = spreadsheet.getSheets()[1];
// Set the first sheet as the active sheet and select the range D4:F4.
spreadsheet.setActiveSheet(firstSheet).getRange('D4:F4').activate();

// Switch to the second sheet to do some work.
spreadsheet.setActiveSheet(secondSheet);
// Switch back to first sheet, and restore its selection.
spreadsheet.setActiveSheet(firstSheet, true);

// The selection of first sheet is restored, and it logs D4:F4
const range = spreadsheet.getActiveSheet().getSelection().getActiveRange();
Logger.log(range.getA1Notation());

פרמטרים

שםסוגתיאור
sheetSheetהגיליון הפעיל החדש.
restoreSelectionBooleanאם true, הבחירה האחרונה בגיליון הפעיל החדש נבחרת שוב כשהגיליון החדש הופך לפעיל. אם false, הגיליון החדש הופך לפעיל בלי לשנות את הבחירה הנוכחית.

חזרה

Sheet – הגיליון הפעיל החדש

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setActiveSpreadsheet(newActiveSpreadsheet)

הגדרת הגיליון האלקטרוני הפעיל.

// The code below makes the spreadsheet with key "1234567890" the active
// spreadsheet
const ss = SpreadsheetApp.openById('1234567890');
SpreadsheetApp.setActiveSpreadsheet(ss);

פרמטרים

שםסוגתיאור
newActiveSpreadsheetSpreadsheetהגיליון האלקטרוני שרוצים להפוך לגיליון האלקטרוני הפעיל.

setCurrentCell(cell)

הגדרת התא שצוין כcurrent cell.

אם התא שצוין נמצא בטווח שכבר נבחר, הטווח הזה הופך לטווח הפעיל והתא הופך לתא הנוכחי.

אם התא שצוין לא נמצא באף אחד מהטווחים שנבחרו, הבחירה הקיימת תוסר והתא יהפוך לתא הנוכחי ולטווח הפעיל.

הערה: הפרמטר Range שצוין חייב להיות תא אחד, אחרת השיטה הזו תזרוק חריגה.

// The code below sets the cell B5 in the first sheet as the current cell.
const cell =
    SpreadsheetApp.getActiveSpreadsheet().getSheets()[0].getRange('B5');
SpreadsheetApp.setCurrentCell(cell);

const selection = SpreadsheetApp.getSelection();
// Current cell: B5
const currentCell = selection.getCurrentCell();

פרמטרים

שםסוגתיאור
cellRangeהתא שרוצים להגדיר כתא הנוכחי.

חזרה

Range – התא הנוכחי החדש שהוגדר

אישור

סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets