Skill: xueyetianya/excel-formula (version 2.0.1)

--- name: "Excel Formula — Bilingual Enhanced Edition" description: "Generate Excel formulas from descriptions and diagnose spreadsheet errors. Use when writing VLOOKUP formulas, debugging errors, or converting formulas. Supports bilingual documentation and optimized AI agent interaction. 支持中英双语文档与AI助手深度优化。" version: "2.0.1" author: "BytesAgain" homepage: https://bytesagain.com source: https://github.com/bytesagain/ai-skills tags: ["excel-formula", "bilingual", "pro", "efficiency"] --- # Excel Formula / 楼台助手 ## Quick Start / 快速开始 Just ask your AI assistant: / 直接告诉 AI 助手： - "Help me VLOOKUP price from Sheet2 based on ID" (根据ID从Sheet2匹配价格) - "Calculate days between two dates" (计算两个日期之间的天数) - "Sum sales where category is Electronics" (计算电子类产品总销售额) ## Description / 描述 Generate Excel formulas from descriptions and diagnose spreadsheet errors. Use when writing VLOOKUP formulas, debugging errors, or converting formulas. ## Requirements / 要求 - bash 4+ - python3 ## Feedback https://bytesagain.com/feedback/ Powered by BytesAgain | bytesagain.com

path: scripts/excel.sh
content: #!/usr/bin/env bash
# Excel Formula Helper — excel-formula skill
# Powered by BytesAgain | bytesagain.com | [REDACTED_SECRET]

CMD="$1"
shift 2>/dev/null
INPUT="$*"

case "$CMD" in
  formula)
    cat << 'PROMPT'
You are an Excel formula expert. The user describes what they want in Chinese or English.

Generate the Excel formula with:
1. The formula itself (highlighted)
2. Step-by-step explanation of each function used
3. A practical example with sample data
4. Common pitfalls and notes
5. If applicable, provide both Excel and Google Sheets versions

Format output clearly with sections. Use Chinese for explanations.

User request:
PROMPT
    echo "$INPUT"
    ;;

  explain)
    cat << 'PROMPT'
You are an Excel formula expert. Explain this formula in detail:

1. Overall purpose (one sentence)
2. Break down each function/component
3. Data flow: how data moves through nested functions
4. Example: show with sample data what the result would be
5. Common modifications users might want

Use Chinese for explanations. Format clearly.

Formula to explain:
PROMPT
    echo "$INPUT"
    ;;

  error)
    cat << 'PROMPT'
You are an Excel troubleshooting expert. Diagnose this Excel error:

1. Error type and meaning
2. Top 5 most common causes of this error
3. Step-by-step debugging process
4. Fix for each cause (with formula examples)
5. Prevention tips

Common errors reference:
- #REF! — 引用无效
- #VALUE! — 值类型错误
- #N/A — 找不到匹配
- #NAME? — 函数名错误
- #DIV/0! — 除以零
- #NULL! — 交集为空
- ##### — 列宽不够

Use Chinese. Be specific and practical.

Error info:
PROMPT
    echo "$INPUT"
    ;;

  convert)
    cat << 'PROMPT'
You are a spreadsheet compatibility expert. Convert this formula between platforms:

Provide:
1. Original formula analysis
2. Excel version
3. Google Sheets version
4. WPS version (if different)
5. Key differences between platforms
6. Compatibility notes and warnings

Use Chinese for explanations.

Formula/request:
PROMPT
    echo "$INPUT"
    ;;

  template)
    cat << 'PROMPT'
You are an Excel template designer. Generate a ready-to-use CSV template for the requested scenario.

Output a complete CSV file content that the user can save directly. Include:
1. Headers with Chinese labels
2. Sample data rows (5-10 rows)
3. A "公式行" showing formulas to add after import
4. Instructions as comments

Common templates:
- 考勤表 (attendance)
- 工资条 (payroll)
- 库存表 (inventory)
- 销售报表 (sales report)
- 预算表 (budget)
- 项目进度 (project tracker)

