我是Google脚本新手。我有一个项目,将数据从谷歌表合并到谷歌幻灯片。我需要创建一张幻灯片,其中所有数据都合并到一个文件幻灯片中。我有谷歌许多解决方案,但似乎无法正常工作。 即使我有10个数据,但只有第一个数据才合并到第一张幻灯片中。 请帮助
这是我的代码:
function slidemerge()
{
// Use the Sheets API to load data, one record per row.
var srcSlideId = 'id';
var values = SpreadsheetApp.openById('ssid').getDataRange().getValues();
var copysrcSlideIndex = 1; // 0 means page 1.
var copydstSlideIndex = 2; // 0 means page 1.
// Duplicate the template presentation using the Drive API.
var copyTitle = 'Report'+ Utilities.formatDate(new Date(), "GMT+8", "dd-MMM-yyyy");
var copyFile = {
title: copyTitle,
parents: [{id: 'root'}]
};
copyFile = Drive.Files.copy(copyFile, srcSlideId);
var presentationCopyId = copyFile.id;
var src = SlidesApp.openById(presentationCopyId).getSlides()
[copysrcSlideIndex];
// For each record, create a new merged presentation.
for (var i = 1; i < values.length; ++i) {
var row = values[i];
var pid=row[9];
var customerName = row[10];
var slip=row[11];
var dupslideid=SlidesApp.openById(presentationCopyId).insertSlide(copydstSlideIndex, src);
// Create the text merge (replaceAllText) requests for this presentation.
requests = [{
replaceAllText: {
pageObjectIds: src[dupslideid.getObjectId()],
containsText: {
text: '{{ID}}',
matchCase: true
},
replaceText: pid,
}
},{
replaceAllText: {
containsText: {
text: '{{Name}}',
matchCase: true
},
replaceText: customerName
}
},{
replaceAllShapesWithImage: {
imageUrl: slip,
replaceMethod: 'CENTER_INSIDE',
containsText: {
text: '{{Slip}}',
matchCase: true
}
}
}];
// Execute the requests for this presentation.
var result = Slides.Presentations.batchUpdate({
requests: requests
}, presentationCopyId);
}
}