惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
量子位
大猫的无限游戏
大猫的无限游戏
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
Google DeepMind News
Google DeepMind News
小众软件
小众软件
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
雷峰网
雷峰网
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 莫小龙

geoserver之强制配置OnlineResource mysql之将shp转化为wkt,然后存储再geomerty字段内 cesium之用着色器添加建筑贴图 uniapp之plus.downloader.createDownload下载文件传参 谷歌之将网页保存为图片 elementui之table中相同数据的单元格合并 krpano之使用教程 threejs之灯光不跟随OrbitControls控制器旋转 threejs之将张纹理图片组成材质组 canvas之修改Base64图片中不透明部分的颜色 threejs之将PlaneGeometry转换为BufferGeometry threejs之利用shape通过线绘制面和体 threejs之添加渐变背景 threejs之创建发光墙体 paperjs之fitBounds适应区域前后屏幕坐标和输入坐标的转换 arcmap之通过点数据获取等值线 uniapp之安卓APP打开百度地图、高德地图APP openlayer之添加带箭头的线 geoserver之图片图标样式 SHP转WKT文件工具 openlayers之geoserver的wms图层mysql数据源数据修改后更新问题 通过日照时数计算每天RAD(太阳辐射)值 Uniapp之安卓签名证书(.keystore)生成
wps之使用宏修改全篇表格样式
莫小龙 · 2026-08-14 · via 博客园 - 莫小龙

wps之使用宏修改全篇表格样式

宏使用步骤:

1.【工具】》【开发工具】

image

2.运行宏

image

 3.创建宏

image

 4.编辑宏

image

 5.编辑后不用保存,直接关闭编辑页面

6.运行宏

image

注意事项:

保存文档前需要删除或者保存宏

JS宏代码:

1.修改表格和表头底色

/**
 * 修改表格样式 Macro
 */
function FormatAllTableHeader() {
    const doc = Application.ActiveDocument;
    const tables = doc.Tables;
    const total = tables.Count;

    if (total === 0) {
        alert("文档内没有表格");
        return;
    }

    // 表头蓝色
    const headerCellBg = RGB(31, 78, 121);
    const headerFontColor = wdColorWhite;
    const contentCellBg = wdColorWhite;
    const contentFontColor = wdColorBlack;

    let successNum = 0;

    for (let t = 1; t <= total; t++) {
        try {
            const tbl = tables.Item(t);
            const rowTotal = tbl.Rows.Count;
            if (rowTotal < 1) continue;

            // ========== 表头:第1行单元格 ==========
            const headRow = tbl.Rows.Item(1);
            const cellNumHead = headRow.Cells.Count;
            for (let c = 1; c <= cellNumHead; c++) {
                const cell = headRow.Cells.Item(c);
                // 设置【单元格底纹】整格填充
                cell.Shading.BackgroundPatternColor = headerCellBg;
                // 设置文字颜色
                cell.Range.Font.Color = headerFontColor;
            }

            // ========== 内容行:第2行至最后 ==========
            for (let r = 2; r <= rowTotal; r++) {
                const dataRow = tbl.Rows.Item(r);
                const cellNum = dataRow.Cells.Count;
                for (let c = 1; c <= cellNum; c++) {
                    const cell = dataRow.Cells.Item(c);
                    // 单元格底色白色
                    cell.Shading.BackgroundPatternColor = contentCellBg;
                    // 文字黑色
                    cell.Range.Font.Color = contentFontColor;
                }
            }
            successNum++;
        } catch (e) {
            console.log(`第${t}个表格异常:` + e.message);
        }
    }

    alert(`处理完成!\n总计表格:${total} 个\n成功处理:${successNum} 个`);
}

2.修改表格边框

function SetAllTableGrayBorder() {
    const doc = Application.ActiveDocument;
    const tables = doc.Tables;
    const total = tables.Count;

    if (total === 0) {
        alert("文档内没有表格");
        return;
    }

    // 灰色,可自行修改RGB数值
    const borderColor = RGB(128, 128, 128);
    let successNum = 0;

    // 边框类型:上下左右 + 内部横线 + 内部竖线
    const borderIds = [-1, -2, -3, -4, -5, -6];

    for (let t = 1; t <= total; t++) {
        try {
            const tbl = tables.Item(t);
            tbl.Borders.Enable = true;

            for (let i = 0; i < borderIds.length; i++) {
                const b = tbl.Borders.Item(borderIds[i]);
                b.LineStyle = wdLineStyleSingle;   // 实线
                b.LineWidth = wdLineWidth050pt;    // 0.5磅
                b.Color = borderColor;             // 灰色
            }
            successNum++;
        } catch (e) {
            console.log("第" + t + "个表格边框异常:" + e.message);
        }
    }

    alert("边框处理完成!\n总计表格:" + total + " 个\n成功:" + successNum + " 个");
}

3.表格首列加粗

function BoldFirstColumn() {
    const doc = Application.ActiveDocument;
    const tables = doc.Tables;
    const total = tables.Count;

    if (total === 0) {
        alert("文档内没有表格");
        return;
    }

    let successNum = 0;

    for (let t = 1; t <= total; t++) {
        try {
            const tbl = tables.Item(t);
            const rowTotal = tbl.Rows.Count;

            // 遍历每一行,将第一列单元格文字加粗
            for (let r = 1; r <= rowTotal; r++) {
                const row = tbl.Rows.Item(r);
                if (row.Cells.Count >= 1) {
                    row.Cells.Item(1).Range.Font.Bold = true;
                }
            }
            successNum++;
        } catch (e) {
            console.log("第" + t + "个表格异常:" + e.message);
        }
    }

    alert("第一列加粗完成!\n总计表格:" + total + " 个\n成功:" + successNum + " 个");
}

  宏代码可AI生成

钻研不易,转载请注明出处。。。。。。