Class Master

Master

A master in a presentation.

Masters contains all common page elements and the common properties for a set of layouts. They serve three purposes:

  • Placeholder shapes on a master contain the default text styles and shape properties of all placeholder shapes on pages that use that master.
  • The properties of a master page define the common page properties inherited by its layouts.
  • Any other shapes on the master slide appear on all slides using that master, regardless of their layout.

Methods

MethodReturn typeBrief description
getBackground()PageBackgroundGets the page's background.
getColorScheme()ColorSchemeGets the ColorScheme associated with the page.
getGroups()Group[]Returns the list of Group objects on the page.
getImages()Image[]Returns the list of Image objects on the page.
getLayouts()Layout[]Gets this master's layouts.
getLines()Line[]Returns the list of Line objects on the page.
getObjectId()StringGets the unique ID for the page.
getPageElements()PageElement[]Returns the list of PageElement objects rendered on the page.
getPageType()PageTypeGets the type of the page.
getPlaceholder(placeholderType)PageElementReturns the placeholder PageElement object for a specified PlaceholderType or null if a matching placeholder is not present.
getPlaceholder(placeholderType, placeholderIndex)PageElementReturns the placeholder PageElement object for a specified PlaceholderType and a placeholder index, or null if the placeholder is not present.
getPlaceholders()PageElement[]Returns the list of placeholder PageElement objects in the page.
getShapes()Shape[]Returns the list of Shape objects on the page.
getSheetsCharts()SheetsChart[]Returns the list of SheetsChart objects on the page.
getTables()Table[]Returns the list of Table objects on the page.
getVideos()Video[]Returns the list of Video objects on the page.
getWordArts()WordArt[]Returns the list of WordArt objects on the page.
insertImage(blobSource)ImageInserts an image at the top left corner of the page with a default size from the specified image blob.
insertImage(blobSource, left, top, width, height)ImageInserts an image on the page with the provided position and size from the specified image blob.
insertImage(imageUrl)ImageInserts an image at the top left corner of the page with a default size from the provided URL.
insertImage(imageUrl, left, top, width, height)ImageInserts an image on the page with the provided position and size from the provided URL.
insertLine(lineCategory, startLeft, startTop, endLeft, endTop)LineInserts a line on the page.
insertShape(shapeType)ShapeInserts a shape on the page.
insertShape(shapeType, left, top, width, height)ShapeInserts a shape on the page.
insertSheetsChart(sourceChart)SheetsChartInserts a Google Sheets chart on the page.
insertSheetsChart(sourceChart, left, top, width, height)SheetsChartInserts a Google Sheets chart on the page with the provided position and size.
insertSheetsChartAsImage(sourceChart)ImageInserts a Google Sheets chart as an Image on the page.
insertSheetsChartAsImage(sourceChart, left, top, width, height)ImageInserts a Google Sheets chart as an Image on the page with the provided position and size.
insertTable(numRows, numColumns)TableInserts a table on the page.
insertTable(numRows, numColumns, left, top, width, height)TableInserts a table on the page with the provided position and size.
insertVideo(videoUrl)VideoInserts a video at the top left corner of the page with a default size.
insertVideo(videoUrl, left, top, width, height)VideoInserts a video on the page with the provided position and size.
remove()voidRemoves the page.
replaceAllText(findText, replaceText)IntegerReplaces all instances of text matching find text with replace text.
replaceAllText(findText, replaceText, matchCase)IntegerReplaces all instances of text matching find text with replace text.
selectAsCurrentPage()voidSelects the Page in the active presentation as the current page selection and removes any previous selection.

Detailed documentation

getBackground()

Gets the page's background.

Return

PageBackground


getColorScheme()

Gets the ColorScheme associated with the page.

Return

ColorScheme


getGroups()

Returns the list of Group objects on the page.

Return

Group[]


getImages()

Returns the list of Image objects on the page.

Return

Image[]


getLayouts()

Gets this master's layouts.

Return

Layout[]


getLines()

Returns the list of Line objects on the page.

Return

Line[]


getObjectId()

Gets the unique ID for the page. Object IDs used by pages and page elements share the same namespace.

Return

String


getPageElements()

Returns the list of PageElement objects rendered on the page.

Return

PageElement[]


getPageType()

Gets the type of the page.

Return

PageType


