使用Apps Script修改Google Slides线条宽度时遇代码异常
解决Google Slides脚本中setWeight报错问题
错误原因:
getWeight()方法返回的是线条宽度的数值(比如你获取到的0.75),而setWeight()是Line对象的专属方法,不能在数值类型上调用该方法,因此触发.setWeight is not a function错误。正确代码示例:
直接获取Line对象后调用setWeight方法即可:SlidesApp.getActivePresentation().getPageElementById('g2b1b713b937_0_0').asLine().setWeight(2);如果需要基于当前宽度调整:
const lineElement = SlidesApp.getActivePresentation().getPageElementById('g2b1b713b937_0_0').asLine(); const currentWeight = lineElement.getWeight(); lineElement.setWeight(currentWeight + 1.25); // 在原有0.75基础上调整为2
内容的提问来源于stack exchange,提问作者Colin Wood
相关产品推荐
相关产品推荐