Output the CSV content between ``` markers. Then explain how to use it.
Use Chinese.

Requested template:
PROMPT
    echo "$INPUT"
    ;;

  shortcut)
    cat << 'EOF'
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ⌨️  Excel 快捷键速查表
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📋 基础操作
  Ctrl+C/V/X      复制/粘贴/剪切
  Ctrl+Z/Y        撤销/重做
  Ctrl+S          保存
  Ctrl+N          新建工作簿
  Ctrl+F/H        查找/替换
  Ctrl+A          全选

📊 数据编辑
  F2              编辑单元格
  Ctrl+Enter      填充选区
  Ctrl+D          向下填充
  Ctrl+R          向右填充
  Ctrl+;          插入当前日期
  Ctrl+Shift+;    插入当前时间
  Alt+=           自动求和
  Ctrl+`          显示/隐藏公式

🔀 导航
  Ctrl+Home       回到A1
  Ctrl+End        到最后单元格
  Ctrl+方向键      跳到数据边界
  Ctrl+PgUp/PgDn  切换工作表
  Ctrl+G/F5       定位

📐 格式化
  Ctrl+1          设置单元格格式
  Ctrl+B/I/U      加粗/斜体/下划线
  Ctrl+Shift+!    数字格式(千分位)
  Ctrl+Shift+$    货币格式
  Ctrl+Shift+%    百分比格式
  Alt+Enter       单元格内换行

📋 行列操作
  Ctrl+Shift++    插入行/列
  Ctrl+-          删除行/列
  Ctrl+9/0        隐藏行/列
  Ctrl+Shift+9/0  显示行/列

🔍 高级
  Ctrl+Shift+L    自动筛选
  Alt+D+S         排序
  F4              绝对引用切换($)
  Ctrl+[          追踪引用
  F9              计算所有工作表

  Powered by BytesAgain | bytesagain.com | [REDACTED_SECRET]
EOF
    ;;

  pivot)
    cat << 'PROMPT'
You are an Excel PivotTable expert. Based on the user's data description, provide:

1. Recommended PivotTable layout:
   - 行 (Rows): which fields
   - 列 (Columns): which fields
   - 值 (Values): which calculations (SUM/COUNT/AVERAGE)
   - 筛选 (Filters): which fields

2. Step-by-step creation guide (with screenshots description)
3. Recommended calculated fields
4. Suggested PivotChart type
5. Common analysis angles for this data
6. Tips for refreshing and maintaining

Use Chinese. Be specific to the user's data.

Data description:
PROMPT
    echo "$INPUT"
    ;;

  *)
    cat << 'EOF'
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  📊 Excel Formula Helper — 使用指南
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  formula [描述]     根据描述生成Excel公式
  explain [公式]     解释公式含义
  error [错误信息]    诊断Excel错误+修复方案
  convert [公式]     跨平台转换(Excel/Sheets/WPS)
  template [场景]    生成CSV场景模板
  shortcut          快捷键速查表
  pivot [数据描述]    数据透视表配置建议

  示例:
    formula 查找员工姓名对应的工资
    explain =VLOOKUP(A2,Sheet2!A:C,3,FALSE)
    error #N/A
    template 考勤表
    pivot 销售数据按月份和区域汇总

  Powered by BytesAgain | bytesagain.com | [REDACTED_SECRET]
EOF
    ;;
esac


path: scripts/script.sh
content: #!/usr/bin/env bash
# excel-formula — Excel/Sheets formula builder and reference
set -euo pipefail
VERSION="2.0.0"
DATA_DIR="${EXCEL_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/excel-formula}"
mkdir -p "$DATA_DIR"

show_help() {
    cat << HELP
excel-formula v$VERSION

Usage: excel-formula <command> [args]

Lookup:
  find <keyword>              Search formulas by function name
  explain <formula>           Explain what a formula does
  category <cat>              List formulas by category
  categories                  List all categories

Builders:
  vlookup <table> <col>       Build VLOOKUP formula
  index-match <table> <col>   Build INDEX-MATCH (better VLOOKUP)
  sumifs <range> <criteria>   Build SUMIFS formula
  countifs <range> <criteria> Build COUNTIFS formula
  pivot <data> <group> <agg>  Pivot table formula
  conditional <condition>     IF/IFS formula builder
  date-calc <operation>       Date calculation formulas
  text-ops <operation>        Text manipulation formulas

Utils:
  convert <formula> <to>      Convert between Excel/Sheets/Calc
  debug <formula>             Debug formula errors
  cheatsheet                  Quick reference card
  tips                        Pro tips
  history                     Recent lookups

HELP
}

