Class Range

טווח

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

Methods

שיטהסוג הערך שמוחזרתיאור קצר
activate()Rangeמגדיר את הטווח שצוין כ-active range, כשהתא העליון הימני בטווח הוא current cell.
activateAsCurrentCell()Rangeהגדרת התא שצוין כcurrent cell.
addDeveloperMetadata(key)Rangeמוסיף לטווח מטא-נתונים של מפתח עם המפתח שצוין.
addDeveloperMetadata(key, visibility)Rangeהפונקציה מוסיפה לטווח מטא-נתונים של מפתח עם המפתח והסטטוס שצוינו.
addDeveloperMetadata(key, value)Rangeהפונקציה מוסיפה לטווח מטא-נתונים של מפתח עם המפתח והערך שצוינו.
addDeveloperMetadata(key, value, visibility)Rangeמוסיף לטווח מטא-נתונים של מפתח עם המפתח, הערך והסטטוס שצוינו.
applyColumnBanding()Bandingהחלת עיצוב ברירת מחדל של פסי צבע בעמודות על הטווח.
applyColumnBanding(bandingTheme)Bandingהפונקציה מחילה על הטווח עיצוב של פסי עמודות שצוין.
applyColumnBanding(bandingTheme, showHeader, showFooter)Bandingהפונקציה מחילה על הטווח עיצוב של פסי צבע בעמודות עם הגדרות שצוינו לכותרת ולכותרת התחתונה.
applyRowBanding()Bandingהחלת עיצוב ברירת מחדל של פסי שורות על הטווח.
applyRowBanding(bandingTheme)Bandingהחלת עיצוב של פסי שורות על הטווח.
applyRowBanding(bandingTheme, showHeader, showFooter)Bandingהפונקציה מחילה עיצוב של פסי שורות על הטווח עם הגדרות הכותרת והכותרת התחתונה שצוינו.
autoFill(destination, series)voidהנתונים בטווח הזה ימלאו את destinationRange.
autoFillToNeighbor(series)voidמחשב טווח למילוי בנתונים חדשים על סמך תאים סמוכים וממלא אוטומטית את הטווח הזה בערכים חדשים על סמך הנתונים שכלולים בטווח.
breakApart()Rangeמפצלים שוב את התאים בטווח שמכילים כמה עמודות לתאים נפרדים.
canEdit()Booleanההגדרה קובעת אם למשתמש יש הרשאה לערוך כל תא בטווח.
check()Rangeמשנה את המצב של תיבות הסימון בטווח ל'מסומן'.
clear()Rangeמנקה את הטווח של התוכן והפורמטים.
clear(options)Rangeמנקה את טווח התוכן, הפורמט, כללי אימות הנתונים ו/או התגובות, כפי שמצוין באפשרויות המתקדמות שניתנו.
clearContent()Rangeהתוכן בטווח נמחק, אבל העיצוב נשאר.
clearDataValidations()Rangeמנקה את הכללים לאימות נתונים בטווח.
clearFormat()Rangeהסרת העיצוב מהטווח הזה.
clearNote()Rangeמחיקת ההערה בתא או בתאים שצוינו.
collapseGroups()Rangeכל הקבוצות שנמצאות בטווח יכווצו.
copyFormatToRange(gridId, column, columnEnd, row, rowEnd)voidמעתיקה את העיצוב של הטווח למיקום שצוין.
copyFormatToRange(sheet, column, columnEnd, row, rowEnd)voidמעתיקה את העיצוב של הטווח למיקום שצוין.
copyTo(destination)voidמעתיקה את הנתונים מטווח תאים אחד לטווח תאים אחר.
copyTo(destination, copyPasteType, transposed)voidמעתיקה את הנתונים מטווח תאים אחד לטווח תאים אחר.
copyTo(destination, options)voidמעתיקה את הנתונים מטווח תאים אחד לטווח תאים אחר.
copyValuesToRange(gridId, column, columnEnd, row, rowEnd)voidהעתקת התוכן של הטווח למיקום שצוין.
copyValuesToRange(sheet, column, columnEnd, row, rowEnd)voidהעתקת התוכן של הטווח למיקום שצוין.
createDataSourcePivotTable(dataSource)DataSourcePivotTableיוצר טבלת צירים ריקה של מקור הנתונים, שמעוגנת בתא הראשון בטווח הזה.
createDataSourceTable(dataSource)DataSourceTableיוצר טבלה ריקה של מקור נתונים ממקור הנתונים, שמעוגנת בתא הראשון בטווח הזה.
createDeveloperMetadataFinder()DeveloperMetadataFinderמחזירה DeveloperMetadataFinderApi כדי למצוא מטא-נתונים למפתחים בטווח הזה.
createFilter()Filterיוצרת מסנן ומחילת אותו על הטווח שצוין בגיליון.
createPivotTable(sourceData)PivotTableיוצרת טבלת צירים ריקה מהטווח שצוין sourceData, שמעוגנת לתא הראשון בטווח.
createTextFinder(findText)TextFinderיוצר כלי לחיפוש טקסט בטווח, שיכול למצוא ולהחליף טקסט בטווח הזה.
deleteCells(shiftDimension)voidמחיקת הטווח הזה של תאים.
expandGroups()Rangeהרחבה של הקבוצות המכווצות שהטווח שלהן או המתג שלהן חותך את הטווח הזה.
getA1Notation()Stringמחזירה תיאור מחרוזת של הטווח, בסימון A1.
getBackground()Stringהפונקציה מחזירה את צבע הרקע של התא הימני העליון בטווח (לדוגמה, '#ffffff').
getBackgroundObject()Colorהפונקציה מחזירה את צבע הרקע של התא הימני העליון בטווח.
getBackgroundObjects()Color[][]הפונקציה מחזירה את צבעי הרקע של התאים בטווח.
getBackgrounds()String[][]הפונקציה מחזירה את צבעי הרקע של התאים בטווח (לדוגמה, '#ffffff').
getBandings()Banding[]הפונקציה מחזירה את כל ההדגשות שמוחלות על תאים בטווח.
getCell(row, column)Rangeהפונקציה מחזירה תא נתון בטווח.
getColumn()Integerהפונקציה מחזירה את מיקום העמודה ההתחלתי של הטווח הזה.
getDataRegion()Rangeהפונקציה מחזירה עותק של הטווח שהורחב לארבעת הכיוונים הראשיים Direction כדי לכלול את כל התאים הסמוכים שמכילים נתונים.
getDataRegion(dimension)Rangeמחזירה עותק של הטווח המורחב Direction.UP ו-Direction.DOWN אם המימד שצוין הוא Dimension.ROWS, או Direction.NEXT ו-Direction.PREVIOUS אם המימד הוא Dimension.COLUMNS.
getDataSourceFormula()DataSourceFormulaהפונקציה מחזירה את הערך DataSourceFormula של התא הראשון בטווח, או את הערך null אם התא לא מכיל נוסחה של מקור נתונים.
getDataSourceFormulas()DataSourceFormula[]הפונקציה מחזירה את DataSourceFormulas של התאים בטווח.
getDataSourcePivotTables()DataSourcePivotTable[]מחזירה את כל טבלאות הצירים של מקורות הנתונים שחופפות לטווח.
getDataSourceTables()DataSourceTable[]אחזור כל הטבלאות של מקורות הנתונים שחופפות לטווח.
getDataSourceUrl()Stringהפונקציה מחזירה כתובת URL לנתונים בטווח הזה, שאפשר להשתמש בה כדי ליצור תרשימים ושאילתות.
getDataTable()DataTableהפונקציה מחזירה את הנתונים בתוך האובייקט הזה כ-DataTable.
getDataTable(firstRowIsHeader)DataTableמחזירה את הנתונים בטווח הזה כ-DataTable.
getDataValidation()DataValidationהפונקציה מחזירה את כלל אימות הנתונים של התא הימני העליון בטווח.
getDataValidations()DataValidation[][]הפונקציה מחזירה את כללי אימות הנתונים של כל התאים בטווח.
getDeveloperMetadata()DeveloperMetadata[]מחזירה את המטא-נתונים של המפתח שמשויכים לטווח הזה.
getDisplayValue()Stringהפונקציה מחזירה את הערך המוצג של התא הימני העליון בטווח.
getDisplayValues()String[][]הפונקציה מחזירה את הרשת המלבנית של הערכים בטווח הזה.
getFilter()Filterהפונקציה מחזירה את המסנן בגיליון שאליו שייך הטווח הזה, או null אם אין מסנן בגיליון.
getFontColorObject()Colorהפונקציה מחזירה את צבע הגופן של התא בפינה הימנית העליונה של הטווח.
getFontColorObjects()Color[][]הפונקציה מחזירה את צבעי הגופן של התאים בטווח.
getFontFamilies()String[][]הפונקציה מחזירה את משפחות הגופנים של התאים בטווח.
getFontFamily()Stringהפונקציה מחזירה את משפחת הגופנים של התא בפינה הימנית העליונה של הטווח.
getFontLine()Stringמחזירה את סגנון הקו של התא בפינה הימנית העליונה של הטווח ('underline', ‏'line-through' או 'none').
getFontLines()String[][]מחזירה את סגנון הקו של התאים בטווח ('underline', ‏'line-through' או 'none').
getFontSize()Integerהפונקציה מחזירה את גודל הגופן בנקודות של התא בפינה הימנית העליונה של הטווח.
getFontSizes()Integer[][]הפונקציה מחזירה את גדלי הגופן של התאים בטווח.
getFontStyle()Stringהפונקציה מחזירה את סגנון הגופן ('italic' או 'normal') של התא בפינה הימנית העליונה של הטווח.
getFontStyles()String[][]הפונקציה מחזירה את סגנונות הגופן של התאים בטווח.
getFontWeight()Stringהפונקציה מחזירה את עובי הגופן (רגיל או מודגש) של התא בפינה הימנית העליונה של הטווח.
getFontWeights()String[][]הפונקציה מחזירה את עובי הגופן של התאים בטווח.
getFormula()Stringהפונקציה מחזירה את הנוסחה (בסימון A1) של התא הימני העליון בטווח, או מחרוזת ריקה אם התא ריק או לא מכיל נוסחה.
getFormulaR1C1()Stringהפונקציה מחזירה את הנוסחה (בסימון R1C1) של תא נתון, או null אם אין נוסחה.
getFormulas()String[][]הפונקציה מחזירה את הנוסחאות (בסימון A1) של התאים בטווח.
getFormulasR1C1()String[][]הפונקציה מחזירה את הנוסחאות (בסימון R1C1) של התאים בטווח.
getGridId()Integerהפונקציה מחזירה את מזהה הגיליון הראשי של הטווח.
getHeight()Integerהפונקציה מחזירה את הגובה של הטווח.
getHorizontalAlignment()Stringהפונקציה מחזירה את היישור האופקי של הטקסט (משמאל/מרכז/ימין) בתא בפינה הימנית העליונה של הטווח.
getHorizontalAlignments()String[][]הפונקציה מחזירה את היישור האופקי של התאים בטווח.
getLastColumn()Integerמחזירה את מיקום עמודת הסיום.
getLastRow()Integerמחזירה את מיקום שורת הסיום.
getMergedRanges()Range[]הפונקציה מחזירה מערך של אובייקטים מסוג Range שמייצגים תאים שמוזגו, שנמצאים במלואם בטווח הנוכחי או שמכילים לפחות תא אחד בטווח הנוכחי.
getNextDataCell(direction)Rangeהפונקציה מתחילה בתא בעמודה ובשורה הראשונות של הטווח, ומחזירה את התא הבא בכיוון שצוין, שהוא הקצה של טווח רציף של תאים עם נתונים או התא בקצה של הגיליון האלקטרוני באותו כיוון.
getNote()Stringהפונקציה מחזירה את ההערה שמשויכת לטווח הנתון.
getNotes()String[][]הפונקציה מחזירה את ההערות שמשויכות לתאים בטווח.
getNumColumns()Integerהפונקציה מחזירה את מספר העמודות בטווח הזה.
getNumRows()Integerהפונקציה מחזירה את מספר השורות בטווח הזה.
getNumberFormat()Stringמקבלים את עיצוב המספר או התאריך של התא הימני העליון בטווח הנתון.
getNumberFormats()String[][]הפונקציה מחזירה את הפורמטים של המספרים או התאריכים בתאים בטווח.
getRichTextValue()RichTextValueהפונקציה מחזירה את הערך של הטקסט העשיר בתא הימני העליון בטווח, או null אם הערך בתא הוא לא טקסט.
getRichTextValues()RichTextValue[][]הפונקציה מחזירה את הערכים של הטקסט העשיר בתאים בטווח.
getRow()Integerמחזירה את מיקום השורה של הטווח הזה.
getRowIndex()Integerמחזירה את מיקום השורה של הטווח הזה.
getSheet()Sheetהפונקציה מחזירה את הגיליון שאליו שייך הטווח הזה.
getTextDirection()TextDirectionהפונקציה מחזירה את כיוון הטקסט של התא הימני העליון בטווח.
getTextDirections()TextDirection[][]הפונקציה מחזירה את כיווני הטקסט של התאים בטווח.
getTextRotation()TextRotationהפונקציה מחזירה את הגדרות סיבוב הטקסט של התא הימני העליון בטווח.
getTextRotations()TextRotation[][]הפונקציה מחזירה את הגדרות סיבוב הטקסט בתאים בטווח.
getTextStyle()TextStyleהפונקציה מחזירה את סגנון הטקסט של התא הימני העליון בטווח.
getTextStyles()TextStyle[][]הפונקציה מחזירה את סגנונות הטקסט של התאים בטווח.
getValue()Objectהפונקציה מחזירה את הערך של התא הימני העליון בטווח.
getValues()Object[][]הפונקציה מחזירה את הרשת המלבנית של הערכים בטווח הזה.
getVerticalAlignment()Stringהפונקציה מחזירה את היישור האנכי (למעלה/באמצע/למטה) של התא בפינה הימנית העליונה של הטווח.
getVerticalAlignments()String[][]מחזירה את היישור האנכי של התאים בטווח.
getWidth()Integerהפונקציה מחזירה את רוחב הטווח בעמודות.
getWrap()Booleanהפונקציה מחזירה את הערך true אם הטקסט בתא מוצג בשורות נפרדות, ואת הערך false אם לא.
getWrapStrategies()WrapStrategy[][]הפונקציה מחזירה את אסטרטגיות גלישת הטקסט בתאים בטווח.
getWrapStrategy()WrapStrategyהפונקציה מחזירה את אסטרטגיית גלישת הטקסט של התא הימני העליון בטווח.
getWraps()Boolean[][]הפונקציה מחזירה אם הטקסט בתאים מוצג בגלישה.
insertCells(shiftDimension)Rangeהוספת תאים ריקים לטווח הזה.
insertCheckboxes()Rangeהפונקציה מוסיפה תיבות סימון לכל תא בטווח, עם הערך true אם התיבה מסומנת ועם הערך false אם היא לא מסומנת.
insertCheckboxes(checkedValue)Rangeמוסיפה תיבות סימון לכל תא בטווח, עם ערך מותאם אישית לסימון ומחרוזת ריקה לביטול הסימון.
insertCheckboxes(checkedValue, uncheckedValue)Rangeמוסיף תיבות סימון לכל תא בטווח, עם ערכים מותאמים אישית למצבים המסומנים והלא מסומנים.
isBlank()Booleanהפונקציה מחזירה את הערך true אם הטווח ריק לחלוטין.
isChecked()Booleanהפונקציה מחזירה את הערך TRUE אם כל התאים בטווח מסומנים בתיבת הסימון, ואת הערך FALSE אם לא.
isEndColumnBounded()Booleanקובעת אם סוף הטווח קשור לעמודה מסוימת.
isEndRowBounded()Booleanקובעת אם סוף הטווח קשור לשורה מסוימת.
isPartOfMerge()Booleanהפונקציה מחזירה true אם התאים בטווח הנוכחי חופפים לתאים ממוזגים.
isStartColumnBounded()Booleanקובעת אם תחילת הטווח קשורה לעמודה מסוימת.
isStartRowBounded()Booleanקובעת אם תחילת הטווח קשורה לשורה מסוימת.
merge()Rangeממזגת את התאים בטווח לבלוק אחד.
mergeAcross()Rangeממזגים את התאים בטווח לאורך העמודות של הטווח.
mergeVertically()Rangeממזגת את התאים בטווח.
moveTo(target)voidגוזרים ומדביקים (גם את הפורמט וגם את הערכים) מהטווח הזה לטווח היעד.
offset(rowOffset, columnOffset)Rangeמחזירה טווח חדש שמוסט מהטווח הזה במספר נתון של שורות ועמודות (יכול להיות שלילי).
offset(rowOffset, columnOffset, numRows)Rangeהפונקציה מחזירה טווח חדש ביחס לטווח הנוכחי, שנקודת הפינה הימנית העליונה שלו מוסטת מהטווח הנוכחי במספר השורות והעמודות שצוין, ועם הגובה שצוין בתאים.
offset(rowOffset, columnOffset, numRows, numColumns)Rangeמחזירה טווח חדש ביחס לטווח הנוכחי, שנקודת הפינה הימנית העליונה שלו מוסטת מהטווח הנוכחי במספר השורות והעמודות שצוין, ועם הגובה והרוחב שצוינו בתאים.
protect()Protectionיוצר אובייקט שיכול להגן על הטווח מפני עריכה, למעט משתמשים שיש להם הרשאה.
randomize()Rangeהפונקציה משנה את הסדר של השורות בטווח הנתון באופן אקראי.
removeCheckboxes()Rangeמסיר את כל תיבות הסימון מהטווח.
removeDuplicates()Rangeמסירה שורות בטווח הזה שמכילות ערכים שהם כפולים של ערכים בשורה קודמת כלשהי.
removeDuplicates(columnsToCompare)Rangeהפונקציה מסירה שורות בטווח הזה שמכילות ערכים בעמודות שצוינו שהם כפולים של ערכים בשורה קודמת כלשהי.
setBackground(color)Rangeמגדיר את צבע הרקע של כל התאים בטווח בסימון CSS (לדוגמה, '#ffffff' או 'white').
setBackgroundObject(color)Rangeמגדיר את צבע הרקע של כל התאים בטווח.
setBackgroundObjects(color)Rangeהגדרת רשת מלבנית של צבעי רקע (המידות צריכות להיות זהות למידות של הטווח הזה).
setBackgroundRGB(red, green, blue)Rangeהגדרת הרקע לצבע שצוין באמצעות ערכי RGB (מספרים שלמים בין 0 ל-255, כולל).
setBackgrounds(color)Rangeהגדרת רשת מלבנית של צבעי רקע (המידות צריכות להיות זהות למידות של הטווח הזה).
setBorder(top, left, bottom, right, vertical, horizontal)Rangeהגדרת מאפיין הגבול.
setBorder(top, left, bottom, right, vertical, horizontal, color, style)Rangeמגדיר את מאפיין הגבול עם צבע ו/או סגנון.
setDataValidation(rule)Rangeמגדירה כלל אחד לאימות נתונים לכל התאים בטווח.
setDataValidations(rules)Rangeמגדירה את כללי אימות הנתונים לכל התאים בטווח.
setFontColor(color)Rangeהגדרת צבע הגופן בסימון CSS (למשל '#ffffff' או 'white').
setFontColorObject(color)Rangeהגדרת צבע הגופן של הטווח הנתון.
setFontColorObjects(colors)Rangeמגדיר רשת מלבנית של צבעי גופן (חייב להתאים לממדים של הטווח הזה).
setFontColors(colors)Rangeמגדיר רשת מלבנית של צבעי גופן (חייב להתאים לממדים של הטווח הזה).
setFontFamilies(fontFamilies)Rangeמגדיר רשת מלבנית של משפחות גופנים (צריך להתאים לממדים של הטווח הזה).
setFontFamily(fontFamily)Rangeמגדיר את משפחת הגופנים, כמו Arial או Helvetica.
setFontLine(fontLine)Rangeמגדיר את סגנון הקו של הגופן בטווח הנתון ('underline', 'line-through' או 'none').
setFontLines(fontLines)Rangeמגדיר רשת מלבנית של סגנונות קו (חייב להתאים לממדים של הטווח הזה).
setFontSize(size)Rangeהגדרת גודל הגופן, כאשר הגודל הוא גודל הנקודה לשימוש.
setFontSizes(sizes)Rangeמגדיר רשת מלבנית של גדלי גופן (חייב להתאים לממדים של הטווח הזה).
setFontStyle(fontStyle)Rangeהגדרת סגנון הגופן לטווח הנתון ('italic' או 'normal').
setFontStyles(fontStyles)Rangeמגדיר רשת מלבנית של סגנונות גופן (חייב להתאים לממדים של הטווח הזה).
setFontWeight(fontWeight)Rangeהגדרת עובי הגופן לטווח הנתון (רגיל/מודגש).
setFontWeights(fontWeights)Rangeמגדיר רשת מלבנית של משקלי גופן (חייב להתאים לממדים של הטווח הזה).
setFormula(formula)Rangeמעדכן את הנוסחה של הטווח הזה.
setFormulaR1C1(formula)Rangeמעדכן את הנוסחה של הטווח הזה.
setFormulas(formulas)Rangeמגדיר רשת מלבנית של נוסחאות (חייב להתאים לממדים של הטווח הזה).
setFormulasR1C1(formulas)Rangeמגדיר רשת מלבנית של נוסחאות (חייב להתאים לממדים של הטווח הזה).
setHorizontalAlignment(alignment)Rangeהגדרת היישור האופקי (משמאל לימין) לטווח הנתון (שמאל/מרכז/ימין).
setHorizontalAlignments(alignments)Rangeמגדירה רשת מלבנית של יישורים אופקיים.
setNote(note)Rangeמגדיר את ההערה לערך שצוין.
setNotes(notes)Rangeמגדיר רשת מלבנית של הערות (חייב להתאים לממדים של הטווח הזה).
setNumberFormat(numberFormat)Rangeמגדירה את הפורמט של המספר או התאריך למחרוזת הפורמט שצוינה.
setNumberFormats(numberFormats)Rangeמגדירה רשת מלבנית של פורמטים של מספרים או תאריכים (חייבים להתאים לממדים של הטווח הזה).
setRichTextValue(value)Rangeמגדירה את הערך של הטקסט העשיר לתאים בטווח.
setRichTextValues(values)Rangeמגדירה רשת מלבנית של ערכי טקסט עשיר.
setShowHyperlink(showHyperlink)Rangeהגדרה שקובעת אם להציג היפר-קישורים בטווח או לא.
setTextDirection(direction)Rangeהגדרת כיוון הטקסט בתאים בטווח.
setTextDirections(directions)Rangeמגדירה רשת מלבנית של כיווני טקסט.
setTextRotation(degrees)Rangeהגדרת ההגדרות של סיבוב הטקסט בתאים בטווח.
setTextRotation(rotation)Rangeהגדרת ההגדרות של סיבוב הטקסט בתאים בטווח.
setTextRotations(rotations)Rangeהגדרת רשת מלבנית של סיבובי טקסט.
setTextStyle(style)Rangeהגדרת סגנון הטקסט של התאים בטווח.
setTextStyles(styles)Rangeמגדירה רשת מלבנית של סגנונות טקסט.
setValue(value)Rangeהגדרת הערך של הטווח.
setValues(values)Rangeמגדיר רשת מלבנית של ערכים (חייב להתאים לממדים של הטווח הזה).
setVerticalAlignment(alignment)Rangeהגדרת היישור האנכי (מלמעלה למטה) לטווח הנתון (למעלה/באמצע/למטה).
setVerticalAlignments(alignments)Rangeהגדרת רשת מלבנית של יישור אנכי (חייבת להתאים למידות של הטווח הזה).
setVerticalText(isVertical)Rangeהגדרה של האפשרות להציג את הטקסט בתאים בטווח אחד מעל השני.
setWrap(isWrapEnabled)Rangeמגדירים את גלישת הטקסט בתאים בטווח הנתון.
setWrapStrategies(strategies)Rangeמגדירה רשת מלבנית של שיטות גלישת טקסט.
setWrapStrategy(strategy)Rangeהגדרת אסטרטגיית גלישת הטקסט בתאים בטווח.
setWraps(isWrapEnabled)Rangeמגדיר רשת מלבנית של מדיניות גלישת מילים (חייבת להתאים לממדים של הטווח הזה).
shiftColumnGroupDepth(delta)Rangeהפונקציה משנה את עומק הקיבוץ של העמודות בטווח בסכום שצוין.
shiftRowGroupDepth(delta)Rangeהפונקציה משנה את העומק של קיבוץ השורות בטווח בסכום שצוין.
sort(sortSpecObj)Rangeממיינת את התאים בטווח הנתון לפי העמודה והסדר שצוינו.
splitTextToColumns()voidמפצלת עמודת טקסט לכמה עמודות על סמך מפריד שזוהה אוטומטית.
splitTextToColumns(delimiter)voidמפצלת עמודת טקסט לכמה עמודות באמצעות המחרוזת שצוינה כמפריד בהתאמה אישית.
splitTextToColumns(delimiter)voidמפצלת עמודת טקסט לכמה עמודות על סמך התו המפריד שצוין.
trimWhitespace()Rangeמסירה את הרווחים הלבנים (כמו רווחים, טאבים או שורות חדשות) בכל תא בטווח הזה.
uncheck()Rangeמשנה את המצב של תיבות הסימון בטווח ל'לא מסומן'.

