You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 22:48:11