לגשת לקבצים ב-Google Sheets וליצור קבצים חדשים. המחלקה הזו היא מחלקת האב של שירות הגיליון האלקטרוני.
מאפיינים
| נכס | סוג | תיאור |
|---|---|---|
Auto | Auto | רשימה של סוגי הסדרות שמשמשות לחישוב ערכים במילוי אוטומטי. |
Banding | Banding | רשימה של העיצובים האפשריים של פסים. |
Boolean | Boolean | ספירה של קריטריונים בוליאניים לעיצוב מותנה. |
Border | Border | רשימה של הסגנונות התקפים להגדרת גבולות ב-Range. |
Color | Color | רשימה של סוגי צבעים אפשריים. |
Copy | Copy | רשימה של סוגי ההדבקה האפשריים. |
Data | Data | רשימה של קודי שגיאות אפשריים בהפעלת נתונים. |
Data | Data | רשימה של מצבי הפעלה אפשריים של נתונים. |
Data | Data | רשימה של סוגי הפרמטרים האפשריים של מקור הנתונים. |
Data | Data | ספירה של היקפי רענון אפשריים של מקורות נתונים. |
Data | Data | רשימה של סוגי מקורות הנתונים האפשריים. |
Data | Data | ספירה שמייצגת את הקריטריונים לאימות הנתונים שאפשר להגדיר בטווח. |
Date | Date | ספירה של כלל קיבוץ לפי תאריך ושעה. |
Developer | Developer | ספירה של סוגי מיקומים אפשריים של מטא נתונים למפתחים. |
Developer | Developer | רשימה של סטטוסי השיתוף האפשריים של המטא-נתונים של המפתח. |
Dimension | Dimension | רשימה של המאפיינים האפשריים של גיליון אלקטרוני. |
Direction | Direction | ספירה של הכיוונים האפשריים שאפשר לנוע בהם בגיליון אלקטרוני באמצעות מקשי החיצים. |
Frequency | Frequency | רשימה של סוגי תדירות אפשריים. |
Group | Group | רשימה של המיקומים שבהם יכול להיות המתג של אמצעי הבקרה של הקבוצה. |
Interpolation | Interpolation | ספירה של סוגי אינטרפולציה של מעברי צבע בעיצוב מותנה. |
Pivot | Pivot | רשימה של הפונקציות שאפשר להשתמש בהן לסיכום ערכים בטבלת צירים. |
Pivot | Pivot | רשימה של האפשרויות להצגת ערך בטבלת צירים. |
Protection | Protection | ספירה שמייצגת את החלקים בגיליון האלקטרוני שאפשר להגן עליהם מפני עריכות. |
Recalculation | Recalculation | רשימה של המרווחים האפשריים שאפשר להשתמש בהם בחישוב מחדש של גיליון אלקטרוני. |
Relative | Relative | ספירה של אפשרויות תאריכים יחסיים לחישוב ערך לשימוש ב-Boolean מבוסס-תאריך. |
Sheet | Sheet | רשימה של הסוגים השונים של גיליונות שיכולים להיות בגיליון אלקטרוני. |
Sort | Sort | ספירה של סדר המיון. |
Text | Text | רשימה של כיווני טקסט תקינים. |
Text | Text | רשימה של תווי ההפרדה המוגדרים מראש לפיצול טקסט לעמודות. |
Theme | Theme | רשימה של סוגי צבעי עיצוב אפשריים. |
Value | Value | ספירה של סוגי ערכים שמוחזרים על ידי Range.getValue() ו-Range.getValues() מהמחלקה Range של שירות הגיליון האלקטרוני. ערכי המספור שמפורטים בהמשך הם בנוסף לערכים Number, Boolean, Date או String. |
Wrap | Wrap | רשימה של האסטרטגיות שמשמשות להוספת גלישת טקסט לתאים. |
Methods
| שיטה | סוג הערך שמוחזר | תיאור קצר |
|---|---|---|
create(name) | Spreadsheet | יצירת גיליון אלקטרוני חדש עם השם שצוין. |
create(name, rows, columns) | Spreadsheet | הפונקציה יוצרת גיליון אלקטרוני חדש עם השם שצוין ומספר השורות והעמודות שצוינו. |
enable | void | הפעלת ביצוע נתונים לכל סוגי מקורות הנתונים. |
enable | void | הפעלה של הפעלות של נתונים במקורות נתונים של BigQuery. |
enable | void | הפעלת הפעלות של נתונים במקורות נתונים של Looker. |
flush() | void | השינוי יחול על כל הגיליון האלקטרוני. |
get | Spreadsheet | מחזירה את הגיליון האלקטרוני שפעיל כרגע, או null אם אין גיליון כזה. |
get | Range | הפונקציה מחזירה את הטווח שנבחר בגיליון הפעיל, או null אם אין טווח פעיל. |
get | Range | מחזירה את רשימת הטווחים הפעילים בגיליון הפעיל או null אם לא נבחרו טווחים. |
get | Sheet | מחזירה את הגיליון הפעיל בגיליון אלקטרוני. |
get | Spreadsheet | מחזירה את הגיליון האלקטרוני שפעיל כרגע, או null אם אין גיליון כזה. |
get | Range|null | הפונקציה מחזירה את התא הנוכחי (המסומן) שנבחר באחד מהטווחים הפעילים בגיליון הפעיל, או null אם אין תא נוכחי. |
get | Selection | הפונקציה מחזירה את התאריך הנוכחי Selection בגיליון האלקטרוני. |
get | Ui | הפונקציה מחזירה מופע של סביבת ממשק המשתמש של הגיליון האלקטרוני, שמאפשר לסקריפט להוסיף תכונות כמו תפריטים, תיבות דו-שיח וסרגלי צד. |
new | Cell | יוצרת Builder ל-Cell. |
new | Color | יוצרת Builder ל-Color. |
new | Conditional | יוצר builder לכלל של עיצוב מותנה. |
new | Data | יוצרת Builder ל-Data. |
new | Data | יוצרת כלי ליצירת כלל לאימות נתונים. |
new | Filter | יוצרת Builder ל-Filter. |
new | Rich | יוצרת כלי ליצירת ערך של טקסט עשיר. |
new | Text | יוצרת כלי ליצירת סגנון טקסט. |
open(file) | Spreadsheet | פותח את הגיליון האלקטרוני שמתאים לאובייקט הקובץ שצוין. |
open | Spreadsheet | פותח את הגיליון האלקטרוני עם המזהה שצוין. |
open | Spreadsheet | פותח את הגיליון האלקטרוני עם כתובת ה-URL שצוינה. |
set | Range | מגדיר את הטווח שצוין כactive range, כשהתא העליון הימני בטווח הוא current cell. |
set | Range | המדיניות הזו מגדירה את רשימת הטווחים שצוינה כ-active ranges. |
set | Sheet | הפונקציה מגדירה את הגיליון הפעיל בגיליון אלקטרוני. |
set | Sheet | הפעולה מגדירה את הגיליון הפעיל בגיליון אלקטרוני, עם אפשרות לשחזור הבחירה האחרונה בגיליון הזה. |
set | void | הגדרת הגיליון האלקטרוני הפעיל. |
set | 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());
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
name | String | השם של הגיליון האלקטרוני. |
חזרה
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());
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
name | String | השם של הגיליון האלקטרוני. |
rows | Integer | מספר השורות בגיליון האלקטרוני. |
columns | Integer | מספר העמודות בגיליון האלקטרוני. |
חזרה
Spreadsheet — גיליון אלקטרוני חדש
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets
enable All Data Sources Execution()
הפעלת ביצוע נתונים לכל סוגי מקורות הנתונים.
הפעלת הנתונים מעלה חריגה אם סוג מקור הנתונים לא מופעל. אפשר להשתמש בשיטה הזו כדי להפעיל את ההרצה של נתונים בכל סוגי מקורות הנתונים.
// 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
enable Big Query Execution()
הפעלה של הפעלות של נתונים במקורות נתונים של 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
enable Looker Execution()
הפעלת הפעלות של נתונים במקורות נתונים של 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(); } }
get Active()
מחזירה את הגיליון האלקטרוני שפעיל כרגע, או 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
get Active Range()
הפונקציה מחזירה את הטווח שנבחר בגיליון הפעיל, או 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
get Active Range List()
מחזירה את רשימת הטווחים הפעילים בגיליון הפעיל או null אם לא נבחרו טווחים. הטווח הפעיל שמכיל את התא המודגש הנוכחי מופיע אחרון ברשימה.
אם נבחר טווח יחיד, הפעולה תהיה כמו get.
// Returns the list of active ranges. const rangeList = SpreadsheetApp.getActiveRangeList();
חזרה
Range — רשימת הטווחים הפעילים
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Active Sheet()
מחזירה את הגיליון הפעיל בגיליון אלקטרוני.
הגיליון הפעיל בגיליון אלקטרוני הוא הגיליון שמוצג בממשק המשתמש של הגיליון האלקטרוני.
// 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
get Active Spreadsheet()
מחזירה את הגיליון האלקטרוני שפעיל כרגע, או 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
get Current Cell()
הפונקציה מחזירה את התא הנוכחי (המסומן) שנבחר באחד מהטווחים הפעילים בגיליון הפעיל, או 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
get Selection()
הפונקציה מחזירה את התאריך הנוכחי Selection בגיליון האלקטרוני.
const selection = SpreadsheetApp.getSelection(); const currentCell = selection.getCurrentCell();
חזרה
Selection – הבחירה הנוכחית
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Ui()
הפונקציה מחזירה מופע של סביבת ממשק המשתמש של הגיליון האלקטרוני, שמאפשר לסקריפט להוסיף תכונות כמו תפריטים, תיבות דו-שיח וסרגלי צד. סקריפט יכול לבצע אינטראקציה עם ממשק המשתמש רק עבור המופע הנוכחי של גיליון אלקטרוני פתוח, ורק אם הסקריפט מקשר לגיליון האלקטרוני. מידע נוסף זמין במדריכים בנושא תפריטים ותיבות דו-שיח וסרגלי צד.
// 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 – מופע של סביבת ממשק המשתמש של הגיליון האלקטרוני הזה
new Cell Image()
יוצרת Builder ל-Cell.
// 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);
חזרה
Cell – הכלי החדש ליצירת קהלים.
new Color()
יוצרת Builder ל-Color.
const rgbColor = SpreadsheetApp.newColor().setRgbColor('#FF0000').build();
חזרה
Color – הכלי החדש ליצירת קהלים.
new Conditional Format Rule()
יוצר 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);
חזרה
Conditional – הכלי החדש ליצירת קהלים.
new Data Source Spec()
יוצרת Builder ל-Data.
// 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);
חזרה
Data – הכלי החדש ליצירת קהלים.
new Data Validation()
יוצרת כלי ליצירת כלל לאימות נתונים.
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);
חזרה
Data – הכלי החדש ליצירת קהלים.
new Filter Criteria()
יוצרת Builder ל-Filter.
// 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);
חזרה
Filter — הכלי החדש ליצירת אתרים
new Rich Text Value()
יוצרת כלי ליצירת ערך של טקסט עשיר.
// 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);
חזרה
Rich – הכלי החדש ליצירת קהלים.
new Text Style()
יוצרת כלי ליצירת סגנון טקסט.
// 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);
חזרה
Text – הכלי החדש ליצירת קהלים.
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()); }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
file | File | הקובץ שרוצים לפתוח. |
חזרה
Spreadsheet — הגיליון האלקטרוני
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets
open By Id(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());
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
id | String | המזהה הייחודי של הגיליון האלקטרוני. |
חזרה
Spreadsheet — אובייקט הגיליון האלקטרוני עם המזהה הנתון
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets
open By Url(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());
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
url | String | כתובת ה-URL של הגיליון האלקטרוני. |
חזרה
Spreadsheet — אובייקט הגיליון האלקטרוני עם כתובת ה-URL שצוינה.
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets
set Active Range(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();
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
range | Range | הטווח שרוצים להגדיר כטווח הפעיל. |
חזרה
Range – הטווח הפעיל החדש
set Active Range List(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();
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
range | Range | רשימת הטווחים לבחירה. |
חזרה
Range – רשימת הטווחים החדשה שנבחרה
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Active Sheet(sheet)
הפונקציה מגדירה את הגיליון הפעיל בגיליון אלקטרוני. ממשק המשתמש של Google Sheets מציג את הגיליון שנבחר, אלא אם הגיליון שייך לגיליון אלקטרוני אחר.
// The code below makes the 2nd sheet active in the active spreadsheet. const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[1]);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
sheet | Sheet | הגיליון הפעיל החדש. |
חזרה
Sheet – הגיליון שהוגדר כגיליון הפעיל החדש
set Active Sheet(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());
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
sheet | Sheet | הגיליון הפעיל החדש. |
restore | Boolean | אם true, הבחירה האחרונה בגיליון הפעיל החדש נבחרת שוב כשהגיליון החדש הופך לפעיל. אם false, הגיליון החדש הופך לפעיל בלי לשנות את הבחירה הנוכחית. |
חזרה
Sheet – הגיליון הפעיל החדש
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Active Spreadsheet(newActiveSpreadsheet)
הגדרת הגיליון האלקטרוני הפעיל.
// The code below makes the spreadsheet with key "1234567890" the active // spreadsheet const ss = SpreadsheetApp.openById('1234567890'); SpreadsheetApp.setActiveSpreadsheet(ss);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
new | Spreadsheet | הגיליון האלקטרוני שרוצים להפוך לגיליון האלקטרוני הפעיל. |
set Current Cell(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();
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
cell | Range | התא שרוצים להגדיר כתא הנוכחי. |
חזרה
Range – התא הנוכחי החדש שהוגדר
אישור
סקריפטים שמשתמשים בשיטה הזו דורשים הרשאה עם אחת או יותר מההיקפים הבאים:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets