当前位置:   article > 正文

wps-文档-js宏-批量修改表格格式_wps js宏官方文档

wps js宏官方文档

前言

由于需要修改word的表格的格式,一个一个的修改太慢了,所以需要通过宏的方式来修改,需要注意的是低版本可能没有JS宏…

开启JS宏

切换到工具–>点击开发工具
在这里插入图片描述
点击之后功能栏会变化成这样
在这里插入图片描述
选择WPS 宏编辑器
在这里插入图片描述
新增模块
在这里插入图片描述
然后开始编写代码即可

我的脚本

/**
 * 修改表格样式
 */
function 批量修改表格样式() {
  // 获取表格对象
  const table= ActiveDocument.Tables;
  // 循环所有表格数据
  for (let i = 1; i <= table.Count; i++) {
  
    // 根据窗口自动调整表格,这里的I 是表示第几个表格
    ActiveDocument.Tables.Item(i).AutoFitBehavior(wdAutoFitWindow);
    
    // 批量给表格加上线
    ((obj) => {
      ((obj) => {
        obj.LineStyle = wdLineStyleSingle;
        obj.LineWidth = wdLineWidth050pt;
        obj.Color = wdColorBlack;
      })(obj.Borders.Item(wdBorderTop));
      ((obj) => {
        obj.LineStyle = wdLineStyleSingle;
        obj.LineWidth = wdLineWidth050pt;
        obj.Color = wdColorBlack;
      })(obj.Borders.Item(wdBorderLeft));
      ((obj) => {
        obj.LineStyle = wdLineStyleSingle;
        obj.LineWidth = wdLineWidth050pt;
        obj.Color = wdColorBlack;
      })(obj.Borders.Item(wdBorderBottom));
      ((obj) => {
        obj.LineStyle = wdLineStyleSingle;
        obj.LineWidth = wdLineWidth050pt;
        obj.Color = wdColorBlack;
      })(obj.Borders.Item(wdBorderRight));
      ((obj) => {
        obj.LineStyle = wdLineStyleSingle;
        obj.LineWidth = wdLineWidth050pt;
        obj.Color = wdColorBlack;
      })(obj.Borders.Item(wdBorderHorizontal));
      ((obj) => {
        obj.LineStyle = wdLineStyleSingle;
        obj.LineWidth = wdLineWidth050pt;
        obj.Color = wdColorBlack;
      })(obj.Borders.Item(wdBorderVertical));
     // ,这里的I 是表示第几个表格
    })(ActiveDocument.Tables.Item(i));
  }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

参考API文档

https://open.wps.cn/previous/docs/client/wpsLoad

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/742173
推荐阅读
相关标签
  

闽ICP备14008679号