getPlaceholder(placeholderType)

Returns the placeholder PageElement object for a specified PlaceholderType or null if a matching placeholder is not present.

If there are multiple placeholders with the same type, it returns the one with minimal placeholder index. If there are multiple matching placeholders with the same index, it returns the first placeholder from the page's page elements collection.

 var slide = SlidesApp.getActivePresentation().getSlides()[0];
 var placeholder = slide.getPlaceholder(SlidesApp.PlaceholderType.CENTERED_TITLE);
 

Parameters

NameTypeDescription
placeholderTypePlaceholderType

Return

PageElement


getPlaceholder(placeholderType, placeholderIndex)

Returns the placeholder PageElement object for a specified PlaceholderType and a placeholder index, or null if the placeholder is not present.

If there are multiple placeholders with the same type and index, it returns the first placeholder from the page's page elements collection.

 var slide = SlidesApp.getActivePresentation().getSlides()[0];
 var placeholder = slide.getPlaceholder(SlidesApp.PlaceholderType.CENTERED_TITLE, 0);
 

Parameters

NameTypeDescription
placeholderTypePlaceholderType
placeholderIndexInteger

Return

PageElement


getPlaceholders()

Returns the list of placeholder PageElement objects in the page.

 var master = SlidesApp.getActivePresentation().getMasters()[0];
 Logger.log('Number of placeholders in the master: ' + master.getPlaceholders().length);
 

Return

PageElement[]


getShapes()

Returns the list of Shape objects on the page.

Return

Shape[]


getSheetsCharts()

Returns the list of SheetsChart objects on the page.

Return

SheetsChart[]


getTables()

Returns the list of Table objects on the page.

Return

Table[]


getVideos()

Returns the list of Video objects on the page.

Return

Video[]


getWordArts()

Returns the list of WordArt objects on the page.

Return

WordArt[]


insertImage(blobSource)

Inserts an image at the top left corner of the page with a default size from the specified image blob.

Inserting the image fetches it from the BlobSource once and a copy is stored for display inside the presentation. Images must be less than 50MB in size, cannot exceed 25 megapixels, and must be in either in PNG, JPEG, or GIF format.

 var slide = SlidesApp.getActivePresentation().getSlides()[0];
 // Get the Drive image file with the given ID.
 var image = DriveApp.getFileById(fileId);
 slide.insertImage(image);
 

Parameters

NameTypeDescription
blobSourceBlobSourceThe image data.

Return

Image — the inserted image


insertImage(blobSource, left, top, width, height)

Inserts an image on the page with the provided position and size from the specified image blob.

The image is fetched from the provided BlobSource once at insertion time and a copy is stored for display inside the presentation. Images must be less than 50MB in size, cannot exceed 25 megapixels, and must be in either in PNG, JPEG, or GIF format.

In order to maintain the image's aspect ratio, the image is scaled and centered with respect to the provided size.

 var slide = SlidesApp.getActivePresentation().getSlides()[0];
 // Get the Drive image file with the given ID.
 var image = DriveApp.getFileById(fileId);
 var position = {left: 0, top: 0};
 var size = {width: 300, height: 100};
 slide.insertImage(image, position.left, position.top, size.width, size.height);
 

Parameters

NameTypeDescription
blobSourceBlobSourceThe image data.
leftNumberThe horizontal position of the image in points, measured from the upper left corner of the page.
topNumberThe vertical position of the image in points, measured from the upper left corner of the page.
widthNumberThe width of the image in points.
heightNumberThe height of the image in points.

Return

Image — the inserted image


insertImage(imageUrl)

Inserts an image at the top left corner of the page with a default size from the provided URL.

Inserting the image fetches it from the URL once and a copy is stored for display inside the presentation. Images must be less than 50MB in size, cannot exceed 25 megapixels, and must be in either in PNG, JPEG, or GIF format.

The provided URL must be no larger than 2kB.

Parameters

NameTypeDescription
imageUrlStringThe image URL.

Return

Image — the inserted image


insertImage(imageUrl, left, top, width, height)

Inserts an image on the page with the provided position and size from the provided URL.

Inserting the image fetches it from the URL once and a copy is stored for display inside the presentation. Images must be less than 50MB in size, cannot exceed 25 megapixels, and must be in either in PNG, JPEG, or GIF format.