תיעוד מפורט

activate()

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

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getRange('A1:D10');
range.activate();

const selection = sheet.getSelection();
// Current cell: A1
const currentCell = selection.getCurrentCell();
// Active Range: A1:D10
const activeRange = selection.getActiveRange();

חזרה

Range — הטווח הזה, לשרשור.


activateAsCurrentCell()

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

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

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

הערה: הערך של Range חייב להיות תא אחד, אחרת תופעל חריגה.

// Gets the first sheet of the spreadsheet.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];

// Gets the cell B5 and sets it as the active cell.
const range = sheet.getRange('B5');
const currentCell = range.activateAsCurrentCell();

// Logs the activated cell.
console.log(currentCell.getA1Notation());

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

addDeveloperMetadata(key)

מוסיף לטווח מטא-נתונים של מפתח עם המפתח שצוין.

// 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 row 2 on the sheet.
const range = sheet.getRange('2:2');

// Adds the key 'NAME' to the developer metadata for row 2.
range.addDeveloperMetadata('NAME');

// Gets the metadata and logs it to the console.
const developerMetaData = range.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());

פרמטרים

שםסוגתיאור
keyStringהמפתח של מטא הנתונים החדשים של המפתח.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

addDeveloperMetadata(key, visibility)

הפונקציה מוסיפה לטווח מטא-נתונים של מפתח עם המפתח והסטטוס שצוינו.

// 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 row 2 on Sheet1.
const range = sheet.getRange('2:2');

// Adds the key 'NAME' and sets the developer metadata visibility to 'DOCUMENT'
// for row 2 on Sheet1.
range.addDeveloperMetadata(
    'NAME',
    SpreadsheetApp.DeveloperMetadataVisibility.DOCUMENT,
);

// Gets the updated metadata info and logs it to the console.
const developerMetaData = range.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());
console.log(developerMetaData.getVisibility().toString());

פרמטרים

שםסוגתיאור
keyStringהמפתח של מטא הנתונים החדשים של המפתח.
visibilityDeveloperMetadataVisibilityסטטוס השיתוף של המטא נתונים החדשים של המפתח.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

addDeveloperMetadata(key, value)

הפונקציה מוסיפה לטווח מטא-נתונים של מפתח עם המפתח והערך שצוינו.

// 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 row 2 of Sheet1.
const range = sheet.getRange('2:2');

// Adds the key 'NAME' and sets the value to 'GOOGLE' for the metadata of row 2.
range.addDeveloperMetadata('NAME', 'GOOGLE');

// Gets the metadata and logs it to the console.
const developerMetaData = range.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());
console.log(developerMetaData.getValue());

פרמטרים

שםסוגתיאור
keyStringהמפתח של מטא הנתונים החדשים של המפתח.
valueStringהערך של מטא הנתונים החדשים של המפתח.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

addDeveloperMetadata(key, value, visibility)

מוסיף לטווח מטא-נתונים של מפתח עם המפתח, הערך והסטטוס שצוינו.

// 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 row 2 on the sheet.
const range = sheet.getRange('2:2');

// Adds the key 'NAME', sets the value to 'GOOGLE', and sets the visibility
// to PROJECT for row 2 on the sheet.
range.addDeveloperMetadata(
    'NAME',
    'GOOGLE',
    SpreadsheetApp.DeveloperMetadataVisibility.PROJECT,
);

// Gets the updated metadata info and logs it to the console.
const developerMetaData = range.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());
console.log(developerMetaData.getValue());
console.log(developerMetaData.getVisibility().toString());

