WPS宏全文修改表格样式

  1. 打开开发工具

image

  1. 打开宏编辑器

image

  1. 输入代码(需确保预先创建了两个样式)

image

function tableLineStyle() {
	var count = ActiveDocument.Tables.Count;
	// 跳过封面的表格
	for(i = 4; i <= count; i++) {
		var table = ActiveDocument.Tables.Item(i);
		// 宽度
		table.PreferredWidthType = wdPreferredWidthPercent;
		table.PreferredWidth = 100;
		// 外边框
		table.Borders.OutsideLineStyle = wdLineStyleSingle;
		table.Borders.OutsideLineWidth = wdLineWidth100pt;
		// 内边框
		table.Borders.InsideLineStyle = wdLineStyleSingle;
		table.Borders.InsideLineWidth = wdLineWidth100pt;		
		// 正文样式
		Selection.SetRange(table.Range.Start, table.Range.End);
		Selection.Style = "表格-正文-宋体五号单倍行距";
		// 表头样式
		if (table.Rows.Count > 1) {
			var FirstRow = table.Rows.First;
			Selection.SetRange(FirstRow.Range.Start, FirstRow.Range.End);
			Selection.Style = "表格-表头-宋体五号单倍行距";
		}
	}
}

  1. 运行宏

image

posted @ 2025-07-15 20:00  HiroSyu  阅读(96)  评论(0)    收藏  举报