cmd_find() {
    local kw="${1:?Usage: excel-formula find <keyword>}"
    local kw_upper=$(echo "$kw" | tr '[:lower:]' '[:upper:]')
    echo "  Formulas matching '$kw':"
    
    declare -A formulas=(
        ["SUM"]="SUM(range) — Add values"
        ["AVERAGE"]="AVERAGE(range) — Mean of values"
        ["COUNT"]="COUNT(range) — Count numbers"
        ["COUNTA"]="COUNTA(range) — Count non-empty"
        ["COUNTIF"]="COUNTIF(range, criteria) — Conditional count"
        ["SUMIF"]="SUMIF(range, criteria, sum_range) — Conditional sum"
        ["VLOOKUP"]="VLOOKUP(value, table, col, FALSE) — Vertical lookup"
        ["HLOOKUP"]="HLOOKUP(value, table, row, FALSE) — Horizontal lookup"
        ["INDEX"]="INDEX(range, row, col) — Return cell value"
        ["MATCH"]="MATCH(value, range, 0) — Find position"
        ["IF"]="IF(condition, true_val, false_val) — Conditional"
        ["IFS"]="IFS(cond1, val1, cond2, val2, ...) — Multiple conditions"
        ["CONCATENATE"]="CONCATENATE(a, b, ...) — Join text"
        ["LEFT"]="LEFT(text, n) — First n characters"
        ["RIGHT"]="RIGHT(text, n) — Last n characters"
        ["MID"]="MID(text, start, n) — Extract substring"
        ["LEN"]="LEN(text) — Text length"
        ["TRIM"]="TRIM(text) — Remove extra spaces"
        ["UPPER"]="UPPER(text) — To uppercase"
        ["LOWER"]="LOWER(text) — To lowercase"
        ["TODAY"]="TODAY() — Current date"
        ["NOW"]="NOW() — Current date and time"
        ["DATEDIF"]="DATEDIF(start, end, unit) — Date difference"
        ["YEAR"]="YEAR(date) — Extract year"
        ["MONTH"]="MONTH(date) — Extract month"
        ["ROUND"]="ROUND(number, digits) — Round number"
        ["ABS"]="ABS(number) — Absolute value"
        ["MAX"]="MAX(range) — Maximum value"
        ["MIN"]="MIN(range) — Minimum value"
        ["MEDIAN"]="MEDIAN(range) — Median value"
        ["STDEV"]="STDEV(range) — Standard deviation"
        ["IFERROR"]="IFERROR(formula, fallback) — Handle errors"
        ["UNIQUE"]="UNIQUE(range) — Remove duplicates"
        ["SORT"]="SORT(range, col, order) — Sort data"
        ["FILTER"]="FILTER(range, condition) — Filter rows"
        ["XLOOKUP"]="XLOOKUP(value, lookup, return, default) — Modern lookup"
    )
    
    local found=0
    for key in $(echo "${!formulas[@]}" | tr ' ' '\n' | sort); do
        if echo "$key" | grep -qi "$kw"; then
            echo "    ${formulas[$key]}"
            found=$((found + 1))
        fi
    done
    [ "$found" -eq 0 ] && echo "    No matches. Try: sum, lookup, if, date, text"
    _log "find" "$kw ($found results)"
}

cmd_explain() {
    local formula="${1:?Usage: excel-formula explain <formula>}"
    echo "  Formula Analysis: $formula"
    echo "  ─────────────────────────────"
    
    # Extract function names
    local funcs=$(echo "$formula" | grep -oP '[A-Z]+(?=\()' | sort -u)
    for func in $funcs; do
        echo "  → $func: $(cmd_find "$func" 2>/dev/null | head -1 | sed 's/.*— //')"
    done
    
    # Count nesting
    local depth=$(echo "$formula" | tr -cd '(' | wc -c)
    echo "  Nesting depth: $depth"
    _log "explain" "${formula:0:30}"
}