פרמטרים

שםסוגתיאור
keyStringהמפתח של מטא הנתונים החדשים של המפתח.
valueStringהערך של מטא הנתונים החדשים של המפתח.
visibilityDeveloperMetadataVisibilityסטטוס השיתוף של המטא נתונים החדשים של המפתח.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

applyColumnBanding()

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

// 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 row 2 on the sheet.
const range = sheet.getRange('2:2');

// Applies column banding to row 2.
const colBanding = range.applyColumnBanding();

// Gets the first banding on the sheet and logs the color of the header column.
console.log(
    sheet.getBandings()[0]
        .getHeaderColumnColorObject()
        .asRgbColor()
        .asHexString(),
);

// Gets the first banding on the sheet and logs the color of the second column.
console.log(
    sheet.getBandings()[0]
        .getSecondColumnColorObject()
        .asRgbColor()
        .asHexString(),
);

חזרה

Banding — הסיווג החדש.

אישור

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

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

applyColumnBanding(bandingTheme)

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

// 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 row 2 on the sheet.
const range = sheet.getRange('2:2');

// Applies the INDIGO color banding theme to the columns in row 2.
const colBanding = range.applyColumnBanding(SpreadsheetApp.BandingTheme.INDIGO);

// Gets the first banding on the sheet and logs the color of the second column.
console.log(
    sheet.getBandings()[0]
        .getSecondColumnColorObject()
        .asRgbColor()
        .asHexString(),
);

פרמטרים

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

חזרה

Banding — הסיווג החדש.

אישור

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

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

applyColumnBanding(bandingTheme, showHeader, showFooter)

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

// 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 rows 12-22 on the sheet.
const range = sheet.getRange('12:22');

// Applies the BLUE color banding theme to rows 12-22.
// Sets the header visibility to false and the footer visibility to true.
const colBanding = range.applyColumnBanding(
    SpreadsheetApp.BandingTheme.BLUE,
    false,
    true,
);

// Gets the banding color and logs it to the console.
console.log(
    sheet.getBandings()[0]
        .getSecondColumnColorObject()
        .asRgbColor()
        .asHexString(),
);

// Gets the header color object and logs it to the console. Returns null because
// the header visibility is set to false.
console.log(sheet.getBandings()[0].getHeaderColumnColorObject());

// Gets the footer color and logs it to the console.
console.log(
    sheet.getBandings()[0]
        .getFooterColumnColorObject()
        .asRgbColor()
        .asHexString(),
);

פרמטרים

שםסוגתיאור
bandingThemeBandingThemeערכת צבעים להחלה על העמודות בטווח.
showHeaderBooleanאם הערך הוא true, צבע הכותרת של העיצוב עם הפסים יוחל על העמודה הראשונה.
showFooterBooleanאם הערך הוא true, צבע הכותרת התחתונה של העיצוב עם הפסים יוחל על העמודה האחרונה.

חזרה

Banding — הסיווג החדש.

אישור

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

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

applyRowBanding()

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

// Opens the spreadsheet by its URL. If you created your script from within a
// Google Sheets spreadsheet, 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 rows 1-30 on Sheet1.
const range = sheet.getRange('1:30');

// Applies row banding to rows 1-30.
range.applyRowBanding();

// Gets the hex color of the second banded row.
const secondRowColor =
    range.getBandings()[0].getSecondRowColorObject().asRgbColor().asHexString();

// Logs the hex color to console.
console.log(secondRowColor);

חזרה

Banding — העיצוב.

אישור

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

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

applyRowBanding(bandingTheme)

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

// Opens the spreadsheet by its URL. If you created your script from within a
// Google Sheets spreadsheet, 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 rows 1-30 on Sheet1.
const range = sheet.getRange('1:30');

// Applies the INDIGO row banding theme to rows 1-30.
range.applyRowBanding(SpreadsheetApp.BandingTheme.INDIGO);

// Gets the hex color of the second banded row.
const secondRowColor =
    range.getBandings()[0].getSecondRowColorObject().asRgbColor().asHexString();

// Logs the hex color to console.
console.log(secondRowColor);

פרמטרים

שםסוגתיאור
bandingThemeBandingThemeערכת צבעים להחלה על השורות בטווח.

חזרה

Banding — הסיווג החדש.

אישור

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

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

applyRowBanding(bandingTheme, showHeader, showFooter)

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

// Opens the spreadsheet by its URL. If you created your script from within a
// Google Sheets spreadsheet, 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 rows 1-30 on Sheet1.
const range = sheet.getRange('1:30');

// Applies the INDIGO row banding to rows 1-30 and
// specifies to hide the header and show the footer.
range.applyRowBanding(SpreadsheetApp.BandingTheme.INDIGO, false, true);

פרמטרים

שםסוגתיאור
bandingThemeBandingThemeערכת צבעים להחלה על השורות בטווח.
showHeaderBooleanאם true, צבע הכותרת של העיצוב עם הפסים מוחל על השורה הראשונה.
showFooterBooleanאם הערך הוא true, צבע הכותרת התחתונה של העיצוב עם הפסים יוחל על השורה האחרונה.

חזרה

Banding — הסיווג החדש.

אישור

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

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

autoFill(destination, series)

הנתונים בטווח הזה ימלאו את destinationRange. הערכים החדשים נקבעים גם לפי סוג המידע series שצוין. טווח היעד חייב להכיל את הטווח הזה ולהאריך אותו בכיוון אחד בלבד. לדוגמה, הפונקציה הבאה ממלאת את A1:A20 בסדרה של מספרים עולים על סמך הערכים הנוכחיים ב-A1:A4:

const sheet = SpreadsheetApp.getActiveSheet();

// Has values [1, 2, 3, 4].
const sourceRange = sheet.getRange('A1:A4');
// The range to fill with values.
const destination = sheet.getRange('A1:A20');

// Inserts new values in A5:A20, continuing the pattern expressed in A1:A4
sourceRange.autoFill(destination, SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);

פרמטרים

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

אישור

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

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

autoFillToNeighbor(series)

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

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

לדוגמה, אם A1:A20 מלא בסדרה של מספרים עולים והשיטה הזו נקראת בטווח B1:B4 שמכיל סדרה של תאריכים, ערכים חדשים מוכנסים רק ל-B5:B20. כך הערכים החדשים האלה 'נדבקים' לתאים שמכילים ערכים בעמודה א'.

const sheet = SpreadsheetApp.getActiveSheet();

// A1:A20 has values [1, 2, 3, ... 20].
// B1:B4 has values [1/1/2017, 1/2/2017, ...]
const sourceRange = sheet.getRange('B1:B4');

// Results in B5:B20 having values [1/5/2017, ... 1/20/2017]
sourceRange.autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);

פרמטרים

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

אישור

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

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

breakApart()

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

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

// Opens the spreadsheet by its URL. If you created your script from within a
// Google Sheets spreadsheet, 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 the range A1:C6 on Sheet1.
const range = sheet.getRange('A1:C6');

// Unmerges the range A1:C6 into individual cells.
range.breakApart();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

canEdit()

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

// Opens the spreadsheet by its URL. If you created your script from within a
// Google Sheets spreadsheet, 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 the range A1:C6 on Sheet1.
const range = sheet.getRange('A1:C6');

// Logs whether the user has permission to edit every cell in the range.
console.log(range.canEdit());

חזרה

Booleantrue אם למשתמש יש הרשאה לערוך כל תא בטווח; false אחרת.

אישור

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

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

check()

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

// Changes the state of cells which currently contain either the checked or
// unchecked value configured in the range A1:B10 to 'checked'.
const range = SpreadsheetApp.getActive().getRange('A1:B10');
range.check();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

clear()

מנקה את הטווח של התוכן והפורמטים.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('A1:D10');
range.clear();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

clear(options)

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

// The code below clears range C2:G7 in the active sheet, but preserves the
// format, data validation rules, and comments.
SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 5).clear({
  contentsOnly: true
});

פרמטרים

שםסוגתיאור
optionsObjectאובייקט JavaScript שמציין פרמטרים מתקדמים, כמו אלה שמופיעים בהמשך.

פרמטרים מתקדמים

שםסוגתיאור
commentsOnlyBooleanהאם לנקות רק את התגובות.
contentsOnlyBooleanהאם לנקות רק את התוכן.
formatOnlyBooleanהאם לנקות רק את הפורמט. שימו לב: ניקוי הפורמט מנקה גם את כללי אימות הנתונים.
validationsOnlyBooleanהאם להסיר רק כללים לאימות נתונים.
skipFilteredRowsBooleanהאם להימנע מהסרת שורות מסוננות.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

clearContent()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('A1:D10');
range.clearContent();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

clearDataValidations()

מנקה את הכללים לאימות נתונים בטווח.

// Clear the data validation rules for cells A1:B5.
const range = SpreadsheetApp.getActive().getRange('A1:B5');
range.clearDataValidations();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

clearFormat()

הסרת העיצוב מהטווח הזה.

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('A1:D10');
range.clearFormat();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

clearNote()

מחיקת ההערה בתא או בתאים שצוינו.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('A1:D10');
range.clearNote();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

collapseGroups()

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

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();

// All row and column groups within the range are collapsed.
range.collapseGroups();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

copyFormatToRange(gridId, column, columnEnd, row, rowEnd)

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

תיאור מפורט של הפרמטר gridId זמין getGridId().

const ss = SpreadsheetApp.getActiveSpreadsheet();
const source = ss.getSheets()[0];

const range = source.getRange('B2:D4');

// This copies the formatting in B2:D4 in the source sheet to
// D4:F6 in the sheet with gridId 1555299895. Note that you can get the gridId
// of a sheet by calling sheet.getSheetId() or range.getGridId().
range.copyFormatToRange(1555299895, 4, 6, 4, 6);

פרמטרים

שםסוגתיאור
gridIdIntegerהמזהה הייחודי של הגיליון בגיליון האלקטרוני, ללא קשר למיקום.
columnIntegerהעמודה הראשונה בטווח היעד.
columnEndIntegerהעמודה האחרונה בטווח היעד.
rowIntegerהשורה הראשונה בטווח היעד.
rowEndIntegerהשורה האחרונה בטווח היעד.

אישור

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

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

ראה גם


copyFormatToRange(sheet, column, columnEnd, row, rowEnd)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const source = ss.getSheets()[0];
const destination = ss.getSheets()[1];

const range = source.getRange('B2:D4');

// This copies the formatting in B2:D4 in the source sheet to
// D4:F6 in the second sheet
range.copyFormatToRange(destination, 4, 6, 4, 6);

פרמטרים

שםסוגתיאור
sheetSheetגיליון היעד.
columnIntegerהעמודה הראשונה בטווח היעד.
columnEndIntegerהעמודה האחרונה בטווח היעד.
rowIntegerהשורה הראשונה בטווח היעד.
rowEndIntegerהשורה האחרונה בטווח היעד.

אישור

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

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

copyTo(destination)

מעתיקה את הנתונים מטווח תאים אחד לטווח תאים אחר. הערכים והפורמט מועתקים.

// The code below copies the first 5 columns over to the 6th column.
const sheet = SpreadsheetApp.getActiveSheet();
const rangeToCopy = sheet.getRange(1, 1, sheet.getMaxRows(), 5);
rangeToCopy.copyTo(sheet.getRange(1, 6));

פרמטרים

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

אישור

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

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

copyTo(destination, copyPasteType, transposed)

מעתיקה את הנתונים מטווח תאים אחד לטווח תאים אחר.

// The code below copies only the values of the first 5 columns over to the 6th
// column.
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange('A:E').copyTo(
    sheet.getRange('F1'),
    SpreadsheetApp.CopyPasteType.PASTE_VALUES,
    false,
);

פרמטרים

שםסוגתיאור
destinationRangeטווח היעד להעתקה. רק המיקום של התא העליון השמאלי רלוונטי.
copyPasteTypeCopyPasteTypeסוג שמציין איך התוכן של הטווח מודבק ביעד.
transposedBooleanהארגומנט שקובע אם להדביק את הטווח בכיוון המועבר שלו.

אישור

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

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

copyTo(destination, options)

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

// The code below copies only the values of the first 5 columns over to the 6th
// column.
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange('A:E').copyTo(sheet.getRange('F1'), {contentsOnly: true});

פרמטרים

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

פרמטרים מתקדמים

שםסוגתיאור
formatOnlyBooleanמציין שצריך להעתיק רק את הפורמט
contentsOnlyBooleanמציין שצריך להעתיק רק את התוכן

אישור

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

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

copyValuesToRange(gridId, column, columnEnd, row, rowEnd)

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

תיאור מפורט של הפרמטר gridId זמין getGridId().

const ss = SpreadsheetApp.getActiveSpreadsheet();
const source = ss.getSheets()[0];

const range = source.getRange('B2:D4');

// This copies the data in B2:D4 in the source sheet to
// D4:F6 in the sheet with gridId 0
range.copyValuesToRange(0, 4, 6, 4, 6);

פרמטרים

שםסוגתיאור
gridIdIntegerהמזהה הייחודי של הגיליון בגיליון האלקטרוני, ללא קשר למיקום.
columnIntegerהעמודה הראשונה בטווח היעד.
columnEndIntegerהעמודה האחרונה בטווח היעד.
rowIntegerהשורה הראשונה בטווח היעד.
rowEndIntegerהשורה האחרונה בטווח היעד.

אישור

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

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

ראה גם


copyValuesToRange(sheet, column, columnEnd, row, rowEnd)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const source = ss.getSheets()[0];
const destination = ss.getSheets()[1];

const range = source.getRange('B2:D4');

// This copies the data in B2:D4 in the source sheet to
// D4:F6 in the second sheet
range.copyValuesToRange(destination, 4, 6, 4, 6);

פרמטרים

שםסוגתיאור
sheetSheetגיליון היעד.
columnIntegerהעמודה הראשונה בטווח היעד.
columnEndIntegerהעמודה האחרונה בטווח היעד.
rowIntegerהשורה הראשונה בטווח היעד.
rowEndIntegerהשורה האחרונה בטווח היעד.

אישור

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

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

createDataSourcePivotTable(dataSource)

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

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

const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const anchorCell = spreadsheet.getSheets()[0].getRange('A1');
const dataSource = spreadsheet.getDataSources()[0];

