WPS生成工资条,JSA宏模板!
▼ 动画演示



/** 功能:将工资汇总表自动转换为工资条格式*/function 工资条自动生成() {const ws = ActiveSheet;const dataRange = ws.Range("A1").CurrentRegion;const totalRows = dataRange.Rows.Count;const totalCols = dataRange.Columns.Count;if (totalRows < 3) {MsgBox("数据不足!\n需要至少1行表头 + 2行数据才能生成工资条。", 48, "提示");return;}const confirm = MsgBox("即将为 " + (totalRows - 1) + " 名员工生成工资条\n\n⚠" +"操作不可撤销,建议先备份文件\n\n是否继续?",36,"确认生成");if (confirm !== 6) return; // 用户点击"否"Application.ScreenUpdating = false;// 获取表头行范围(第1行)const headerRange = ws.Rows(1);// 从最后一条数据往前处理(避免插入行导致行号错位)for (let i = totalRows; i >= 3; i--) {ws.Rows(i).Insert(xlShiftDown); // 插入空行(分隔用)ws.Rows(i).Insert(xlShiftDown); // 再插入一行放表头headerRange.Copy(ws.Rows(i)); // 复制表头到插入的行}// 自动调整列宽const lastCol = String.fromCharCode(64 + totalCols);ws.Range("A1:" + lastCol + "1").Columns.AutoFit();Application.ScreenUpdating = true;MsgBox("工资条生成完成!\n共生成 " + (totalRows - 1) + " 张工资条",64,"完成");}
夜雨聆风