由于需要修改word的表格的格式,一个一个的修改太慢了,所以需要通过宏的方式来修改,需要注意的是低版本可能没有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));
}
}
https://open.wps.cn/previous/docs/client/wpsLoad