const pivotTable = anchorCell.createDataSourcePivotTable(dataSource);
pivotTable.addRowGroup('dataColumnA');
pivotTable.addColumnGroup('dataColumnB');
pivotTable.addPivotValue(
    'dataColumnC',
    SpreadsheetApp.PivotTableSummarizeFunction.SUM,
);
pivotTable.addFilter(
    'dataColumnA',
    SpreadsheetApp.newFilterCriteria().whenTextStartsWith('A').build(),
);

פרמטרים

שםסוגתיאור
dataSourceDataSourceמקור הנתונים שממנו רוצים ליצור את טבלת הצירים.

חזרה

DataSourcePivotTable — טבלת הצירים של מקור הנתונים שנוצרה.

אישור

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

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

createDataSourceTable(dataSource)

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

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

const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const anchorCell = spreadsheet.getSheets()[0].getRange('A1');
const dataSource = spreadsheet.getDataSources()[0];

const dataSourceTable =
    anchorCell.createDataSourceTable(dataSource)
        .addColumns('dataColumnA', 'dataColumnB', 'dataColumnC')
        .addSortSpec('dataColumnA', true)    // ascending=true
        .addSortSpec('dataColumnB', false);  // ascending=false

פרמטרים

שםסוגתיאור
dataSourceDataSourceמקור הנתונים שממנו רוצים ליצור את טבלת הצירים.

חזרה

DataSourceTable — הטבלה של מקור הנתונים שנוצרה.

אישור

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

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

createDeveloperMetadataFinder()

מחזירה DeveloperMetadataFinderApi כדי למצוא מטא-נתונים למפתחים בטווח הזה. מטא-נתונים נמצאים בטווח רק אם הם כלולים בו באופן מלא. לדוגמה, מטא-נתונים שמשויכים לשורה '3:3' לא נכללים בהיקף של הטווח 'A1:D5', אבל כן נכללים בהיקף של הטווח '1:5'.

// 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 the range A1:C6.
const range = sheet.getRange('A1:C6');

// Creates a developer metadata finder to search for metadata in the scope of
// this range.
const developerMetaDataFinder = range.createDeveloperMetadataFinder();

// Logs information about the developer metadata finder to the console.
const developerMetaData = developerMetaDataFinder.find()[0];
console.log(developerMetaData.getKey());
console.log(developerMetaData.getValue());
console.log(developerMetaData.getVisibility().toString());

חזרה

DeveloperMetadataFinder – מאתר מטא נתונים למפתחים לחיפוש מטא נתונים בטווח הזה.


createFilter()

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

const ss = SpreadsheetApp.getActiveSheet();
const range = ss.getRange('A1:C20');

// Creates a new filter and applies it to the range A1:C20 on the active sheet.
function createFilter() {
  range.createFilter();
}
// Gets the filter and applies criteria that only shows cells that aren't empty.
function getFilterAddCriteria() {
  const filter = range.getFilter();
  const criteria =
      SpreadsheetApp.newFilterCriteria().whenCellNotEmpty().build();
  filter.setColumnFilterCriteria(2, criteria);
}
משתמשים בשיטה הזו כדי ליצור מסננים לגיליונות Grid, סוג הגיליון שמוגדר כברירת מחדל. גיליונות רשת הם גיליונות שלא מקושרים למסד נתונים. כדי ליצור סוגים אחרים של מסננים, אפשר לעיין במאמרים הבאים:

חזרה

Filter — המסנן החדש.

אישור

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

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

createPivotTable(sourceData)

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

// 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 as a range in order to place the pivot table.
const range = sheet.getRange('A1');

// Gets the range of the source data for the pivot table.
const dataRange = sheet.getRange('E12:G20');

// Creates an empty pivot table from the specified source data.
const pivotTable = range.createPivotTable(dataRange);

// Logs the values from the pivot table's source data to the console.
console.log(pivotTable.getSourceDataRange().getValues());

פרמטרים

שםסוגתיאור
sourceDataRangeהנתונים שמהם רוצים ליצור את טבלת הצירים.

חזרה

PivotTablePivotTable שנוצר לאחרונה.

אישור

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

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

createTextFinder(findText)

יוצר כלי לחיפוש טקסט בטווח, שיכול למצוא ולהחליף טקסט בטווח הזה.

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();

// Creates  a text finder for the range.
const textFinder = range.createTextFinder('dog');

// Returns the first occurrence of 'dog'.
const firstOccurrence = textFinder.findNext();

// Replaces the last found occurrence of 'dog' with 'cat' and returns the number
// of occurrences replaced.
const numOccurrencesReplaced = textFinder.replaceWith('cat');

פרמטרים

שםסוגתיאור
findTextStringהטקסט שרוצים לחפש.

חזרה

TextFinder — הTextFinder לטווח


deleteCells(shiftDimension)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('A1:D10');
range.deleteCells(SpreadsheetApp.Dimension.COLUMNS);

פרמטרים

שםסוגתיאור
shiftDimensionDimensionהמאפיין שלפיו יזוזו הנתונים הקיימים.

אישור

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

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

expandGroups()

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

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();

// All row and column groups within the range are expanded.
range.expandGroups();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

getA1Notation()

מחזירה תיאור מחרוזת של הטווח, בסימון A1.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange(1, 1, 2, 5);

// Logs "A1:E2"
Logger.log(range.getA1Notation());

חזרה

String – תיאור המחרוזת של הטווח בסימון A1.

אישור

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

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

getBackground()

הפונקציה מחזירה את צבע הרקע של התא הימני העליון בטווח (לדוגמה, '#ffffff').

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B5');
Logger.log(cell.getBackground());

חזרה

String — קוד הצבע של הרקע.

אישור

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

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

getBackgroundObject()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B5');
Logger.log(cell.getBackgroundObject().asRgbColor().asHexString());

חזרה

Color – צבע הרקע של התא הימני העליון בטווח.

אישור

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

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

getBackgroundObjects()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B5:C6');
const bgColors = range.getBackgroundObjects();
for (const i in bgColors) {
  for (const j in bgColors[i]) {
    Logger.log(bgColors[i][j].asRgbColor().asHexString());
  }
}

חזרה

Color[][] — מערך דו-ממדי של צבעי רקע.

אישור

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

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

getBackgrounds()

הפונקציה מחזירה את צבעי הרקע של התאים בטווח (לדוגמה, '#ffffff').

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B5:C6');
const bgColors = range.getBackgrounds();
for (const i in bgColors) {
  for (const j in bgColors[i]) {
    Logger.log(bgColors[i][j]);
  }
}

חזרה

String[][] — מערך דו-ממדי של קודי צבע של הרקעים.

אישור

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

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

getBandings()

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

// 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 a range.
const range = sheet.getRange('A1:K50');

// Gets the banding info for the range.
const bandings = range.getBandings();

// Logs the second row color for each banding to the console.
for (const banding of bandings) {
  console.log(banding.getSecondRowColor());
}

חזרה

Banding[] – כל ההדגשות שמוחלות על תאים בטווח הזה.

אישור

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

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

getCell(row, column)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B2:D4');

// The row and column here are relative to the range
// getCell(1,1) in this code returns the cell at B2
const cell = range.getCell(1, 1);
Logger.log(cell.getValue());

פרמטרים

שםסוגתיאור
rowIntegerהשורה של התא ביחס לטווח.
columnIntegerהעמודה של התא ביחס לטווח.

חזרה

Range – טווח שמכיל תא יחיד בקואורדינטות שצוינו.

אישור

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

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

getColumn()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B2:D4');
// Logs "2.0"
Logger.log(range.getColumn());

חזרה

Integer – מיקום עמודת ההתחלה של הטווח בגיליון האלקטרוני.

אישור

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

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

getDataRegion()

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

// Assume the active spreadsheet is blank.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
sheet.getRange('C2').setValue(100);
sheet.getRange('B3').setValue(100);
sheet.getRange('D3').setValue(100);
sheet.getRange('C4').setValue(100);
// Logs "B2:D4"
Logger.log(sheet.getRange('C3').getDataRegion().getA1Notation());

חזרה

Range — האזור הגיאוגרפי לאחסון נתונים של הטווח או טווח של הגיליון האלקטרוני כולו.

אישור

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

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

getDataRegion(dimension)

מחזירה עותק של הטווח המורחב Direction.UP ו-Direction.DOWN אם המימד שצוין הוא Dimension.ROWS, או Direction.NEXT ו-Direction.PREVIOUS אם המימד הוא Dimension.COLUMNS. הרחבת הטווח מבוססת על זיהוי נתונים לצד הטווח, שמאורגנים כמו טבלה. הטווח המורחב כולל את כל התאים הסמוכים עם נתונים לאורך המימד שצוין, כולל גבולות הטבלה. אם הטווח המקורי מוקף בתאים ריקים לאורך המימד שצוין, הטווח עצמו מוחזר. השיטה הזו דומה לבחירת הטווח ולהקלדת Ctrl+Space לעמודות או Shift+Space לשורות בכלי העריכה.

// Assume the active spreadsheet is blank.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
sheet.getRange('C2').setValue(100);
sheet.getRange('B3').setValue(100);
sheet.getRange('D3').setValue(100);
sheet.getRange('C4').setValue(100);
// Logs "C2:C4"
Logger.log(
    sheet.getRange('C3')
        .getDataRegion(SpreadsheetApp.Dimension.ROWS)
        .getA1Notation(),
);
// Logs "B3:D3"
Logger.log(
    sheet.getRange('C3')
        .getDataRegion(SpreadsheetApp.Dimension.COLUMNS)
        .getA1Notation(),
);

פרמטרים

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

חזרה

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

אישור

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

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

getDataSourceFormula()

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

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

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

// Gets the data source formula from cell A1.
const dataSourceFormula = range.getDataSourceFormula();

// Gets the formula.
const formula = dataSourceFormula.getFormula();

// Logs the formula.
console.log(formula);

חזרה

DataSourceFormulaDataSourceFormula של התא.

אישור

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

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

getDataSourceFormulas()

הפונקציה מחזירה את DataSourceFormulas של התאים בטווח.

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the range A1:B5 on Sheet1.
const range = sheet.getRange('A1:B5');

// Gets an array of the data source formulas in the range A1:B5.
const dataSourceFormulas = range.getDataSourceFormulas();

// Logs the first formula in the array.
console.log(dataSourceFormulas[0].getFormula());

חזרה

DataSourceFormula[] – מערך של DataSourceFormula.

אישור

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

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

getDataSourcePivotTables()

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

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the range A1:G50 on Sheet1.
const range = sheet.getRange('A1:G50');

// Gets an array of the data source pivot tables in the range A1:G50.
const dataSourcePivotTables = range.getDataSourcePivotTables();

// Logs the last time that the first pivot table in the array was refreshed.
console.log(dataSourcePivotTables[0].getStatus().getLastRefreshedTime());

חזרה

DataSourcePivotTable[] – רשימה של טבלאות צירים של מקורות נתונים.

אישור

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

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

getDataSourceTables()

אחזור כל הטבלאות של מקורות הנתונים שחופפות לטווח.

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the range A1:G50 on Sheet1.
const range = sheet.getRange('A1:G50');

// Gets the first data source table in the range A1:G50.
const dataSourceTable = range.getDataSourceTables()[0];

// Logs the time of the last completed data execution on the data source table.
console.log(dataSourceTable.getStatus().getLastExecutionTime());

חזרה

DataSourceTable[] — רשימה של טבלאות של מקורות נתונים.

אישור

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

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

getDataSourceUrl()

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

Code.gs

function doGet() {
  const ss = SpreadsheetApp.openById(
      '1khO6hBWTNNyvyyxvob7aoZTI9ZvlqqASNeq0e29Tw2c',
  );
  const sheet = ss.getSheetByName('ContinentData');
  const range = sheet.getRange('A1:B8');

  const template = HtmlService.createTemplateFromFile('piechart');
  template.dataSourceUrl = range.getDataSourceUrl();
  return template.evaluate();
}

piechart.html