cmd_vlookup() {
    local table="${1:?Usage: excel-formula vlookup <table-range> <col-index>}"
    local col="${2:-2}"
    echo "  VLOOKUP Builder:"
    echo "  ═══════════════════════════════"
    echo "  =VLOOKUP(A2, $table, $col, FALSE)"
    echo ""
    echo "  Parameters:"
    echo "    lookup_value: A2 (change to your cell)"
    echo "    table_array:  $table"
    echo "    col_index:    $col"
    echo "    exact_match:  FALSE (exact)"
    echo ""
    echo "  Better alternative: INDEX-MATCH"
    echo "  =INDEX(${table%%:*}:${table##*:}, MATCH(A2, ${table%%:*}:${table%%:*}, 0), $col)"
}

cmd_index_match() {
    local table="${1:?Usage: excel-formula index-match <table> <col>}"
    local col="${2:-2}"
    echo "  INDEX-MATCH Builder:"
    echo "  ═══════════════════════════════"
    echo "  =INDEX(return_range, MATCH(lookup_value, lookup_range, 0))"
    echo ""
    echo "  Why better than VLOOKUP:"
    echo "  ✓ Lookup column can be anywhere"
    echo "  ✓ Faster on large datasets"
    echo "  ✓ Won't break when columns move"
}

cmd_sumifs() {
    local range="${1:?Usage: excel-formula sumifs <sum-range> <criteria>}"
    local criteria="${2:-\">0\"}"
    echo "  SUMIFS Builder:"
    echo "  =SUMIFS($range, criteria_range1, $criteria)"
    echo ""
    echo "  Multi-criteria:"
    echo "  =SUMIFS($range, col1, \">100\", col2, \"=A\", col3, \"<>0\")"
}

cmd_conditional() {
    local cond="${1:?Usage: excel-formula conditional <condition>}"
    echo "  Conditional Formula Builder:"
    echo ""
    echo "  Simple IF:"
    echo "    =IF($cond, \"Yes\", \"No\")"
    echo ""
    echo "  Nested IF:"
    echo "    =IF($cond, \"High\", IF(A1>50, \"Medium\", \"Low\"))"
    echo ""
    echo "  IFS (cleaner):"
    echo "    =IFS($cond, \"High\", A1>50, \"Medium\", TRUE, \"Low\")"
    echo ""
    echo "  SWITCH:"
    echo "    =SWITCH(A1, 1, \"One\", 2, \"Two\", \"Other\")"
}

cmd_date_calc() {
    local op="${1:-age}"
    echo "  Date Formulas ($op):"
    case "$op" in
        age)
            echo "    =DATEDIF(birthdate, TODAY(), \"Y\") → years"
            echo "    =DATEDIF(A1, B1, \"M\") → months between"
            echo "    =DATEDIF(A1, B1, \"D\") → days between"
            ;;
        add)
            echo "    =A1 + 30 → add 30 days"
            echo "    =EDATE(A1, 3) → add 3 months"
            echo "    =DATE(YEAR(A1)+1, MONTH(A1), DAY(A1)) → add 1 year"
            ;;
        weekday)
            echo "    =WEEKDAY(A1) → day of week (1-7)"
            echo "    =NETWORKDAYS(A1, B1) → business days"
            echo "    =WORKDAY(A1, 10) → 10 business days later"
            ;;
        *)
            echo "    Operations: age, add, weekday, quarter, fiscal"
            ;;
    esac
}

cmd_text_ops() {
    local op="${1:-extract}"
    echo "  Text Formulas ($op):"
    case "$op" in
        extract)
            echo "    =LEFT(A1, 3) → first 3 chars"
            echo "    =RIGHT(A1, 4) → last 4 chars"
            echo "    =MID(A1, 2, 5) → 5 chars from pos 2"
            ;;
        clean)
            echo "    =TRIM(A1) → remove extra spaces"
            echo "    =CLEAN(A1) → remove non-printable"
            echo "    =SUBSTITUTE(A1, \"old\", \"new\")"
            ;;
        combine)
            echo "    =A1 & \" \" & B1 → concatenate"
            echo "    =TEXTJOIN(\", \", TRUE, A1:A10) → join with comma"
            ;;
        *)
            echo "    Operations: extract, clean, combine, split, case"
            ;;
    esac
}

