【发布时间】:2025-12-06 17:25:01
【问题描述】:
我正在从 Google 表格中提取数据,以便从模板创建新的 Google 幻灯片。一切正常,但是一旦我用电子表格数据替换了模板变量,我就无法弄清楚如何将文本作为链接点击。
如何将我的网站变量 company_website 替换为网站链接并使其可点击?
function createSlidesfromSheets() {
var dataSpreadsheetUrl = "https://docs.google.com/spreadsheets/d/xxxxxlink/edit"; //make sure this includes the '/edit at the end
var ss = SpreadsheetApp.openByUrl(dataSpreadsheetUrl);
var deck = SlidesApp.getActivePresentation();
var sheet = ss.getSheetByName('Sheet1'); // this needs to be the name of the sheet/feuille
var values = sheet.getRange('A2:M20').getValues(); //this is the range of data to create the slides from.
//Logger.log(values);
var slides = deck.getSlides();
var templateSlideOne = slides[0];
var templateSlideTwo = slides[1];
var presLength = slides.length;
values.forEach(function(page){
if(page[0]){
var company_name = page[0];
var company_country = page[1];
var company_city = page[2];
var company_website = page[3];
var company_description = page[4];
templateSlideOne.duplicate(); //duplicate the first template slide
templateSlideTwo.duplicate(); //duplicate the second template slide
slides = deck.getSlides(); //update the slides array for indexes and length
newSlideOne = slides[1]; // declare the copy to update of the first template slide (right after the first template's slide)
newSlideTwo = slides[3]; // declare the copy to update of the second template slide (right after the second template's slide)
var firstShapes = (newSlideOne.getShapes());
firstShapes.forEach(function(shape){
shape.getText().replaceAllText('{{company-name}}',company_name);
shape.getText().replaceAllText('{{company-city}}',company_city);
shape.getText().replaceAllText('{{company-country}}',company_country);
shape.getText().replaceAllText('{{company-website}}',company_website);
// how do I use setLinkUrl() to make the new company_website text a clickable link?
});
var secondShapes = (newSlideTwo.getShapes());
secondShapes.forEach(function(shape){
shape.getText().replaceAllText('{{company-name}}',company_name);
shape.getText().replaceAllText('{{company-description}}',company_description);
});
presLength = slides.length;
newSlideOne.move(presLength);
presLength = slides.length;
newSlideTwo.move(presLength);
} // end our conditional statement
}); //close our loop of values
}
【问题讨论】:
标签: google-apps-script google-sheets google-slides