<!DOCTYPE html>
<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      // Load the Visualization API and the corechart package.
      google.charts.load('current', {'packages': ['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.charts.setOnLoadCallback(queryData);

      function queryData() {
        var query = new google.visualization.Query('<?= dataSourceUrl ?>');
        query.send(drawChart);
      }

      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart(response) {
        if (response.isError()) {
          alert('Error: ' + response.getMessage() + ' ' + response.getDetailedMessage());
          return;
        }
        var data = response.getDataTable();

        // Set chart options.
        var options = {
          title: 'Population by Continent',
          width: 400,
          height: 300
        };

        // Instantiate and draw the chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <!-- Div that holds the pie chart. -->
    <div id="chart_div"></div>
  </body>
</html>

חזרה

String – כתובת URL של הטווח הזה כמקור נתונים שאפשר להעביר לממשקי API אחרים, כמו תרשימים.

אישור

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

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

getDataTable()

הפונקציה מחזירה את הנתונים בתוך האובייקט הזה כ-DataTable.

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the range A1:B7 on Sheet1.
const range = sheet.getRange('A1:B7');

// Gets the range A1:B7 as a data table. The values in each column must be of
// the same type.
const datatable = range.getDataTable();

// Uses the Charts service to build a bar chart from the data table.
// This doesn't build an embedded chart. To do that, use
// sheet.newChart().addRange() instead.
const chart = Charts.newBarChart()
                  .setDataTable(datatable)
                  .setOption('title', 'Your Chart Title Here')
                  .build();

חזרה

DataTable – הנתונים כטבלת נתונים.


getDataTable(firstRowIsHeader)

מחזירה את הנתונים בטווח הזה כ-DataTable.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:B7');

// Calling this method with "true" sets the first line to be the title of the
// axes
const datatable = range.getDataTable(true);

// Note that this doesn't build an EmbeddedChart, so you can't just use
// Sheet#insertChart(). To do that, use sheet.newChart().addRange() instead.
const chart = Charts.newBarChart()
                  .setDataTable(datatable)
                  .setOption('title', 'Your Title Here')
                  .build();

פרמטרים

שםסוגתיאור
firstRowIsHeaderBooleanהאם להתייחס לשורה הראשונה ככותרת.

חזרה

DataTable — הנתונים כטבלת נתונים.

אישור

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

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

getDataValidation()

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

// Log information about the data validation rule for cell A1.
const cell = SpreadsheetApp.getActive().getRange('A1');
const rule = cell.getDataValidation();
if (rule != null) {
  const criteria = rule.getCriteriaType();
  const args = rule.getCriteriaValues();
  Logger.log('The data validation rule is %s %s', criteria, args);
} else {
  Logger.log('The cell does not have a data validation rule.');
}

חזרה

DataValidation – כלל אימות הנתונים של התא הימני העליון בטווח.

אישור

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

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

getDataValidations()

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

// Change existing data validation rules that require a date in 2013 to require
// a date in 2014.
const oldDates = [new Date('1/1/2013'), new Date('12/31/2013')];
const newDates = [new Date('1/1/2014'), new Date('12/31/2014')];
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns());
const rules = range.getDataValidations();

for (let i = 0; i < rules.length; i++) {
  for (let j = 0; j < rules[i].length; j++) {
    const rule = rules[i][j];

    if (rule != null) {
      const criteria = rule.getCriteriaType();
      const args = rule.getCriteriaValues();

      if (criteria === SpreadsheetApp.DataValidationCriteria.DATE_BETWEEN &&
          args[0].getTime() === oldDates[0].getTime() &&
          args[1].getTime() === oldDates[1].getTime()) {
        // Create a builder from the existing rule, then change the dates.
        rules[i][j] = rule.copy().withCriteria(criteria, newDates).build();
      }
    }
  }
}
range.setDataValidations(rules);

חזרה

DataValidation[][] – מערך דו-ממדי של כללי אימות נתונים שמשויכים לתאים בטווח.

אישור

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

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

getDeveloperMetadata()

מחזירה את המטא-נתונים של המפתח שמשויכים לטווח הזה.

// 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 row 2 on Sheet1.
const range = sheet.getRange('2:2');

// Adds metadata to row 2.
range.addDeveloperMetadata('NAME', 'GOOGLE');

// Logs the metadata to console.
for (const metadata of range.getDeveloperMetadata()) {
  console.log(`${metadata.getKey()}: ${metadata.getValue()}`);
}

חזרה

DeveloperMetadata[] — המטא-נתונים של המפתח שמשויכים לטווח הזה.

אישור

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

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

getDisplayValue()

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

// 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 A30 and sets its value to 'Test code.'
const cell = sheet.getRange('A30');
cell.setValue('Test code');

// Gets the value and logs it to the console.
console.log(cell.getDisplayValue());

חזרה

String — הערך שמוצג בתא הזה.

אישור

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

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

getDisplayValues()

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

מחזירה מערך דו-ממדי של ערכים שמוצגים, עם אינדקס לפי שורה ואז לפי עמודה. הערכים הם אובייקטים של String. הערך שמוצג לוקח בחשבון את העיצוב של התאריך, השעה והמטבע, כולל פורמטים שמוחלים באופן אוטומטי על ידי הגדרת הלוקאל של הגיליון האלקטרוני. תאים ריקים מיוצגים על ידי מחרוזת ריקה במערך. חשוב לזכור שאינדקס טווח מתחיל ב-1, 1, אבל אינדקס המערך ב-JavaScript מתחיל ב-[0][0].

// The code below gets the displayed values for the range C2:G8
// in the active spreadsheet.  Note that this is a JavaScript array.
const values =
    SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getDisplayValues();
Logger.log(values[0][0]);

חזרה

String[][] – מערך דו-ממדי של ערכים.

אישור

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

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

getFilter()

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

const ss = SpreadsheetApp.getActiveSheet();
const range = ss.getRange('A1:C20');
// Gets the existing filter on the sheet that the given range belongs to.
const filter = range.getFilter();

חזרה

Filter – המסנן.

אישור

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

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

getFontColorObject()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getFontColorObject().asRgbColor().asHexString());

חזרה

Color — צבע הגופן של התא הימני העליון בטווח.

אישור

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

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

getFontColorObjects()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getFontColorObjects();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j].asRgbColor().asHexString());
  }
}

חזרה

Color[][] — מערך דו-ממדי של צבעי גופן שמשויכים לתאים בטווח.

אישור

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

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

getFontFamilies()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getFontFamilies();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

חזרה

String[][] — מערך דו-ממדי של משפחות גופנים שמשויכות לתאים בטווח.

אישור

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

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

getFontFamily()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getFontFamily());

חזרה

String – משפחת הגופנים של התא.

אישור

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

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

getFontLine()

מחזירה את סגנון הקו של התא בפינה הימנית העליונה של הטווח ('underline', ‏'line-through' או 'none').

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getFontLine());

חזרה

String — שורת הגופן.

אישור

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

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

getFontLines()

מחזירה את סגנון הקו של התאים בטווח ('underline', ‏'line-through' או 'none').

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getFontLines();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

חזרה

String[][] — מערך דו-ממדי של שורות גופן שמשויכות לתאים בטווח.

אישור

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

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

getFontSize()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getFontSize());

חזרה

Integer – גודל הגופן בנקודות.

אישור

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

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

getFontSizes()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getFontSizes();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

חזרה

Integer[][] — מערך דו-ממדי של גדלי הגופן של הטקסט שמשויך לתאים בטווח.

אישור

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

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

getFontStyle()

הפונקציה מחזירה את סגנון הגופן ('italic' או 'normal') של התא בפינה הימנית העליונה של הטווח.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getFontStyle());

חזרה

String — סגנון הגופן של הטקסט בתא.

אישור

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

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

getFontStyles()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getFontStyles();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

חזרה

String[][] – מערך דו-ממדי של סגנונות גופן של טקסט שמשויך לתאים בטווח.

אישור

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

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

getFontWeight()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getFontWeight());

חזרה

String — משקל הגופן של הטקסט בתא.

אישור

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

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

getFontWeights()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getFontWeights();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

חזרה

String[][] — מערך דו-ממדי של משקלי גופן של טקסט שמשויך לתאים בטווח.

אישור

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

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

getFormula()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// This assumes you have a function in B5 that sums up
// B2:B4
const range = sheet.getRange('B5');

// Logs the calculated value and the formula
Logger.log(
    'Calculated value: %s Formula: %s',
    range.getValue(),
    range.getFormula(),
);

חזרה

String – הנוסחה של התא.

אישור

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

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

getFormulaR1C1()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B5');
const formula = range.getFormulaR1C1();
Logger.log(formula);

חזרה

String — הנוסחה בשיטת הסימון R1C1.

אישור

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

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

getFormulas()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B5:C6');
const formulas = range.getFormulas();
for (const i in formulas) {
  for (const j in formulas[i]) {
    Logger.log(formulas[i][j]);
  }
}

חזרה

String[][] — מערך דו-ממדי של נוסחאות בפורמט מחרוזת.

אישור

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

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

getFormulasR1C1()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B5:C6');
const formulas = range.getFormulasR1C1();
for (const i in formulas) {
  for (const j in formulas[i]) {
    Logger.log(formulas[i][j]);
  }
}

חזרה

String[][] – מערך דו-ממדי של נוסחאות בסימון R1C1.

אישור

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

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

getGridId()

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

// Log the grid ID of the first sheet (by tab position) in the spreadsheet.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getGridId());

חזרה

Integer – המזהה של הגיליון הראשי.

אישור

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

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

getHeight()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B2:D4');
// logs 3.0
Logger.log(range.getHeight());

חזרה

Integer — גובה הטווח.

אישור

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

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

getHorizontalAlignment()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getHorizontalAlignment());

חזרה

String — היישור האופקי של הטקסט בתא.

אישור

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

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

getHorizontalAlignments()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getHorizontalAlignments();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

חזרה

String[][] — מערך דו-ממדי של יישורים אופקיים של טקסט שמשויך לתאים בטווח.

אישור

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

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

getLastColumn()

מחזירה את מיקום עמודת הסיום.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B2:D4');
// Logs "4.0"
Logger.log(range.getLastColumn());

חזרה

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

אישור

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

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

getLastRow()

מחזירה את מיקום שורת הסיום.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B2:D4');
// Logs "4.0"
Logger.log(range.getLastRow());

חזרה

Integer – מיקום שורת הסיום של הטווח בגיליון האלקטרוני.

אישור

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

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

getMergedRanges()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('A1:B3');

const mergedRanges = range.getMergedRanges();
for (let i = 0; i < mergedRanges.length; i++) {
  Logger.log(mergedRanges[i].getA1Notation());
  Logger.log(mergedRanges[i].getDisplayValue());
}

חזרה

Range[] — מערך של אובייקטים מסוג Range שמייצגים תאים ממוזגים שחופפים לטווח.


getNextDataCell(direction)

הפונקציה מתחילה בתא בעמודה ובשורה הראשונות של הטווח, ומחזירה את התא הבא בכיוון שצוין, שהוא הקצה של טווח רציף של תאים עם נתונים או התא בקצה של הגיליון האלקטרוני באותו כיוון. זה שווה ערך להקלדת Ctrl+[arrow key] בכלי העריכה.

// Assume the active spreadsheet is blank.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('C3:E5');
// Logs "C1"
Logger.log(range.getNextDataCell(SpreadsheetApp.Direction.UP).getA1Notation());

פרמטרים

שםסוגתיאור
directionDirectionהכיוון שבו צריך לחפש את התא הבא בקצה של אזור הנתונים.

חזרה

Range — התא בקצה של אזור הנתונים או התא בקצה של הגיליון האלקטרוני.

אישור

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

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

getNote()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getNote());

חזרה

String — ההערה שמשויכת לתא הנתון.

אישור

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

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

getNotes()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getNotes();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

חזרה

String[][] — מערך דו-ממדי של הערות שמשויכות לתאים בטווח.

אישור

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

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

getNumColumns()

הפונקציה מחזירה את מספר העמודות בטווח הזה.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B2:D5');
Logger.log(range.getNumColumns());

חזרה

Integer — מספר העמודות בטווח הזה.

אישור

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

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

getNumRows()

הפונקציה מחזירה את מספר השורות בטווח הזה.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B2:D5');
Logger.log(range.getNumRows());

חזרה

Integer — מספר השורות בטווח הזה.

אישור

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

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

getNumberFormat()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('C4');
Logger.log(cell.getNumberFormat());

חזרה

String — פורמט המספר של התא הימני העליון בטווח.

אישור

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

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

getNumberFormats()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B5:C6');
const formats = range.getNumberFormats();
for (const i in formats) {
  for (const j in formats[i]) {
    Logger.log(formats[i][j]);
  }
}

חזרה

String[][] — מערך דו-ממדי של פורמטים של מספרים.

אישור

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

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

getRichTextValue()

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

// Gets the Rich Text value of cell D4.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('D4:F6');
const richText = range.getRichTextValue();
console.log(richText.getText());

חזרה

RichTextValue — הערך של הטקסט העשיר בתא הימני העליון בטווח, או null אם ערך התא הוא לא טקסט.

אישור

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

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

getRichTextValues()

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

// Gets the Rich Text values for all cells in range B5:C6
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
const values = range.getRichTextValues();

for (let i = 0; i < values.length; i++) {
  for (let j = 0; j < values[i].length; j++) {
    console.log(values[i][j].getText());
  }
}

חזרה

RichTextValue[][] — מערך דו-ממדי של ערכי טקסט עשיר.

אישור

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

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

getRow()

מחזירה את מיקום השורה של הטווח הזה. זהה ל-getRowIndex().

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B2');
Logger.log(range.getRow());

חזרה

Integer — מיקום השורה של הטווח.

אישור

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

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

getRowIndex()

מחזירה את מיקום השורה של הטווח הזה. זהה ל-getRow()‎.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B2');
Logger.log(range.getRowIndex());

חזרה

Integer — מיקום השורה של הטווח.

אישור

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

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

ראה גם


getSheet()

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

// 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 the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Gets the sheet that the range belongs to.
const rangeSheet = range.getSheet();

// Gets the sheet name and logs it to the console.
console.log(rangeSheet.getName());

חזרה

Sheet — הגיליון שהטווח הזה שייך לו.

אישור

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

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

getTextDirection()

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

// Get the text direction of cell B1.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B1:D4');
Logger.log(range.getTextDirection());

חזרה

TextDirection — כיוון הטקסט של התא הימני העליון בטווח.

אישור

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

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

getTextDirections()

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

// Get the text directions for all cells in range B5:C6
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
const directions = range.getTextDirections();

for (let i = 0; i < directions.length; i++) {
  for (let j = 0; j < directions[i].length; j++) {
    Logger.log(directions[i][j]);
  }
}

חזרה

TextDirection[][] — מערך דו-ממדי של כיווני טקסט.

אישור

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

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

getTextRotation()

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

// Log the text rotation settings for a cell.
const sheet = SpreadsheetApp.getActiveSheet();

const cell = sheet.getRange('A1');
Logger.log(cell.getTextRotation());

חזרה

TextRotation — הגדרות סיבוב הטקסט.

אישור

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

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

getTextRotations()

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

const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');

const results = range.getTextRotations();

for (const i in results) {
  for (const j in results[i]) {
    const rotation = results[i][j];
    Logger.log('Cell [%s, %s] has text rotation: %v', i, j, rotation);
  }
}

חזרה

TextRotation[][] — מערך דו-ממדי של סיבובי טקסט שמשויכים לתאים בטווח.

אישור

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

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

getTextStyle()

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

// Get the text style of cell D4.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('D4:F6');
const style = range.getTextStyle();
Logger.log(style);

חזרה

TextStyle — סגנון הטקסט של התא הימני העליון בטווח.

אישור

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

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

getTextStyles()

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

// Get the text styles for all cells in range B5:C6
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
const styles = range.getTextStyles();

for (let i = 0; i < styles.length; i++) {
  for (let j = 0; j < styles[i].length; j++) {
    Logger.log(styles[i][j]);
  }
}

חזרה

TextStyle[][] – מערך דו-ממדי של סגנונות טקסט.

אישור

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

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

getValue()

הפונקציה מחזירה את הערך של התא הימני העליון בטווח. הערך יכול להיות מסוג Number,‏ Boolean, ‏ Date או String, בהתאם לערך של התא. תאים ריקים מחזירים מחרוזת ריקה.

// 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 the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Gets the value of the top-left cell in the range and logs it to the console.
console.log(range.getValue());

חזרה

Object – הערך בתא הזה.

אישור

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

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

getValues()

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

מחזירה מערך דו-ממדי של ערכים, עם אינדקס לפי שורה ואז לפי עמודה. הערכים יכולים להיות מהסוגים Number,‏ Boolean,‏ Date או String, בהתאם לערך של התא. תאים ריקים מיוצגים על ידי מחרוזת ריקה במערך. חשוב לזכור שאינדקס של טווח מתחיל ב-1, 1, אבל אינדקס של מערך JavaScript מתחיל ב-[0][0].