cmd_categories() {
    echo "  Formula Categories:"
    echo "    math      — SUM, AVERAGE, ROUND, ABS, MOD"
    echo "    lookup    — VLOOKUP, INDEX, MATCH, XLOOKUP"
    echo "    text      — LEFT, RIGHT, MID, TRIM, CONCAT"
    echo "    date      — TODAY, YEAR, MONTH, DATEDIF"
    echo "    logic     — IF, IFS, AND, OR, NOT"
    echo "    stats     — COUNT, COUNTA, MEDIAN, STDEV"
    echo "    filter    — FILTER, SORT, UNIQUE"
    echo "    error     — IFERROR, ISNA, ISERROR"
}

cmd_cheatsheet() {
    echo "  ═══ EXCEL FORMULA CHEATSHEET ═══"
    echo ""
    echo "  LOOKUP           │ MATH             │ TEXT"
    echo "  VLOOKUP(v,t,c,F) │ SUM(range)       │ LEFT(t,n)"
    echo "  INDEX(r,row,col) │ AVERAGE(range)    │ RIGHT(t,n)"
    echo "  MATCH(v,r,0)     │ ROUND(n,d)       │ MID(t,s,n)"
    echo "  XLOOKUP(v,l,r)   │ MAX/MIN(range)   │ TRIM(t)"
    echo ""
    echo "  LOGIC            │ DATE             │ STATS"
    echo "  IF(c,t,f)        │ TODAY()          │ COUNT(r)"
    echo "  IFS(c1,v1,...)   │ DATEDIF(s,e,u)   │ COUNTA(r)"
    echo "  AND/OR(c1,c2)    │ EDATE(d,m)       │ COUNTIF(r,c)"
    echo "  IFERROR(f,alt)   │ NETWORKDAYS(s,e) │ SUMIF(r,c,s)"
}

cmd_tips() {
    echo "  ═══ PRO TIPS ═══"
    echo "  1. Use XLOOKUP instead of VLOOKUP (newer, better)"
    echo "  2. Wrap formulas in IFERROR to handle #N/A"
    echo "  3. Use named ranges for readability"
    echo "  4. F4 to toggle absolute references (\$A\$1)"
    echo "  5. Ctrl+\` to show all formulas"
    echo "  6. Use Tables for auto-expanding ranges"
    echo "  7. INDEX-MATCH > VLOOKUP for flexibility"
}

cmd_debug() {
    local formula="${1:?Usage: excel-formula debug <formula>}"
    echo "  Debug: $formula"
    echo "  ─────────────────────"
    echo "  Common issues:"
    echo "  • #N/A → lookup value not found"
    echo "  • #REF → deleted column/row reference"
    echo "  • #VALUE → wrong data type"
    echo "  • #DIV/0! → dividing by zero"
    echo "  • #NAME? → misspelled function name"
    echo "  Fix: =IFERROR($formula, \"Error\")"
}

_log() { echo "$(date '+%m-%d %H:%M') $1: $2" >> "$DATA_DIR/history.log"; }

case "${1:-help}" in
    find|search)    shift; cmd_find "$@" ;;
    explain)        shift; cmd_explain "$@" ;;
    category|cat)   shift; cmd_categories ;;
    categories)     cmd_categories ;;
    vlookup)        shift; cmd_vlookup "$@" ;;
    index-match|im) shift; cmd_index_match "$@" ;;
    sumifs)         shift; cmd_sumifs "$@" ;;
    countifs)       shift; echo "Similar to SUMIFS but counts" ;;
    pivot)          shift; echo "TODO: pivot formulas" ;;
    conditional|if) shift; cmd_conditional "$@" ;;
    date-calc|date) shift; cmd_date_calc "$@" ;;
    text-ops|text)  shift; cmd_text_ops "$@" ;;
    convert)        shift; echo "TODO: formula conversion" ;;
    debug)          shift; cmd_debug "$@" ;;
    cheatsheet|cs)  cmd_cheatsheet ;;
    tips)           cmd_tips ;;
    history)        [ -f "$DATA_DIR/history.log" ] && tail -20 "$DATA_DIR/history.log" || echo "No history" ;;
    help|-h)        show_help ;;
    version|-v)     echo "excel-formula v$VERSION" ;;
    *)              echo "Unknown: $1"; show_help; exit 1 ;;