The provided URL must be no larger than 2kB.

In order to maintain the image's aspect ratio, the image is scaled and centered with respect to the provided size.

Parameters

NameTypeDescription
imageUrlStringThe image URL.
leftNumberThe horizontal position of the image in points, measured from the upper left corner of the page.
topNumberThe vertical position of the image in points, measured from the upper left corner of the page.
widthNumberThe width of the image in points.
heightNumberThe height of the image in points.

Return

Image — the inserted image


insertLine(lineCategory, startLeft, startTop, endLeft, endTop)

Inserts a line on the page.

 // Insert a line in the first slide of the presentation.
 var slide = SlidesApp.getActivePresentation().getSlides()[0];
 var startPoint = {left: 10, top: 10};
 var endPoint = {left: 40, top: 40};
 slide.insertLine(
     SlidesApp.LineCategory.STRAIGHT,
     startPoint.left,
     startPoint.top,
     endPoint.left,
     endPoint.top);
 

Parameters

NameTypeDescription
lineCategoryLineCategoryThe category of the line to insert.
startLeftNumberThe horizontal position of the start point of the line, measured in points from the upper left corner of the page.
startTopNumberThe vertical position of the start point of the line, measured in points from the upper left corner of the page.
endLeftNumberThe horizontal position of the end point of the line, measured in points from the upper left corner of the page.
endTopNumberThe vertical position of the end point of the line, measured in points from the upper left corner of the page.

Return

Line — the inserted line


insertShape(shapeType)

Inserts a shape on the page.

The shape is inserted with a default size at the top left corner of the page.

 // Insert a shape in the first slide of the presentation.
 var slide = SlidesApp.getActivePresentation().getSlides()[0];
 slide.insertShape(SlidesApp.ShapeType.RECTANGLE);
 

Parameters

NameTypeDescription
shapeTypeShapeTypeThe type of shape to insert.

Return

Shape — The inserted shape.


insertShape(shapeType, left, top, width, height)

Inserts a shape on the page.

Parameters

NameTypeDescription
shapeTypeShapeTypeThe type of shape to insert.
leftNumberThe horizontal position of the shape, measured from the upper left corner of the page.
topNumberThe vertical position of the shape, measured from the upper left corner of the page.
widthNumberThe width of the shape.
heightNumberThe height of the shape.

Return

Shape — the inserted shape


insertSheetsChart(sourceChart)

Inserts a Google Sheets chart on the page.

The chart is inserted with a default size at the top left corner of the page.

The inserted chart is linked with the source Google Sheets chart which allows it to be updated. Other collaborators can see the link to the source spreadsheet.

 var sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
 var chart = sheet.getCharts()[0];
 // Insert the spreadsheet chart in the first slide.
 var slide = SlidesApp.getActivePresentation().getSlides()[0];
 slide.insertSheetsChart(chart);
 

Parameters

NameTypeDescription
sourceChartEmbeddedChartThe chart in a spreadsheet to be inserted in the page.

Return

SheetsChart — the inserted chart in the page


insertSheetsChart(sourceChart, left, top, width, height)

Inserts a Google Sheets chart on the page with the provided position and size.

In order to maintain the chart's aspect ratio, the chart is scaled and centered with respect to the provided size.

The inserted chart is linked with the source Google Sheets chart which allows it to be updated. Other collaborators can see the link to the source spreadsheet.

 var sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
 var chart = sheet.getCharts()[0];
 // Insert the spreadsheet chart in the first slide.
 var slide = SlidesApp.getActivePresentation().getSlides()[0];
 var position = {left: 0, top: 0};
 var size = {width: 200, height: 200};
 slide.insertSheetsChart(
     chart,
     position.left,
     position.top,
     size.width,
     size.height);
 

Parameters

NameTypeDescription
sourceChartEmbeddedChartThe chart in a spreadsheet to be inserted in the page.
leftNumberThe horizontal position of the chart in points, measured from the upper left corner of the page.
topNumberThe vertical position of the chart in points, measured from the upper left corner of the page.
widthNumberThe width of the chart in points.
heightNumberThe height of the chart in points.

Return

SheetsChart — the inserted chart in the page


insertSheetsChartAsImage(sourceChart)

Inserts a Google Sheets chart as an Image on the page.