// The code below gets the values for the range C2:G8
// in the active spreadsheet.  Note that this is a JavaScript array.
const values = SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getValues();
Logger.log(values[0][0]);
באפליקציות אינטרנט, הערך Date לא נחשב לפרמטר חוקי. הפונקציה getValues() לא מחזירה נתונים לאפליקציית אינטרנט אם הטווח מכיל תא עם ערך Date. במקום זאת, צריך להמיר את כל הערכים שמאוחזרים מהגיליון לפרימיטיב נתמך של JavaScript, כמו Number, ‏ Boolean או String.

חזרה

Object[][] – מערך דו-ממדי של ערכים.

אישור

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

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

getVerticalAlignment()

הפונקציה מחזירה את היישור האנכי (למעלה/באמצע/למטה) של התא בפינה הימנית העליונה של הטווח.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getVerticalAlignment());

חזרה

String — היישור האנכי של הטקסט בתא.

אישור

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

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

getVerticalAlignments()

מחזירה את היישור האנכי של התאים בטווח.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getVerticalAlignments();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

חזרה

String[][] — מערך דו-ממדי של יישור אנכי של טקסט שמשויך לתאים בטווח.

אישור

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

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

getWidth()

הפונקציה מחזירה את רוחב הטווח בעמודות.

// 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 the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Gets the width of the range in number of columns and logs it to the console.
console.log(range.getWidth());

חזרה

Integer – מספר העמודות בטווח.

אישור

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

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

getWrap()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getWrap());

חזרה

Boolean – האם הטקסט בתא הזה גולש או לא.

אישור

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

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

getWrapStrategies()

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

// Get the text wrapping strategies for all cells in range B5:C6
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
const strategies = range.getWrapStrategies();

for (let i = 0; i < strategies.length; i++) {
  for (let j = 0; j < strategies[i].length; j++) {
    Logger.log(strategies[i][j]);
  }
}

חזרה

WrapStrategy[][] — מערך דו-ממדי של אסטרטגיות לגלישת טקסט.

אישור

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

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

getWrapStrategy()

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

// Get the text wrapping strategy of cell B1.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B1:D4');
Logger.log(range.getWrapStrategy());

חזרה

WrapStrategy — אסטרטגיית גלישת הטקסט של התא הימני העליון בטווח.

אישור

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

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

getWraps()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getVerticalAlignments();

for (const i in results) {
  for (const j in results[i]) {
    const isWrapped = results[i][j];
    if (isWrapped) {
      Logger.log('Cell [%s, %s] has wrapped text', i, j);
    }
  }
}

חזרה

Boolean[][] — מערך דו-ממדי של יישור אנכי של טקסט שמשויך לתאים בטווח.

אישור

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

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

insertCells(shiftDimension)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('A1:D10');
range.insertCells(SpreadsheetApp.Dimension.COLUMNS);

פרמטרים

שםסוגתיאור
shiftDimensionDimensionהמאפיין שלפיו יזוזו הנתונים הקיימים.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

insertCheckboxes()

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

const range = SpreadsheetApp.getActive().getRange('A1:B10');

// Inserts checkboxes into each cell in the range A1:B10 configured with 'true'
// for checked and 'false' for unchecked. Also, sets the value of each cell in
// the range A1:B10 to 'false'.
range.insertCheckboxes();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

insertCheckboxes(checkedValue)

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

const range = SpreadsheetApp.getActive().getRange('A1:B10');

// Inserts checkboxes into each cell in the range A1:B10 configured with 'yes'
// for checked and the empty string for unchecked. Also, sets the value of each
// cell in the range A1:B10 to
//  the empty string.
range.insertCheckboxes('yes');

פרמטרים

שםסוגתיאור
checkedValueObjectהערך שמסומן בתיבת הסימון לאימות נתונים.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

insertCheckboxes(checkedValue, uncheckedValue)

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

const range = SpreadsheetApp.getActive().getRange('A1:B10');

// Inserts checkboxes into each cell in the range A1:B10 configured with 'yes'
// for checked and 'no' for unchecked. Also, sets the value of each cell in the
// range A1:B10 to 'no'.
range.insertCheckboxes('yes', 'no');

פרמטרים

שםסוגתיאור
checkedValueObjectהערך שמסומן בתיבת הסימון לאימות נתונים.
uncheckedValueObjectהערך של תיבת הסימון כשהיא לא מסומנת, לצורך אימות הנתונים.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

isBlank()

הפונקציה מחזירה את הערך true אם הטווח ריק לחלוטין.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.isBlank());

חזרה

Booleantrue אם הטווח ריק; false אחרת.

אישור

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

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

isChecked()

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

const range = SpreadsheetApp.getActive().getRange('A1:A3');

// Inserts checkboxes and sets each cell value to 'no' in the range A1:A3.
range.insertCheckboxes('yes', 'no');

const range1 = SpreadsheetApp.getActive().getRange('A1');
range1.setValue('yes');
// Sets the value of isRange1Checked as true as it contains the checked value.
const isRange1Checked = range1.isChecked();

const range2 = SpreadsheetApp.getActive().getRange('A2');
range2.setValue('no');
// Sets the value of isRange2Checked as false as it contains the unchecked
// value.
const isRange2Checked = range2.isChecked();

const range3 = SpreadsheetApp.getActive().getRange('A3');
range3.setValue('random');
// Sets the value of isRange3Checked as null, as it contains an invalid checkbox
// value.
const isRange3Checked = range3.isChecked();

חזרה

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

אישור

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

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

isEndColumnBounded()

קובעת אם סוף הטווח קשור לעמודה מסוימת. לדוגמה, עבור הטווחים A1:B10 או B:B, שמוגבלים לעמודות בסוף הטווח, השיטה הזו מחזירה true. עבור הטווחים 3:7 או A1:5, שמוגבלים רק לשורות מסוימות בסוף הטווח, השיטה הזו מחזירה false.

// 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 the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Determines if the end of the range is bound to a particular column and logs
// it to the console.
console.log(range.isEndColumnBounded());

חזרה

Booleantrue אם סוף הטווח קשור לעמודה מסוימת; false אחרת.

אישור

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

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

isEndRowBounded()

קובעת אם סוף הטווח קשור לשורה מסוימת. לדוגמה, עבור הטווחים A1:B10 או 3:7, שמוגבלים לשורות בסוף הטווח, השיטה הזו מחזירה true. עבור הטווחים B:B או A1:C, שמוגבלים רק לעמודות מסוימות בסוף הטווח, השיטה הזו מחזירה false.

// 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 the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Determines if the end of the range is bound to a particular row and logs it
// to the console.
console.log(range.isEndRowBounded());

חזרה

Booleantrue אם סוף הטווח קשור לשורה מסוימת; false אחרת.

אישור

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

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

isPartOfMerge()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('A1:B3');

// True if any of the cells in A1:B3 is included in a merge.
const isPartOfMerge = range.isPartOfMerge();

חזרה

Booleantrue אם הטווח חופף לתאים מוזגו, אחרת מחזירה false.


isStartColumnBounded()

קובעת אם תחילת הטווח קשורה לעמודה מסוימת. לדוגמה, עבור הטווחים A1:B10 או B:B, שמוגבלים לעמודות בתחילת הטווח, הפונקציה הזו מחזירה true. עבור הטווח 3:7, שמוגבל רק לשורה בתחילת הטווח, הפונקציה הזו מחזירה false.

// 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 the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Determines if the start of the range is bound to a particular column and logs
// it to the console.
console.log(range.isStartColumnBounded());

חזרה

Booleantrue אם תחילת הטווח קשורה לעמודה מסוימת, אחרת false.

אישור

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

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

isStartRowBounded()

קובעת אם תחילת הטווח קשורה לשורה מסוימת. לדוגמה, עבור הטווחים A1:B10 או 3:7, שמוגבלים לשורות בתחילת הטווח, השיטה הזו מחזירה true. עבור הטווח B:B, שמוגבל רק לעמודה מסוימת בתחילת הטווח, השיטה הזו מחזירה false.

// 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 the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Determines if the start of the range is bound to a particular row and logs it
// to the console.
console.log(range.isStartRowBounded());

חזרה

Booleantrue אם תחילת הטווח קשורה לשורה מסוימת; false אחרת.

אישור

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

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

merge()

ממזגת את התאים בטווח לבלוק אחד.

const sheet = SpreadsheetApp.getActiveSheet();

// The code below 2-dimensionally merges the cells in A1 to B3
sheet.getRange('A1:B3').merge();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

mergeAcross()

ממזגים את התאים בטווח לאורך העמודות של הטווח.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// The code below merges cells C5:E5 into one cell
const range1 = sheet.getRange('C5:E5');
range1.mergeAcross();

// The code below creates 2 horizontal cells, F5:H5 and F6:H6
const range2 = sheet.getRange('F5:H6');
range2.mergeAcross();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

mergeVertically()

ממזגת את התאים בטווח.

const sheet = SpreadsheetApp.getActiveSheet();

// The code below vertically merges the cells in A1 to A10
sheet.getRange('A1:A10').mergeVertically();

// The code below creates 3 merged columns: B1 to B10, C1 to C10, and D1 to D10
sheet.getRange('B1:D10').mergeVertically();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

moveTo(target)

גוזרים ומדביקים (גם את הפורמט וגם את הערכים) מהטווח הזה לטווח היעד.

// The code below moves the first 5 columns over to the 6th column
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange('A1:E').moveTo(sheet.getRange('F1'));

פרמטרים

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

אישור

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

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

offset(rowOffset, columnOffset)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('A1');

// newCell references B2
const newCell = cell.offset(1, 1);

פרמטרים

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

חזרה

Range — הטווח הזה, לשרשור.


offset(rowOffset, columnOffset, numRows)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('A1');

// newCell references B2:B3
const newRange = cell.offset(1, 1, 2);

פרמטרים

שםסוגתיאור
rowOffsetIntegerמספר השורות מתחת לתא הימני העליון של הטווח. ערכים שליליים מייצגים שורות מעל התא הימני העליון של הטווח.
columnOffsetIntegerמספר העמודות מימין לתא הימני העליון בטווח. ערכים שליליים מייצגים עמודות משמאל לתא הימני העליון בטווח.
numRowsIntegerהגובה בשורות של הטווח החדש.

חזרה

Range — הטווח הזה, לשרשור.


offset(rowOffset, columnOffset, numRows, numColumns)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('A1');

// newCell references B2:C3
const newRange = cell.offset(1, 1, 2, 2);

פרמטרים

שםסוגתיאור
rowOffsetIntegerמספר השורות מתחת לתא הימני העליון של הטווח. ערכים שליליים מייצגים שורות מעל התא הימני העליון של הטווח.
columnOffsetIntegerמספר העמודות מימין לתא הימני העליון בטווח. ערכים שליליים מייצגים עמודות משמאל לתא הימני העליון בטווח.
numRowsIntegerהגובה בשורות של הטווח החדש.
numColumnsIntegerרוחב הטווח החדש בעמודות.

חזרה

Range — הטווח הזה, לשרשור.


protect()

יוצר אובייקט שיכול להגן על הטווח מפני עריכה, למעט משתמשים שיש להם הרשאה. עד שהסקריפט ישנה בפועל את רשימת העורכים של הטווח (על ידי קריאה ל-Protection.removeEditor(emailAddress),‏ Protection.removeEditor(user),‏ Protection.removeEditors(emailAddresses),‏ Protection.addEditor(emailAddress),‏ Protection.addEditor(user),‏ Protection.addEditors(emailAddresses) או הגדרה של ערך חדש ל-Protection.setDomainEdit(editable)), ההרשאות משקפות את ההרשאות של הגיליון האלקטרוני עצמו, מה שאומר למעשה שהטווח נשאר לא מוגן. אם הטווח כבר מוגן, השיטה הזו יוצרת טווח מוגן חדש שחופף לטווח הקיים. אם תא מוגן על ידי כמה טווחים מוגנים, ואחד מהם מונע ממשתמש מסוים לערוך את התא, אז למשתמש הזה אין הרשאה לערוך את התא.

// Protect range A1:B10, then remove all other users from the list of editors.
const ss = SpreadsheetApp.getActive();
const range = ss.getRange('A1:B10');
const protection = range.protect().setDescription('Sample protected range');

// Ensure the current user is an editor before removing others. Otherwise, if
// the user's edit permission comes from a group, the script throws an exception
// upon removing the group.
const me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
  protection.setDomainEdit(false);
}

חזרה

Protection – אובייקט שמייצג את הגדרות ההגנה.

אישור

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

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

randomize()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:C7');

// Randomizes the range
range.randomize();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

removeCheckboxes()

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

const range = SpreadsheetApp.getActive().getRange('A1:B10');

// Inserts checkboxes and sets each cell value to 'no' in the range A1:B10.
range.insertCheckboxes('yes', 'no');

const range1 = SpreadsheetApp.getActive().getRange('A1');
range1.setValue('yes');
// Removes the checkbox data validation in cell A1 and clears its value.
range1.removeCheckboxes();

const range2 = SpreadsheetApp.getActive().getRange('A2');
range2.setValue('random');
// Removes the checkbox data validation in cell A2 but does not clear its value.
range2.removeCheckboxes();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

removeDuplicates()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B1:D7');

// Remove duplicate rows in the range.
range.removeDuplicates();

חזרה

Range — הטווח שמתקבל אחרי הסרת הכפילויות. גודל הטווח יקטן בשורה אחת לכל שורה שתוסר.

אישור

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

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

removeDuplicates(columnsToCompare)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B1:D7');

// Remove rows which have duplicate values in column B.
range.removeDuplicates([2]);

// Remove rows which have duplicate values in both columns B and D.
range.removeDuplicates([2, 4]);

פרמטרים

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

חזרה

Range — הטווח שמתקבל אחרי הסרת הכפילויות. גודל הטווח יקטן בשורה אחת לכל שורה שתוסר.

אישור

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

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

setBackground(color)

מגדיר את צבע הרקע של כל התאים בטווח בסימון CSS (לדוגמה, '#ffffff' או 'white').

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('B2:D5');
range.setBackground('red');

פרמטרים

שםסוגתיאור
colorStringקוד צבע בסימון CSS (למשל '#ffffff' או 'white'); ערך של null מאפס את הצבע.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setBackgroundObject(color)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const bgColor = SpreadsheetApp.newColor()
                    .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND)
                    .build();

const range = sheet.getRange('B2:D5');
range.setBackgroundObject(bgColor);

פרמטרים

שםסוגתיאור
colorColorצבע הרקע שרוצים להגדיר. הערך null מאפס את צבע הרקע.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setBackgroundObjects(color)

הגדרת רשת מלבנית של צבעי רקע (המידות צריכות להיות זהות למידות של הטווח הזה).

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const colorAccent1 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)
                         .build();