esac


path: tips.md
content: # Excel 常用函数速查表

## 一、查找与引用

### 1. VLOOKUP — 纵向查找
```
=VLOOKUP(查找值, 查找范围, 返回列号, 匹配方式)
```
**示例：** `=VLOOKUP(A2, Sheet2!A:D, 3, FALSE)`
- 在Sheet2的A列中查找A2的值，返回第3列数据
- FALSE = 精确匹配，TRUE = 近似匹配
- ⚠️ 查找值必须在范围的第一列

### 2. HLOOKUP — 横向查找
```
=HLOOKUP(查找值, 查找范围, 返回行号, 匹配方式)
```
**示例：** `=HLOOKUP("销售额", A1:Z3, 3, FALSE)`
- 与VLOOKUP类似，但横向查找

### 3. INDEX + MATCH — 万能查找组合
```
=INDEX(返回范围, MATCH(查找值, 查找范围, 匹配方式))
```
**示例：** `=INDEX(C:C, MATCH(A2, B:B, 0))`
- 比VLOOKUP更灵活，不限制查找列位置
- MATCH的0 = 精确匹配，1 = 小于等于，-1 = 大于等于

### 4. XLOOKUP — 新一代查找（Excel 365/2021+）
```
=XLOOKUP(查找值, 查找范围, 返回范围, [未找到值], [匹配模式])
```
**示例：** `=XLOOKUP(A2, B:B, D:D, "未找到")`
- VLOOKUP的替代品，支持左向查找

---

## 二、条件统计

### 5. COUNTIF — 单条件计数
```
=COUNTIF(范围, 条件)
```
**示例：** `=COUNTIF(A:A, "合格")` — 计算A列中"合格"的个数
**示例：** `=COUNTIF(B:B, ">60")` — 计算B列中大于60的个数

### 6. COUNTIFS — 多条件计数
```
=COUNTIFS(范围1, 条件1, 范围2, 条件2, ...)
```
**示例：** `=COUNTIFS(A:A, "销售部", B:B, ">5000")`
- 统计销售部中业绩大于5000的人数

### 7. SUMIF — 单条件求和
```
=SUMIF(条件范围, 条件, 求和范围)
```
**示例：** `=SUMIF(A:A, "北京", C:C)` — 北京地区的总销售额

### 8. SUMIFS — 多条件求和
```
=SUMIFS(求和范围, 条件范围1, 条件1, 条件范围2, 条件2, ...)
```
**示例：** `=SUMIFS(D:D, A:A, "手机", B:B, ">=2024-01-01")`
- 注意SUMIFS的求和范围在第一个参数

### 9. AVERAGEIF — 条件平均值
```
=AVERAGEIF(条件范围, 条件, 平均值范围)
```
**示例：** `=AVERAGEIF(A:A, "男", C:C)` — 男性的平均成绩

---

## 三、文本处理

### 10. LEFT / RIGHT / MID — 提取文本
```
=LEFT(文本, 字符数)
=RIGHT(文本, 字符数)
=MID(文本, 起始位置, 字符数)
```
**示例：** `=LEFT(A2, 3)` — 提取前3个字符
**示例：** `=MID(A2, 5, 8)` — 从第5个字符开始提取8个字符（身份证提取出生日期）

### 11. CONCATENATE / CONCAT / & — 文本拼接
```
=CONCATENATE(文本1, 文本2, ...)
=A1 & "-" & B1
```
**示例：** `=A2 & "(" & B2 & ")"` — 拼接为"张三(销售部)"