The image of the chart is inserted with a default size at the top left corner of the page.

The inserted image of chart is not linked with the source Google Sheets chart.

 var sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
 var chart = sheet.getCharts()[0];
 // Insert the spreadsheet chart in the first slide.
 var slide = SlidesApp.getActivePresentation().getSlides()[0];
 slide.insertSheetsChartAsImage(chart);
 

Parameters

NameTypeDescription
sourceChartEmbeddedChartThe chart in a spreadsheet to be inserted in the page.

Return

Image — the inserted image of the chart in the page


insertSheetsChartAsImage(sourceChart, left, top, width, height)

Inserts a Google Sheets chart as an Image on the page with the provided position and size.

In order to maintain the chart image's aspect ratio, the image is scaled and centered with respect to the provided size.

The inserted image of the chart is not linked with the source Google Sheets chart.

 var sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
 var chart = sheet.getCharts()[0];
 // Insert the spreadsheet chart in the first slide.
 var slide = SlidesApp.getActivePresentation().getSlides()[0];
 var position = {left: 0, top: 0};
 var size = {width: 200, height: 200};
 slide.insertSheetsChartAsImage(
     chart,
     position.left,
     position.right,
     size.width,
     size.height);
 

Parameters

NameTypeDescription
sourceChartEmbeddedChartThe chart in a spreadsheet to be inserted in the page.
leftNumberThe horizontal position of the chart in points, measured from the upper left corner of the page.
topNumberThe vertical position of the chart in points, measured from the upper left corner of the page.
widthNumberThe width of the chart in points.
heightNumberThe height of the chart in points.

Return

Image — the inserted image of the chart in the page


insertTable(numRows, numColumns)

Inserts a table on the page.

The table is centered on the page with default size and evenly distributed rows and columns.

Parameters

NameTypeDescription
numRowsIntegerThe number of rows in the table.
numColumnsIntegerThe number of columns in the table.

Return

Table — the inserted table


insertTable(numRows, numColumns, left, top, width, height)

Inserts a table on the page with the provided position and size.

Rows and columns are evenly distributed in the created table.

Parameters

NameTypeDescription
numRowsIntegerThe number of rows in the table.
numColumnsIntegerThe number of columns in the table.
leftNumberThe horizontal position of the table, measured from the upper left corner of the page.
topNumberThe vertical position of the table, measured from the upper left corner of the page.
widthNumberThe width of the table.
heightNumberThe minimum height of the table. The actual height of the rendered table depends on factors such as text font size.

Return

Table — the inserted table


insertVideo(videoUrl)

Inserts a video at the top left corner of the page with a default size.

Only YouTube videos are currently supported.

Parameters

NameTypeDescription
videoUrlStringThe URL of the video to insert.

Return

Video — the inserted video


insertVideo(videoUrl, left, top, width, height)

Inserts a video on the page with the provided position and size.

Only YouTube videos are currently supported.

Parameters

NameTypeDescription
videoUrlStringThe URL of the video to insert.
leftNumberThe horizontal position of the video in points, measured from the upper left corner of the page.
topNumberThe vertical position of the video in points, measured from the upper left corner of the page.
widthNumberThe width of the video in points.
heightNumberThe height of the video in points.

Return

Video — the inserted video


remove()

Removes the page.


replaceAllText(findText, replaceText)

Replaces all instances of text matching find text with replace text. The search is case insensitive.

Parameters

NameTypeDescription
findTextStringThe text to find.
replaceTextStringThe text to replace the matched text.

Return

Integer — the number of occurrences changed


replaceAllText(findText, replaceText, matchCase)

Replaces all instances of text matching find text with replace text.

Parameters

NameTypeDescription
findTextStringThe text to find.
replaceTextStringThe text to replace the matched text.
matchCaseBooleanIf true, the search is case sensitive; if false, the search is case insensitive.

Return

Integer — the number of occurrences changed


selectAsCurrentPage()

Selects the Page in the active presentation as the current page selection and removes any previous selection.

A script can only access the selection of the user who is running the script, and only if the script is bound to the presentation.

 // Select the first slide as the current page selection and replace any previous selection.
 var slide = SlidesApp.getActivePresentation().getSlides()[0];
 slide.selectAsCurrentPage();
 

发送以下问题的反馈:

此网页
Apps Script
Apps Script