我正在创建表格加载项,以将名称标签从Google表格列表打印到Google幻灯片文档。一张幻灯片将包含名称标签和公司名称。创建幻灯片时,我无法插入标题。
var dataRangeNotation = 'Customers!A2:M6';
var values = SpreadsheetApp.openById('').getRange(dataRangeNotation).getValues();
var presentationId = ''
var requests = []
// For each record, create a new merged presentation.
for (var i = 0; i < values.length; ++i) {
var row = values[i];
var customerName = row[0]; // name in column 1
var customerCompany = row[1]; // company description in column 2
var pageId = Utilities.getUuid();
var bodyId = Utilities.getUuid();
var titleID = Utilities.getUuid();
requests.push({
'createSlide': {
'objectId': pageId,
'insertionIndex': 0,
'slideLayoutReference': {
'predefinedLayout': 'TITLE'
},
"placeholderIdMappings": [
{
"layoutPlaceholder": {
"type": "TITLE",
"index": 0
},
"objectId": titleID,
},
{
"layoutPlaceholder": {
"type": "BODY",
"index": 0
},
"objectId": bodyId,
},
],
},
{
"insertText": {
"objectId": titleID,
"text": "This is my slide title",
},
},
});
},
var slide =
Slides.Presentations.batchUpdate({'requests': requests}, presentationId);
Logger.log('Created Slide with ID: ' + slide.replies[0].createSlide.objectId);
布局placeholerIdMappings不起作用。我不想创建幻灯片,然后循环播放幻灯片以更改幻灯片标题。寻找已插入到请求中的方法。
答案 0 :(得分:0)
var dataRangeNotation = 'Customers!A2:M6';
var values = SpreadsheetApp.openById('ss').getRange(dataRangeNotation).getValues();
var presentationId = 'xxx'
var requests = []
// For each record, create a new merged presentation.
for (var i = 0; i < values.length; ++i) {
var pageId = Utilities.getUuid();
var bodyId = Utilities.getUuid();
var subtitleID = Utilities.getUuid();
requests.push(
{
"createSlide": {
"objectId": pageId,
"slideLayoutReference": {
'predefinedLayout': 'TITLE'
},
}
});
}
var slide =
Slides.Presentations.batchUpdate({'requests': requests}, presentationId);
Logger.log('Created Slide with ID: ' + slide.replies[0].createSlide.objectId);
var preso = SlidesApp.openById(presentationId);
for (var i = 0; i < values.length; ++i) {
var row = values[i];
var customerName = row[0]; // name in column 1
var customerCompany = row[1];// case description in column 2
var [title, subtitle] = preso.getSlides()[i].getPageElements();
title.asShape().getText().setText(customerName);
subtitle.asShape().getText().setText(customerCompany);
}
此循环可以解决问题,但由于api限制,不适用于大型更新。