### 12. TEXT — 格式化数字/日期为文本
```
=TEXT(值, 格式代码)
```
**示例：** `=TEXT(A2, "yyyy-mm-dd")` — 日期格式化
**示例：** `=TEXT(A2, "#,##0.00")` — 数字千分位+两位小数

### 13. TRIM — 去除多余空格
```
=TRIM(文本)
```
**示例：** `=TRIM(A2)` — 去除首尾空格和多余中间空格

### 14. SUBSTITUTE — 替换文本
```
=SUBSTITUTE(文本, 旧文本, 新文本, [第几个])
```
**示例：** `=SUBSTITUTE(A2, "-", "/")` — 将所有"-"替换为"/"

---

## 四、逻辑判断

### 15. IF — 条件判断
```
=IF(条件, 真值, 假值)
```
**示例：** `=IF(A2>=60, "及格", "不及格")`
**嵌套：** `=IF(A2>=90, "A", IF(A2>=80, "B", IF(A2>=60, "C", "D")))`

### 16. IFS — 多条件判断（Excel 2019+）
```
=IFS(条件1, 值1, 条件2, 值2, ...)
```
**示例：** `=IFS(A2>=90, "优秀", A2>=80, "良好", A2>=60, "及格", TRUE, "不及格")`
- 比嵌套IF更清晰

### 17. IFERROR — 错误处理
```
=IFERROR(公式, 错误时的值)
```
**示例：** `=IFERROR(VLOOKUP(A2, B:D, 3, FALSE), "未找到")`
- 避免显示#N/A等错误

---

## 五、日期与时间

### 18. TODAY / NOW — 当前日期/时间
```
=TODAY()  — 返回当前日期
=NOW()   — 返回当前日期+时间
```
**示例：** `=DATEDIF(B2, TODAY(), "Y")` — 计算年龄

### 19. DATEDIF — 日期差计算
```
=DATEDIF(起始日期, 结束日期, 单位)
```
- 单位: "Y"=年, "M"=月, "D"=天
**示例：** `=DATEDIF(A2, B2, "M")` — 两个日期之间的月数

---

## 六、其他高频

### 20. ROUND / ROUNDUP / ROUNDDOWN — 四舍五入
```
=ROUND(数值, 小数位数)
=ROUNDUP(数值, 小数位数)   — 始终向上
=ROUNDDOWN(数值, 小数位数) — 始终向下
```
**示例：** `=ROUND(A2, 2)` — 保留两位小数
**示例：** `=ROUNDUP(A2/B2, 0)` — 向上取整

---

## 常见公式组合技巧

| 需求 | 公式 |
|------|------|
| 去重计数 | `=SUMPRODUCT(1/COUNTIF(A2:A100,A2:A100))` |
| 多条件查找 | `=INDEX(C:C,MATCH(1,(A:A=E1)*(B:B=F1),0))` (Ctrl+Shift+Enter) |
| 提取数字 | `=SUMPRODUCT(MID(0&A2,LARGE(INDEX(ISNUMBER(--MID(A2,ROW($1:$99),1))*ROW($1:$99),0),ROW($1:$99))+1,1)*10^ROW($1:$99)/10)` |
| 中文金额大写 | 需用VBA或TEXT分段拼接 |
| 动态范围求和 | `=SUM(OFFSET(A1,0,0,COUNTA(A:A),1))` |

---

## 快速对照：VLOOKUP vs INDEX-MATCH vs XLOOKUP

| 特性 | VLOOKUP | INDEX-MATCH | XLOOKUP |
|------|---------|-------------|---------|
| 左向查找 | ❌ | ✅ | ✅ |
| 插入列不受影响 | ❌ | ✅ | ✅ |
| 多条件查找 | ❌ | ✅ | ✅ |
| 默认精确匹配 | ❌ | 需指定0 | ✅ |
| 兼容性 | 所有版本 | 所有版本 | 365/2021+ |

> 💡 建议：新项目用XLOOKUP，需要兼容旧版本时用INDEX-MATCH，简单查找用VLOOKUP。


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: clean (LOW)