const colorAccent2 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2)
                         .build();
const colorAccent3 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3)
                         .build();
const colorAccent4 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT4)
                         .build();

const colors = [
  [colorAccent1, colorAccent2],
  [colorAccent3, colorAccent4],
];

const cell = sheet.getRange('B5:C6');
cell.setBackgroundObjects(colors);

פרמטרים

שםסוגתיאור
colorColor[][]מערך דו-ממדי של צבעים. ערכי null מאפסים את הצבע.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setBackgroundRGB(red, green, blue)

הגדרת הרקע לצבע שצוין באמצעות ערכי RGB (מספרים שלמים בין 0 ל-255, כולל).

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');

// Sets the background to white
cell.setBackgroundRGB(255, 255, 255);

// Sets the background to red
cell.setBackgroundRGB(255, 0, 0);

פרמטרים

שםסוגתיאור
redIntegerהערך של האדום בסימון RGB.
greenIntegerהערך הירוק בסימון RGB.
blueIntegerהערך של הכחול בסימון RGB.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setBackgrounds(color)

הגדרת רשת מלבנית של צבעי רקע (המידות צריכות להיות זהות למידות של הטווח הזה). הצבעים הם בסימון CSS (למשל '#ffffff' או 'white').

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const colors = [
  ['red', 'white', 'blue'],
  ['#FF0000', '#FFFFFF', '#0000FF'],  // These are the hex equivalents
];

const cell = sheet.getRange('B5:D6');
cell.setBackgrounds(colors);

פרמטרים

שםסוגתיאור
colorString[][]מערך דו-ממדי של צבעים בסימון CSS (למשל '#ffffff' או 'white'); ערכים של null מאפסים את הצבע.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setBorder(top, left, bottom, right, vertical, horizontal)

הגדרת מאפיין הגבול. הערכים החוקיים הם true (מופעל), false (מושבת) ו-null (ללא שינוי).

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
// Sets borders on the top and bottom, but leaves the left and right unchanged
cell.setBorder(true, null, true, null, false, false);

פרמטרים

שםסוגתיאור
topBooleantrue לגבול, false ללא גבול, null ללא שינוי.
leftBooleantrue לגבול, false ללא גבול, null ללא שינוי.
bottomBooleantrue לגבול, false ללא גבול, null ללא שינוי.
rightBooleantrue לגבול, false ללא גבול, null ללא שינוי.
verticalBooleantrue לגבולות אנכיים פנימיים, false ללא גבולות, null ללא שינוי.
horizontalBooleantrue לגבולות אופקיים פנימיים, false ללא גבולות, null ללא שינוי.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setBorder(top, left, bottom, right, vertical, horizontal, color, style)

מגדיר את מאפיין הגבול עם צבע ו/או סגנון. הערכים החוקיים הם true (מופעל), false (מושבת) ו-null (ללא שינוי). לצבע, משתמשים בסימון צבע ב-CSS (למשל '#ffffff' או 'white').

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
// Sets borders on the top and bottom, but leaves the left and right unchanged
// Also sets the color to "red", and the border to "DASHED".
cell.setBorder(
    true,
    null,
    true,
    null,
    false,
    false,
    'red',
    SpreadsheetApp.BorderStyle.DASHED,
);

פרמטרים

שםסוגתיאור
topBooleantrue לגבול, false ללא גבול, null ללא שינוי.
leftBooleantrue לגבול, false ללא גבול, null ללא שינוי.
bottomBooleantrue לגבול, false ללא גבול, null ללא שינוי.
rightBooleantrue לגבול, false ללא גבול, null ללא שינוי.
verticalBooleantrue לגבולות אנכיים פנימיים, false ללא גבולות, null ללא שינוי.
horizontalBooleantrue לגבולות אופקיים פנימיים, false ללא גבולות, null ללא שינוי.
colorStringצבע בסימון CSS (למשל '#ffffff' או 'white'), null לצבע ברירת מחדל (שחור).
styleBorderStyleסגנון לגבולות, null לסגנון ברירת המחדל (אחיד).

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setDataValidation(rule)

מגדירה כלל אחד לאימות נתונים לכל התאים בטווח.

// Set the data validation rule for cell A1 to require a value from B1:B10.
const cell = SpreadsheetApp.getActive().getRange('A1');
const range = SpreadsheetApp.getActive().getRange('B1:B10');
const rule =
    SpreadsheetApp.newDataValidation().requireValueInRange(range).build();
cell.setDataValidation(rule);

פרמטרים

שםסוגתיאור
ruleDataValidationכלל אימות הנתונים שרוצים להגדיר, או null כדי להסיר את אימות הנתונים.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setDataValidations(rules)

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

// Set the data validation rules for Sheet1!A1:B5 to require a value from
// Sheet2!A1:A10.
const destinationRange =
    SpreadsheetApp.getActive().getSheetByName('Sheet1').getRange('A1:B5');
const sourceRange =
    SpreadsheetApp.getActive().getSheetByName('Sheet2').getRange('A1:A10');
const rule =
    SpreadsheetApp.newDataValidation().requireValueInRange(sourceRange).build();
const rules = destinationRange.getDataValidations();
for (let i = 0; i < rules.length; i++) {
  for (let j = 0; j < rules[i].length; j++) {
    rules[i][j] = rule;
  }
}
destinationRange.setDataValidations(rules);

פרמטרים

שםסוגתיאור
rulesDataValidation[][]מערך דו-ממדי של כללים לאימות נתונים להגדרה; null ערכים מסירים אימות נתונים.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontColor(color)

הגדרת צבע הגופן בסימון CSS (למשל '#ffffff' או 'white').

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
cell.setFontColor('red');

פרמטרים

שםסוגתיאור
colorStringצבע הגופן בסימון CSS (למשל '#ffffff' או 'white'); ערך של null מאפס את הצבע.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontColorObject(color)

הגדרת צבע הגופן של הטווח הנתון.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const color = SpreadsheetApp.newColor()
                  .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT)
                  .build();

const cell = sheet.getRange('B2');
cell.setFontColor(color);

פרמטרים

שםסוגתיאור
colorColorצבע הגופן שרוצים להגדיר. ערך של null מאפס את הצבע.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontColorObjects(colors)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const colorAccent1 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)
                         .build();
const colorAccent2 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2)
                         .build();
const colorAccent3 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3)
                         .build();
const colorAccent4 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT4)
                         .build();

const colors = [
  [colorAccent1, colorAccent2],
  [colorAccent3, colorAccent4],
];

const cell = sheet.getRange('B5:C6');
cell.setFontColorObjects(colors);

פרמטרים

שםסוגתיאור
colorsColor[][]מערך דו-ממדי של צבעים. ערכים של null מאפסים את צבע הגופן.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontColors(colors)

מגדיר רשת מלבנית של צבעי גופן (חייב להתאים לממדים של הטווח הזה). הצבעים מופיעים בסימון CSS (למשל, '#ffffff' או 'white').

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const colors = [
  ['red', 'white', 'blue'],
  ['#FF0000', '#FFFFFF', '#0000FF'],  // These are the hex equivalents
];

const cell = sheet.getRange('B5:D6');
cell.setFontColors(colors);

פרמטרים

שםסוגתיאור
colorsObject[][]מערך דו-ממדי של צבעים בסימון CSS (למשל '#ffffff' או 'white'); ערכים של null מאפסים את הצבע.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontFamilies(fontFamilies)

מגדיר רשת מלבנית של משפחות גופנים (צריך להתאים לממדים של הטווח הזה). דוגמאות למשפחות גופנים: Arial או Helvetica.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const fonts = [
  ['Arial', 'Helvetica', 'Verdana'],
  ['Courier New', 'Arial', 'Helvetica'],
];

const cell = sheet.getRange('B2:D3');
cell.setFontFamilies(fonts);

פרמטרים

שםסוגתיאור
fontFamiliesObject[][]מערך דו-ממדי של משפחות גופנים; ערכי null מאפסים את משפחת הגופנים.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontFamily(fontFamily)

מגדיר את משפחת הגופנים, כמו Arial או Helvetica.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
cell.setFontFamily('Helvetica');

פרמטרים

שםסוגתיאור
fontFamilyStringמשפחת הגופנים להגדרה. ערך null מאפס את משפחת הגופנים.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontLine(fontLine)

מגדיר את סגנון הקו של הגופן בטווח הנתון ('underline', 'line-through' או 'none').

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
cell.setFontLine('line-through');

פרמטרים

שםסוגתיאור
fontLineStringסגנון הקו של הגופן, 'underline', 'line-through' או 'none'. ערך של null מאפס את סגנון הקו של הגופן.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontLines(fontLines)

מגדיר רשת מלבנית של סגנונות קו (חייב להתאים לממדים של הטווח הזה).

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// The size of the two-dimensional array must match the size of the range.
const fontLines = [['underline', 'line-through', 'none']];

const range = sheet.getRange('B2:D2');
range.setFontLines(fontLines);

פרמטרים

שםסוגתיאור
fontLinesObject[][]מערך דו-ממדי של סגנונות קו של גופן ('underline',‏ 'line-through' או 'none'); ערכים של null מאפסים את סגנון הקו של הגופן.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontSize(size)

הגדרת גודל הגופן, כאשר הגודל הוא גודל הנקודה לשימוש.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
cell.setFontSize(20);

פרמטרים

שםסוגתיאור
sizeIntegerגודל הגופן בנקודות.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontSizes(sizes)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// The size of the two-dimensional array must match the size of the range.
const fontSizes = [[16, 20, 24]];

const range = sheet.getRange('B2:D2');
range.setFontSizes(fontSizes);

פרמטרים

שםסוגתיאור
sizesObject[][]מערך דו-ממדי של גדלים.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontStyle(fontStyle)

הגדרת סגנון הגופן לטווח הנתון ('italic' או 'normal').

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
cell.setFontStyle('italic');

פרמטרים

שםסוגתיאור
fontStyleStringסגנון הגופן, 'italic' או 'normal'. ערך של null מאפס את סגנון הגופן.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontStyles(fontStyles)

מגדיר רשת מלבנית של סגנונות גופן (חייב להתאים לממדים של הטווח הזה).

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// The size of the two-dimensional array must match the size of the range.
const fontStyles = [['italic', 'normal']];

const range = sheet.getRange('B2:C2');
range.setFontStyles(fontStyles);

פרמטרים

שםסוגתיאור
fontStylesObject[][]מערך דו-ממדי של סגנונות גופן, 'italic' או 'normal'. הערכים null מאפסים את סגנון הגופן.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontWeight(fontWeight)

הגדרת עובי הגופן לטווח הנתון (רגיל/מודגש).

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
cell.setFontWeight('bold');

פרמטרים

שםסוגתיאור
fontWeightStringעובי הגופן, 'bold' או 'normal'. ערך של null מאפס את עובי הגופן.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFontWeights(fontWeights)

מגדיר רשת מלבנית של משקלי גופן (חייב להתאים לממדים של הטווח הזה). דוגמה למשקל גופן היא bold (מודגש).

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// The size of the two-dimensional array must match the size of the range.
const fontStyles = [['bold', 'bold', 'normal']];

const range = sheet.getRange('B2:D2');
range.setFontWeights(fontStyles);

פרמטרים

שםסוגתיאור
fontWeightsObject[][]מערך דו-ממדי של משקלי גופן, 'bold' או 'normal'. הערכים null מאפסים את משקל הגופן.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFormula(formula)

מעדכן את הנוסחה של הטווח הזה. הנוסחה שצוינה חייבת להיות בסימון A1.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B5');
cell.setFormula('=SUM(B3:B4)');

פרמטרים

שםסוגתיאור
formulaStringמחרוזת שמייצגת את הנוסחה להגדרה בתא.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFormulaR1C1(formula)

מעדכן את הנוסחה של הטווח הזה. הנוסחה שצוינה חייבת להיות בסימון R1C1.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B5');
// This sets the formula to be the sum of the 3 rows above B5
cell.setFormulaR1C1('=SUM(R[-3]C[0]:R[-1]C[0])');

פרמטרים

שםסוגתיאור
formulaStringנוסחה של מחרוזת.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFormulas(formulas)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// This sets the formulas to be a row of sums, followed by a row of averages
// right below. The size of the two-dimensional array must match the size of the
// range.
const formulas = [
  ['=SUM(B2:B4)', '=SUM(C2:C4)', '=SUM(D2:D4)'],
  ['=AVERAGE(B2:B4)', '=AVERAGE(C2:C4)', '=AVERAGE(D2:D4)'],
];

const cell = sheet.getRange('B5:D6');
cell.setFormulas(formulas);

פרמטרים

שםסוגתיאור
formulasString[][]מערך דו-ממדי של נוסחאות כמחרוזות.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setFormulasR1C1(formulas)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// This creates formulas for a row of sums, followed by a row of averages.
const sumOfRowsAbove = '=SUM(R[-3]C[0]:R[-1]C[0])';
const averageOfRowsAbove = '=AVERAGE(R[-4]C[0]:R[-2]C[0])';

// The size of the two-dimensional array must match the size of the range.
const formulas = [
  [sumOfRowsAbove, sumOfRowsAbove, sumOfRowsAbove],
  [averageOfRowsAbove, averageOfRowsAbove, averageOfRowsAbove],
];

const cell = sheet.getRange('B5:D6');
// This sets the formula to be the sum of the 3 rows above B5.
cell.setFormulasR1C1(formulas);

פרמטרים

שםסוגתיאור
formulasString[][]מערך דו-ממדי של נוסחאות בפורמט R1C1.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setHorizontalAlignment(alignment)

הגדרת היישור האופקי (משמאל לימין) לטווח הנתון (שמאל/מרכז/ימין).

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
cell.setHorizontalAlignment('center');

פרמטרים

שםסוגתיאור
alignmentStringההיערכות, 'left', 'center' או 'normal'. הערך null מאפס את ההיערכות.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setHorizontalAlignments(alignments)

הגדרת רשת מלבנית של יישורים אופקיים. ראו setHorizontalAlignment(alignment)

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// The size of the two-dimensional array must match the size of the range.
const horizontalAlignments = [['left', 'right', 'center']];

const range = sheet.getRange('B2:D2');
range.setHorizontalAlignments(horizontalAlignments);

פרמטרים

שםסוגתיאור
alignmentsObject[][]מערך דו-ממדי של יישור, 'left', 'center' או 'normal'; ערך של null מאפס את היישור.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

ראה גם


setNote(note)

מגדיר את ההערה לערך שצוין.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
cell.setNote('This is a note');

פרמטרים

שםסוגתיאור
noteStringערך ההערה שרוצים להגדיר לטווח. ערך של null מסיר את ההערה.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setNotes(notes)

מגדיר רשת מלבנית של הערות (חייב להתאים לממדים של הטווח הזה).

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// The size of the two-dimensional array must match the size of the range.
const notes = [
  ['it goes', 'like this', 'the fourth, the fifth'],
  ['the minor fall', 'and the', 'major lift'],
];

const cell = sheet.getRange('B2:D3');
cell.setNotes(notes);

פרמטרים

שםסוגתיאור
notesObject[][]מערך דו-ממדי של הערות. ערכים של null מסירים את ההערה.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

ראה גם


setNumberFormat(numberFormat)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
// Always show 3 decimal points
cell.setNumberFormat('0.000');

פרמטרים

שםסוגתיאור
numberFormatStringמחרוזת של פורמט מספרים.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setNumberFormats(numberFormats)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// The size of the two-dimensional array must match the size of the range.
const formats = [['0.000', '0,000,000', '$0.00']];

const range = sheet.getRange('B2:D2');
range.setNumberFormats(formats);

פרמטרים

שםסוגתיאור
numberFormatsObject[][]מערך דו-ממדי של פורמטים של מספרים.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setRichTextValue(value)

מגדירה את הערך של הטקסט העשיר לתאים בטווח.

// Sets all cells in range B2:D4 to have the text "Hello world", with "Hello"
// bolded.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const richText = SpreadsheetApp.newRichTextValue()
                     .setText('Hello world')
                     .setTextStyle(0, 5, bold)
                     .build();
range.setRichTextValue(richText);

פרמטרים

שםסוגתיאור
valueRichTextValueהערך הרצוי של הטקסט העשיר.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setRichTextValues(values)

מגדירה רשת מלבנית של ערכי טקסט עשיר.

// Sets the cells in range A1:A2 to have Rich Text values.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('A1:A2');
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const italic = SpreadsheetApp.newTextStyle().setItalic(true).build();
const richTextA1 = SpreadsheetApp.newRichTextValue()
                       .setText('This cell is bold')
                       .setTextStyle(bold)
                       .build();
const richTextA2 = SpreadsheetApp.newRichTextValue()
                       .setText('bold words, italic words')
                       .setTextStyle(0, 11, bold)
                       .setTextStyle(12, 24, italic)
                       .build();
range.setRichTextValues([[richTextA1], [richTextA2]]);

פרמטרים

שםסוגתיאור
valuesRichTextValue[][]הערכים הרצויים של טקסט עשיר.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

הגדרה שקובעת אם להציג היפר-קישורים בטווח או לא.

// Opens the spreadsheet file by its URL. If you created your script from within
// a Google Sheets file, you can useSpreadsheetApp.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 A30 and sets its hyperlink value.
const range = sheet.getRange('A30');
range.setValue('https://www.example.com');

// Sets cell A30 to show hyperlinks.
range.setShowHyperlink(true);

פרמטרים

שםסוגתיאור
showHyperlinkBooleanהאם להציג את ההיפר-קישור.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setTextDirection(direction)

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

// Sets right-to-left text direction for the range.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
range.setTextDirection(SpreadsheetApp.TextDirection.RIGHT_TO_LEFT);

פרמטרים

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

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setTextDirections(directions)

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

// Copies all of the text directions from range A1:B2 over to range C5:D6.
const sheet = SpreadsheetApp.getActiveSheet();
const range1 = sheet.getRange('A1:B2');
const range2 = sheet.getRange('C5:D6');

range2.setTextRotations(range1.getTextDirections());

פרמטרים

שםסוגתיאור
directionsTextDirection[][]כיווני הטקסט הרצויים. אם הכיוון שצוין הוא null, המערכת מסיקה את הכיוון לפני ההגדרה.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setTextRotation(degrees)

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

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

// Sets all cell's in range B2:D4 to have text rotated up 45 degrees.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');

range.setTextRotation(45);

פרמטרים

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

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setTextRotation(rotation)

הגדרת ההגדרות של סיבוב הטקסט בתאים בטווח.

// Sets all cell's in range B2:D4 to have the same text rotation settings as
// cell A1.
const sheet = SpreadsheetApp.getActiveSheet();

const rotation = sheet.getRange('A1').getTextRotation();

sheet.getRange('B2:D4').setTextRotation(rotation);

פרמטרים

שםסוגתיאור
rotationTextRotationהגדרות סיבוב הטקסט הרצויות.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setTextRotations(rotations)

הגדרת רשת מלבנית של סיבובי טקסט.

// Copies all of the text rotations from range A1:B2 over to range C5:D6.
const sheet = SpreadsheetApp.getActiveSheet();
const range1 = sheet.getRange('A1:B2');
const range2 = sheet.getRange('C5:D6');

range2.setTextRotations(range1.getTextRotations());

פרמטרים

שםסוגתיאור
rotationsTextRotation[][]הגדרות סיבוב הטקסט הרצויות.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setTextStyle(style)

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

// Sets the cells in range C5:D6 to have underlined size 15 font.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('C5:D6');
const style =
    SpreadsheetApp.newTextStyle().setFontSize(15).setUnderline(true).build();
range.setTextStyle(style);

פרמטרים

שםסוגתיאור
styleTextStyleסגנון הטקסט הרצוי.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setTextStyles(styles)

מגדירה רשת מלבנית של סגנונות טקסט.

// Sets text styles for cells in range A1:B2
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('A1:B2');
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const otherStyle = SpreadsheetApp.newTextStyle()
                       .setBold(true)
                       .setUnderline(true)
                       .setItalic(true)
                       .setForegroundColor('#335522')
                       .setFontSize(44)
                       .build();
range.setTextStyles([
  [bold, otherStyle],
  [otherStyle, bold],
]);

פרמטרים

שםסוגתיאור
stylesTextStyle[][]סגנונות הטקסט הרצויים.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setValue(value)

הגדרת הערך של הטווח. הערך יכול להיות מספרי, מחרוזת, בוליאני או תאריך. אם הוא מתחיל ב-'=', הוא מתפרש כנוסחה.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
cell.setValue(100);

פרמטרים

שםסוגתיאור
valueObjectהערך של הטווח.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setValues(values)

מגדיר רשת מלבנית של ערכים (חייב להתאים לממדים של הטווח הזה). אם ערך מתחיל ב-=, הוא מפורש כנוסחה.

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// The size of the two-dimensional array must match the size of the range.
const values = [['2.000', '1,000,000', '$2.99']];

const range = sheet.getRange('B2:D2');
range.setValues(values);

פרמטרים

שםסוגתיאור
valuesObject[][]מערך דו-ממדי של ערכים.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setVerticalAlignment(alignment)

הגדרת היישור האנכי (מלמעלה למטה) לטווח הנתון (למעלה/באמצע/למטה).

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
cell.setVerticalAlignment('middle');

פרמטרים

שםסוגתיאור
alignmentStringההיערכות, 'top', 'middle' או 'bottom'. הערך null מאפס את ההיערכות.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setVerticalAlignments(alignments)

הגדרת רשת מלבנית של יישור אנכי (חייבת להתאים למידות של הטווח הזה).

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// The size of the two-dimensional array must match the size of the range.
const alignments = [['top', 'middle', 'bottom']];

const range = sheet.getRange('B2:D2');
range.setVerticalAlignments(alignments);

פרמטרים

שםסוגתיאור
alignmentsObject[][]מערך דו-ממדי של יישור, 'top', 'middle' או 'bottom'. ערך של null מאפס את היישור.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

ראה גם


setVerticalText(isVertical)

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

// Sets all cell's in range B2:D4 to have vertically stacked text.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');

range.setVerticalText(true);

פרמטרים

שםסוגתיאור
isVerticalBooleanהאם להציג את הטקסט בשורה אחת או בשתי שורות.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setWrap(isWrapEnabled)

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

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const cell = sheet.getRange('B2');
cell.setWrap(true);

פרמטרים

שםסוגתיאור
isWrapEnabledBooleanהאם להפעיל גלישת טקסט או לא.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setWrapStrategies(strategies)

מגדירה רשת מלבנית של שיטות גלישת טקסט.

// Copies all of the wrap strategies from range A1:B2 over to range C5:D6.
const sheet = SpreadsheetApp.getActiveSheet();
const range1 = sheet.getRange('A1:B2');
const range2 = sheet.getRange('C5:D6');

range2.setWrapStrategies(range1.getWrapStrategies());

פרמטרים

שםסוגתיאור
strategiesWrapStrategy[][]אסטרטגיות הגלישה הרצויות.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setWrapStrategy(strategy)

הגדרת אסטרטגיית גלישת הטקסט בתאים בטווח.

// Sets all cells in range B2:D4 to use the clip wrap strategy.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');

range.setWrapStrategy(SpreadsheetApp.WrapStrategy.CLIP);

פרמטרים

שםסוגתיאור
strategyWrapStrategyאסטרטגיית הגלישה הרצויה.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

setWraps(isWrapEnabled)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

// The size of the two-dimensional array must match the size of the range.
const wraps = [[true, true, false]];

const range = sheet.getRange('B2:D2');
range.setWraps(wraps);

פרמטרים

שםסוגתיאור
isWrapEnabledObject[][]מערך דו-ממדי של משתני גלישה שקובעים אם הטקסט בתא יגלוש או לא.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

ראה גם


shiftColumnGroupDepth(delta)

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

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

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

אם הערך של column group control position הוא BEFORE, תופיע שגיאה כשמנסים להזיז את העומק של השורה הראשונה.

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();

// The column grouping depth is increased by 1.
range.shiftColumnGroupDepth(1);

// The column grouping depth is decreased by 1.
range.shiftColumnGroupDepth(-1);

פרמטרים

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

חזרה

Range — הטווח הזה, לשרשור.

זריקות

Error — כשמנסים לשנות את העומק של העמודה הראשונה כשמיקום אמצעי הבקרה הוא GroupControlTogglePosition.BEFORE

אישור

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

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

shiftRowGroupDepth(delta)

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

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

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

אם הערך של row group control position הוא BEFORE, תופיע שגיאה כשמנסים להזיז את העומק של השורה הראשונה.

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();

// The row grouping depth is increased by 1.
range.shiftRowGroupDepth(1);

// The row grouping depth is decreased by 1.
range.shiftRowGroupDepth(-1);

פרמטרים

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

חזרה

Range — הטווח הזה, לשרשור.

זריקות

Error – כשמנסים לשנות את העומק של השורה הראשונה כשמיקום הפקד הוא GroupControlTogglePosition.BEFORE

אישור

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

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

sort(sortSpecObj)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:C7');

// Sorts by the values in the first column (A)
range.sort(1);

// Sorts by the values in the second column (B)
range.sort(2);

// Sorts descending by column B
range.sort({column: 2, ascending: false});

// Sorts descending by column B, then ascending by column A
// Note the use of an array
range.sort([
  {column: 2, ascending: false},
  {column: 1, ascending: true},
]);

// For rows that are sorted in ascending order, the "ascending" parameter is
// optional, and just an integer with the column can be used instead. Note that
// in general, keeping the sort specification consistent results in more
// readable code. You can express the earlier sort as:
range.sort([{column: 2, ascending: false}, 1]);

// Alternatively, if you want all columns to be in ascending order, you can use
// the following (this makes column 2 ascending)
range.sort([2, 1]);
// ... which is equivalent to
range.sort([
  {column: 2, ascending: true},
  {column: 1, ascending: true},
]);

פרמטרים

שםסוגתיאור
sortSpecObjObjectהעמודות שלפיהן יבוצע המיון.

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

splitTextToColumns()

מפצלת עמודת טקסט לכמה עמודות על סמך מפריד שזוהה אוטומטית.

// A1:A3 has the following values:
//           A                  B                 C
// 1 |one,one,one      |                 |                 |
// 2 |two,two,two      |                 |                 |
// 3 |three,three,three|                 |                 |

const range = SpreadsheetApp.getActiveSheet().getRange('A1:A3');
range.splitTextToColumns();

// Result after splitting the text to columns:
//           A                  B                 C
// 1 |one              |one              |one              |
// 2 |two              |two              |two              |
// 3 |three            |three            |three            |

אישור

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

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

splitTextToColumns(delimiter)

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

// A1:A3 has the following values:
//           A                  B                 C
// 1 |one#one#one      |                 |                 |
// 2 |two#two#two      |                 |                 |
// 3 |three#three#three|                 |                 |

const range = SpreadsheetApp.getActiveSheet().getRange('A1:A3');
range.splitTextToColumns('#');

// Result after splitting the text to columns:
//           A                  B                 C
// 1 |one              |one              |one              |
// 2 |two              |two              |two              |
// 3 |three            |three            |three            |

פרמטרים

שםסוגתיאור
delimiterStringהמפריד המותאם אישית שלפיו יתבצע הפיצול.

אישור

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

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

splitTextToColumns(delimiter)

מפצלת עמודת טקסט לכמה עמודות על סמך התו המפריד שצוין.

// A1:A3 has the following values:
//           A                  B                 C
// 1 |one;one;one      |                 |                 |
// 2 |two;two;two      |                 |                 |
// 3 |three;three;three|                 |                 |

const range = SpreadsheetApp.getActiveSheet().getRange('A1:A3');
range.splitTextToColumns(SpreadsheetApp.TextToColumnsDelimiter.SEMICOLON);

// Result after splitting the text to columns:
//           A                  B                 C
// 1 |one              |one              |one              |
// 2 |two              |two              |two              |
// 3 |three            |three            |three            |

פרמטרים

שםסוגתיאור
delimiterTextToColumnsDelimiterהתו המפריד שמוגדר מראש לפיצול.

אישור

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

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

trimWhitespace()

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

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getRange('A1:A4');
range.activate();
range.setValues([
  ' preceding space',
  'following space ',
  'two  middle  spaces',
  '   =SUM(1,2)',
]);

range.trimWhitespace();

const values = range.getValues();
// Values are ['preceding space', 'following space', 'two middle spaces',
// '=SUM(1,2)']

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

uncheck()

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

// Changes the state of cells which currently contain either the checked or
// unchecked value configured in the range A1:B10 to 'unchecked'.
const range = SpreadsheetApp.getActive().getRange('A1:B10');
range.uncheck();

חזרה

Range — הטווח הזה, לשרשור.

אישור

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

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

שיטות שהוצאו משימוש