AgentSkillsCN

excel-cli

通过 CLI 自动化 Windows 上的 Microsoft Excel。适用于从脚本、CI/CD 或编程智能体中创建、读取或修改 Excel 工作簿时使用。支持 Power Query、DAX、数据透视表、表格、区域、图表、VBA。触发条件:Excel、电子表格、工作簿、xlsx、excelcli、CLI 自动化。

SKILL.md
--- frontmatter
name: excel-cli
description: >
  Automate Microsoft Excel on Windows via CLI. Use when creating, reading,
  or modifying Excel workbooks from scripts, CI/CD, or coding agents.
  Supports Power Query, DAX, PivotTables, Tables, Ranges, Charts, VBA.
  Triggers: Excel, spreadsheet, workbook, xlsx, excelcli, CLI automation.
compatibility: Windows + Microsoft Excel 2016+ required. Uses COM interop - does NOT work on macOS or Linux.
allowed-tools: Cmd(excelcli:*),PowerShell(excelcli:*)
disable-model-invocation: true
license: MIT
version: 1.0.0
repository: https://github.com/sbroenne/mcp-server-excel
documentation: https://excelmcpserver.dev/

Excel Automation with excelcli

Workflow Checklist

StepCommandWhen
1. Sessionsession create/openAlways first
2. Sheetsworksheet create/renameIf needed
3. Write dataSee belowIf writing values
4. Save & closesession close --saveAlways last

Writing Data (Step 3):

  • --values takes a JSON 2D array string: --values '[["Header1","Header2"],[1,2]]'
  • Write one row at a time for reliability: --range-address A1:B1 --values '[["Name","Age"]]'
  • Strings MUST be double-quoted in JSON: "text". Numbers are bare: 42
  • Always wrap the entire JSON value in single quotes to protect special characters

CRITICAL RULES (MUST FOLLOW)

Rule 1: NEVER Ask Clarifying Questions

Execute commands to discover the answer instead:

DON'T ASKDO THIS INSTEAD
"Which file should I use?"excelcli -q session list
"What table should I use?"excelcli -q table list --session <id>
"Which sheet has the data?"excelcli -q worksheet list --session <id>

You have commands to answer your own questions. USE THEM.

Rule 2: Always End With a Text Summary

NEVER end your turn with only a command execution. After completing all operations, always provide a brief text message confirming what was done. Silent command-only responses are incomplete.

Rule 3: Session Lifecycle

Creating vs Opening Files:

powershell
# NEW file - use session create
excelcli -q session create C:\path\newfile.xlsx  # Creates file + returns session ID

# EXISTING file - use session open
excelcli -q session open C:\path\existing.xlsx   # Opens file + returns session ID

CRITICAL: Use session create for new files. session open on non-existent files will fail!

CRITICAL: ALWAYS use the session ID returned by session create or session open in subsequent commands. NEVER guess or hardcode session IDs. The session ID is in the JSON output (e.g., {"sessionId":"abc123"}). Parse it and use it.

powershell
# Example: capture session ID from output, then use it
excelcli -q session create C:\path\file.xlsx     # Returns JSON with sessionId
excelcli -q range set-values --session <returned-session-id> ...
excelcli -q session close --session <returned-session-id> --save

Unclosed sessions leave Excel processes running, locking files.

Rule 4: Data Model Prerequisites

DAX operations require tables in the Data Model:

powershell
excelcli -q table add-to-data-model --session <id> --table-name Sales  # Step 1
excelcli -q datamodel create-measure --session <id> ...               # Step 2 - NOW works

Rule 5: Power Query Development Lifecycle

BEST PRACTICE: Test M code before creating permanent queries

powershell
# Step 1: Test M code without persisting (catches errors early)
excelcli -q powerquery evaluate --session 1 --m-code-file query.m

# Step 2: Create permanent query with validated code
excelcli -q powerquery create --session 1 --query-name Q1 --m-code-file query.m

# Step 3: Load data to destination
excelcli -q powerquery refresh --session 1 --query-name Q1

Rule 6: Report File Errors Immediately

If you see "File not found" or "Path not found" - STOP and report to user. Don't retry.

Rule 7: Use Calculation Mode for Bulk Writes

When writing many values/formulas (10+ cells), disable auto-recalc for performance:

powershell
# 1. Set manual mode
excelcli -q calculationmode set-mode --session 1 --mode manual

# 2. Write data row by row for reliability
excelcli -q range set-values --session 1 --sheet-name Sheet1 --range-address A1:B1 --values '[["Name","Amount"]]'
excelcli -q range set-values --session 1 --sheet-name Sheet1 --range-address A2:B2 --values '[["Salary",5000]]'

# 3. Recalculate once at end
excelcli -q calculationmode calculate --session 1 --scope workbook

# 4. Restore automatic mode
excelcli -q calculationmode set-mode --session 1 --mode automatic

CLI Command Reference

Auto-generated from excelcli --help. Use these exact parameter names.

calculationmode

Control Excel recalculation (automatic vs manual). Set manual mode before bulk writes for faster performance, then recalculate once at the end.

Actions: get-mode, set-mode, calculate

ParameterDescription
--modeTarget calculation mode (required for: set-mode)
--scopeScope: Workbook, Sheet, or Range (required for: calculate)
--sheet-nameSheet name (required for Sheet/Range scope)
--range-addressRange address (required for Range scope)

chart

Chart lifecycle - create, read, move, and delete embedded charts. CRITICAL - AVOID OVERLAPPING DATA: 1. Check used range first with range get-used-range 2. Position chart BELOW or to the RIGHT of data 3. NEVER place charts at default position (0,0) - it overlaps data! POSITIONING: left/top in points (72 points = 1 inch). Use fit-to-range to position chart within a cell range like 'F2:K15'. CHART TYPES: 70+ types available including Column, Line, Pie, Bar, Area, XY Scatter. CREATE OPTIONS: - create-from-range: Create from cell range (e.g., 'A1:D10') - create-from-table: Create from Excel Table (uses table's data range) - create-from-pivottable: Create linked PivotChart Use chartconfig for series, titles, legends, styles, placement mode.

Actions: list, read, create-from-range, create-from-table, create-from-pivottable, delete, move, fit-to-range

ParameterDescription
--chart-nameName of the chart (or shape name) (required for: read, delete, move, fit-to-range)
--sheet-nameTarget worksheet name (required for: create-from-range, create-from-table, create-from-pivottable, fit-to-range)
--source-rangeData range for the chart (e.g., A1:D10) (required for: create-from-range)
--chart-typeType of chart to create (required for: create-from-range, create-from-table, create-from-pivottable)
--leftLeft position in points from worksheet edge (required for: create-from-range, create-from-table, create-from-pivottable)
--topTop position in points from worksheet edge (required for: create-from-range, create-from-table, create-from-pivottable)
--widthChart width in points
--heightChart height in points
--table-nameName of the Excel Table (required for: create-from-table)
--pivot-table-nameName of the source PivotTable (required for: create-from-pivottable)
--range-addressRange to fit the chart to (e.g., A1:D10) (required for: fit-to-range)

chartconfig

Chart configuration - data source, series, type, title, axis labels, legend, and styling. SERIES MANAGEMENT: - add-series: Add data series with valuesRange (required) and optional categoryRange - remove-series: Remove series by 1-based index - set-source-range: Replace entire chart data source TITLES AND LABELS: - set-title: Set chart title (empty string hides title) - set-axis-title: Set axis labels (Category, Value, CategorySecondary, ValueSecondary) CHART STYLES: 1-48 (built-in Excel styles with different color schemes) DATA LABELS: Show values, percentages, series/category names. Positions: Center, InsideEnd, InsideBase, OutsideEnd, BestFit. TRENDLINES: Linear, Exponential, Logarithmic, Polynomial (order 2-6), Power, MovingAverage. PLACEMENT MODE: - 1: Move and size with cells - 2: Move but don't size with cells - 3: Don't move or size with cells (free floating) Use chart for lifecycle operations (create, delete, move, fit-to-range).

Actions: set-source-range, add-series, remove-series, set-chart-type, set-title, set-axis-title, get-axis-number-format, set-axis-number-format, show-legend, set-style, set-placement, set-data-labels, get-axis-scale, set-axis-scale, get-gridlines, set-gridlines, set-series-format, list-trendlines, add-trendline, delete-trendline, set-trendline

ParameterDescription
--chart-nameName of the chart (required)
--source-rangeNew data source range (e.g., Sheet1!A1:D10) (required for: set-source-range)
--series-nameDisplay name for the series (required for: add-series)
--values-rangeRange containing series values (e.g., B2:B10) (required for: add-series)
--category-rangeOptional range for category labels (e.g., A2:A10)
--series-index1-based index of the series to remove (required for: remove-series, set-series-format, list-trendlines, add-trendline, delete-trendline, set-trendline)
--chart-typeNew chart type to apply (required for: set-chart-type)
--titleTitle text to display (required for: set-title, set-axis-title)
--axisWhich axis to set title for (Category, Value, SeriesAxis) (required for: set-axis-title, get-axis-number-format, set-axis-number-format, get-axis-scale, set-axis-scale, set-gridlines)
--number-formatExcel number format code (e.g., "$#,##0", "0.00%") (required for: set-axis-number-format)
--visibleTrue to show legend, false to hide (required for: show-legend)
--legend-positionOptional position for the legend
--style-idExcel chart style ID (1-48 for most chart types) (required for: set-style)
--placementPlacement mode: 1=MoveAndSize, 2=Move, 3=FreeFloating (required for: set-placement)
--show-valueShow data values on labels
--show-percentageShow percentage values (pie/doughnut charts)
--show-series-nameShow series name on labels
--show-category-nameShow category name on labels
--show-bubble-sizeShow bubble size (bubble charts)
--separatorSeparator string between label components
--label-positionPosition of data labels relative to data points
--minimum-scaleMinimum axis value (null for auto)
--maximum-scaleMaximum axis value (null for auto)
--major-unitMajor gridline interval (null for auto)
--minor-unitMinor gridline interval (null for auto)
--show-majorShow major gridlines (null to keep current)
--show-minorShow minor gridlines (null to keep current)
--marker-styleMarker shape style
--marker-sizeMarker size in points (2-72)
--marker-background-colorMarker fill color (#RRGGBB)
--marker-foreground-colorMarker border color (#RRGGBB)
--invert-if-negativeInvert colors for negative values
--typeType of trendline (Linear, Exponential, etc.) (required for: add-trendline)
--orderPolynomial order (2-6, for Polynomial type)
--periodMoving average period (for MovingAverage type)
--forwardPeriods to extend forward
--backwardPeriods to extend backward
--interceptForce trendline through specific Y-intercept
--display-equationDisplay trendline equation on chart
--display-r-squaredDisplay R-squared value on chart
--nameCustom name for the trendline
--trendline-index1-based index of the trendline to delete (required for: delete-trendline, set-trendline)

conditionalformat

Conditional formatting - visual rules based on cell values. TYPES: cellValue (requires operatorType+formula1), expression (formula only). FORMAT: interiorColor/fontColor as #RRGGBB, fontBold/Italic, borderStyle/Color. OPERATORS: equal, notEqual, greater, less, greaterEqual, lessEqual, between, notBetween. For 'between' and 'notBetween', both formula1 and formula2 are required.

Actions: add-rule, clear-rules

ParameterDescription
--sheet-nameSheet name (empty for active sheet)
--range-addressRange address (A1 notation or named range)
--rule-typeRule type: cellValue, expression
--operator-typeXlFormatConditionOperator: equal, notEqual, greater, less, greaterEqual, lessEqual, between, notBetween
--formula1First formula/value for condition
--formula2Second formula/value (for between/notBetween)
--interior-colorFill color (#RRGGBB or color index)
--interior-patternInterior pattern (1=Solid, -4142=None, 9=Gray50, etc.)
--font-colorFont color (#RRGGBB or color index)
--font-boldBold font
--font-italicItalic font
--border-styleBorder style: none, continuous, dash, dot, etc.
--border-colorBorder color (#RRGGBB or color index)

connection

Data connections (OLEDB, ODBC, ODC import). TEXT/WEB/CSV: Use powerquery instead. Power Query connections auto-redirect to powerquery. TIMEOUT: 5 min auto-timeout for refresh/load-to.

Actions: list, view, create, refresh, delete, load-to, get-properties, set-properties, test

ParameterDescription
--connection-nameName of the connection to view
--connection-stringOLEDB or ODBC connection string
--command-textSQL query or table name
--descriptionOptional description for the connection
--timeoutOptional timeout for the refresh operation
--sheet-nameTarget worksheet name
--connection-stringNew connection string (null to keep current)
--command-textNew SQL query or table name (null to keep current)
--background-queryRun query in background (null to keep current)
--refresh-on-file-openRefresh when file opens (null to keep current)
--save-passwordSave password in connection (null to keep current)
--refresh-periodAuto-refresh interval in minutes (null to keep current)

datamodel

Data Model (Power Pivot) - DAX measures and table management. CRITICAL: WORKSHEET TABLES AND DATA MODEL ARE SEPARATE! - After table append changes, Data Model still has OLD data - MUST call refresh to sync changes - Power Query refresh auto-syncs (no manual refresh needed) PREREQUISITE: Tables must be added to the Data Model first. Use table add-to-datamodel for worksheet tables, or powerquery to import and load data directly to the Data Model. DAX MEASURES: - Create with DAX formulas like 'SUM(Sales[Amount])' - DAX formulas are auto-formatted on CREATE/UPDATE via Dax.Formatter (SQLBI) - Read operations return raw DAX as stored DAX EVALUATE QUERIES: - Use evaluate to execute DAX EVALUATE queries against the Data Model - Returns tabular results from queries like 'EVALUATE TableName' - Supports complex DAX: SUMMARIZE, FILTER, CALCULATETABLE, TOPN, etc. DMV (DYNAMIC MANAGEMENT VIEW) QUERIES: - Use execute-dmv to query Data Model metadata via SQL-like syntax - Syntax: SELECT * FROM $SYSTEM.SchemaRowset (ONLY SELECT * supported) - Use DISCOVER_SCHEMA_ROWSETS to list all available DMVs Use datamodelrel for relationships between tables.

Actions: list-tables, list-columns, read-table, read-info, list-measures, read, delete-measure, delete-table, rename-table, refresh, create-measure, update-measure, evaluate, execute-dmv

ParameterDescription
--table-nameName of the table to list columns from (required for: list-columns, read-table, delete-table, create-measure)
--measure-nameName of the measure to get (required for: read, delete-measure, create-measure, update-measure)
--old-nameCurrent name of the table (required for: rename-table)
--new-nameNew name for the table (required for: rename-table)
--timeoutOptional: Timeout for the refresh operation
--dax-formulaDAX formula for the measure (will be auto-formatted) (required for: create-measure)
--format-typeOptional: Format type (Currency, Decimal, Percentage, General)
--descriptionOptional: Description of the measure
--dax-queryDAX EVALUATE query (e.g., "EVALUATE 'TableName'" or "EVALUATE SUMMARIZE(...)") (required for: evaluate)
--dmv-queryDMV query in SQL-like syntax (e.g., "SELECT * FROM $SYSTEM.TMSCHEMA_TABLES") (required for: execute-dmv)

datamodelrel

Data Model relationships - link tables for cross-table DAX calculations. CRITICAL: Deleting or recreating tables removes ALL their relationships. Use list-relationships before table operations to backup, then recreate relationships after schema changes. RELATIONSHIP REQUIREMENTS: - Both tables must exist in the Data Model first - Columns must have compatible data types - fromTable/fromColumn = many-side (detail table, foreign key) - toTable/toColumn = one-side (lookup table, primary key) ACTIVE VS INACTIVE: - Only ONE active relationship can exist between two tables - Use active=false when creating alternative paths - DAX USERELATIONSHIP() activates inactive relationships

Actions: list-relationships, read-relationship, create-relationship, update-relationship, delete-relationship

ParameterDescription
--from-tableSource table name (required for: read-relationship, create-relationship, update-relationship, delete-relationship)
--from-columnSource column name (required for: read-relationship, create-relationship, update-relationship, delete-relationship)
--to-tableTarget table name (required for: read-relationship, create-relationship, update-relationship, delete-relationship)
--to-columnTarget column name (required for: read-relationship, create-relationship, update-relationship, delete-relationship)
--activeWhether the relationship should be active (default: true) (required for: update-relationship)

unknown

Diagnostic commands for testing CLI/MCP infrastructure without Excel. These commands validate parameter parsing, routing, JSON serialization, and error handling — no Excel COM session needed.

Actions: ping, echo, validate-params

ParameterDescription
--messageThe message to echo back (required) (required for: echo)
--tagOptional tag to include in the response
--nameRequired name parameter (required for: validate-params)
--countRequired integer parameter (required for: validate-params)
--labelOptional label parameter
--verboseOptional boolean flag (default: false)

namedrange

Named ranges for formulas/parameters. CREATE/UPDATE: value is cell reference (e.g., 'Sheet1!$A$1'). WRITE: value is data to store. TIP: range(rangeAddress=namedRangeName) for bulk data read/write.

Actions: list, write, read, update, create, delete

ParameterDescription
--nameName of the named range (required for: write, read, update, create, delete)
--valueValue to set (required for: write)
--referenceNew cell reference (e.g., Sheet1!$A$1:$B$10) (required for: update, create)

pivottable

PivotTable lifecycle management: create from various sources, list, read details, refresh, and delete. Use pivottablefield for field operations, pivottablecalc for calculated fields and layout. BEST PRACTICE: Use 'list' before creating. Prefer 'refresh' or field modifications over delete+recreate. Delete+recreate loses field configurations, filters, sorting, and custom layouts. REFRESH: Call 'refresh' after configuring fields with pivottablefield to update the visual display. This is especially important for OLAP/Data Model PivotTables where field operations are structural only and don't automatically trigger a visual refresh. CREATE OPTIONS: - 'create-from-range': Use source sheet and range address for data range - 'create-from-table': Use an Excel Table (ListObject) as source - 'create-from-datamodel': Use a Power Pivot Data Model table as source

Actions: list, read, create-from-range, create-from-table, create-from-datamodel, delete, refresh

ParameterDescription
--pivot-table-nameName of the PivotTable (required for: read, create-from-range, create-from-table, create-from-datamodel, delete, refresh)
--source-sheetSource worksheet name (required for: create-from-range)
--source-rangeSource range address (e.g., "A1:F100") (required for: create-from-range)
--destination-sheetDestination worksheet name (required for: create-from-range, create-from-table, create-from-datamodel)
--destination-cellDestination cell address (e.g., "A1") (required for: create-from-range, create-from-table, create-from-datamodel)
--table-nameName of the Excel Table (required for: create-from-table, create-from-datamodel)
--timeoutOptional timeout for the refresh operation

pivottablecalc

PivotTable calculated fields/members, layout configuration, and data extraction. Use pivottable for lifecycle, pivottablefield for field placement. CALCULATED FIELDS (for regular PivotTables): - Create custom fields using formulas like '=Revenue-Cost' or '=Quantity*UnitPrice' - Can reference existing fields by name - After creating, use pivottablefield add-value-field to add to Values area - For complex multi-table calculations, prefer DAX measures with datamodel CALCULATED MEMBERS (for OLAP/Data Model PivotTables only): - Create using MDX expressions - Member types: Member, Set, Measure LAYOUT OPTIONS: - 0 = Compact (default, fields in single column) - 1 = Tabular (each field in separate column - best for export/analysis) - 2 = Outline (hierarchical with expand/collapse)

Actions: get-data, create-calculated-field, list-calculated-fields, delete-calculated-field, list-calculated-members, create-calculated-member, delete-calculated-member, set-layout, set-subtotals, set-grand-totals

ParameterDescription
--pivot-table-nameName of the PivotTable (required)
--field-nameName for the calculated field (required for: create-calculated-field, delete-calculated-field, set-subtotals)
--formulaFormula using field references (e.g., "=Revenue-Cost") (required for: create-calculated-field, create-calculated-member)
--member-nameName for the calculated member (MDX naming format) (required for: create-calculated-member, delete-calculated-member)
--typeType of calculated member (Member, Set, or Measure)
--solve-orderSolve order for calculation precedence (default: 0)
--display-folderDisplay folder path for organizing measures (optional)
--number-formatNumber format code for the calculated member (optional)
--row-layoutLayout form: 0=Compact, 1=Tabular, 2=Outline (required for: set-layout)
--show-subtotalsTrue to show automatic subtotals, false to hide (required for: set-subtotals)
--show-row-grand-totalsShow row grand totals (bottom summary row) (required for: set-grand-totals)
--show-column-grand-totalsShow column grand totals (right summary column) (required for: set-grand-totals)

pivottablefield

PivotTable field management: add/remove/configure fields, filtering, sorting, and grouping. Use pivottable for lifecycle, pivottablecalc for calculated fields and layout. IMPORTANT: Field operations modify structure only. Call pivottable refresh after configuring fields to update the visual display, especially for OLAP/Data Model PivotTables. FIELD AREAS: - Row fields: Group data by categories (add-row-field) - Column fields: Create column headers (add-column-field) - Value fields: Aggregate numeric data with Sum, Count, Average, etc. (add-value-field) - Filter fields: Add report-level filters (add-filter-field) AGGREGATION FUNCTIONS: Sum, Count, Average, Max, Min, Product, CountNumbers, StdDev, StdDevP, Var, VarP GROUPING: - Date fields: Group by Days, Months, Quarters, Years (group-by-date) - Numeric fields: Group by ranges with start/end/interval (group-by-numeric) NUMBER FORMAT: Use US format codes like '#,##0.00' for currency or '0.00%' for percentages.

Actions: list-fields, add-row-field, add-column-field, add-value-field, add-filter-field, remove-field, set-field-function, set-field-name, set-field-format, set-field-filter, sort-field, group-by-date, group-by-numeric

ParameterDescription
--pivot-table-nameName of the PivotTable (required)
--field-nameName of the field to add (required for: add-row-field, add-column-field, add-value-field, add-filter-field, remove-field, set-field-function, set-field-name, set-field-format, set-field-filter, sort-field, group-by-date, group-by-numeric)
--positionOptional position in row area (1-based)
--aggregation-functionAggregation function (for Regular and OLAP auto-create mode) (required for: set-field-function)
--custom-nameOptional custom name for the field/measure (required for: set-field-name)
--number-formatNumber format string (required for: set-field-format)
--selected-valuesValues to show (others will be hidden) (required for: set-field-filter)
--directionSort direction
--intervalGrouping interval (Months, Quarters, Years) (required for: group-by-date)
--startStarting value (null = use field minimum)
--end-valueEnding value (null = use field maximum)
--interval-sizeSize of each group (e.g., 100 for groups of 100) (required for: group-by-numeric)

powerquery

Power Query M code and data loading. TEST-FIRST DEVELOPMENT WORKFLOW (BEST PRACTICE): 1. evaluate - Test M code WITHOUT persisting (catches syntax errors, validates sources, shows data preview) 2. create/update - Store VALIDATED query in workbook 3. refresh/load-to - Load data to destination Skip evaluate only for trivial literal tables. IF CREATE/UPDATE FAILS: Use evaluate to get the actual M engine error message, fix code, retry. DATETIME COLUMNS: Always include Table.TransformColumnTypes() in M code to set column types explicitly. Without explicit types, dates may be stored as numbers and Data Model relationships may fail. DESTINATIONS: 'worksheet' (default), 'data-model' (for DAX), 'both', 'connection-only'. Use 'data-model' to load to Power Pivot, then use datamodel to create DAX measures. TARGET CELL: targetCellAddress places tables without clearing sheet. TIMEOUT: 5 min auto-timeout for refresh/load. For network queries, use timeout=120 or higher. timeout=0 is INVALID - must be greater than zero.

Actions: list, view, refresh, get-load-config, delete, create, update, load-to, refresh-all, rename, unload, evaluate

ParameterDescription
--query-nameName of the query to view (required for: view, refresh, get-load-config, delete, create, update, load-to, unload)
--timeoutMaximum time to wait for refresh (required for: refresh)
--m-codeRaw M code (inline string) (required for: create, update, evaluate)
--load-destinationLoad destination mode
--target-sheetTarget worksheet name (required for LoadToTable and LoadToBoth; defaults to query name when omitted)
--target-cell-addressOptional target cell address for worksheet loads (e.g., "B5"). Required when loading to an existing worksheet with other data.
--refreshWhether to refresh data after update (default: true)
--old-nameCurrent name of the query (required for: rename)
--new-nameNew name for the query (required for: rename)

range

Core range operations: get/set values and formulas, copy ranges, clear content, and discover data regions. Use rangeedit for insert/delete/find/sort. Use rangeformat for styling/validation. Use rangelink for hyperlinks and cell protection. Calculation mode and explicit recalculation are handled by calculationmode. BEST PRACTICE: Use 'get-values' to check existing data before overwriting. Use 'clear-contents' (not 'clear-all') to preserve cell formatting when clearing data. set-values preserves existing formatting; use set-number-format after if format change needed. DATA FORMAT: values and formulas are 2D JSON arrays representing rows and columns. Example: [[row1col1, row1col2], [row2col1, row2col2]] Single cell returns [[value]] (always 2D). REQUIRED PARAMETERS: - sheetName + rangeAddress for cell operations (e.g., sheetName='Sheet1', rangeAddress='A1:D10') - For named ranges, use sheetName='' (empty string) and rangeAddress='MyNamedRange' COPY OPERATIONS: Specify source and target sheet/range for copy operations. NUMBER FORMATS: Use US locale format codes (e.g., '#,##0.00', 'mm/dd/yyyy', '0.00%').

Actions: get-values, set-values, get-formulas, set-formulas, clear-all, clear-contents, clear-formats, copy, copy-values, copy-formulas, get-number-formats, set-number-format, set-number-formats, get-used-range, get-current-region, get-info

ParameterDescription
--sheet-nameName of the worksheet containing the range - REQUIRED for cell addresses, use empty string for named ranges only (required for: get-values, set-values, get-formulas, set-formulas, clear-all, clear-contents, clear-formats, get-number-formats, set-number-format, set-number-formats, get-used-range, get-current-region, get-info)
--range-addressCell range address (e.g., 'A1', 'A1:D10', 'B:D') or named range name (e.g., 'SalesData') (required for: get-values, set-values, get-formulas, set-formulas, clear-all, clear-contents, clear-formats, get-number-formats, set-number-format, set-number-formats, get-info)
--values2D array of values to set - rows are outer array, columns are inner array (e.g., [[1,2,3],[4,5,6]] for 2 rows x 3 cols). Optional if valuesFile is provided.
--values-filePath to a JSON or CSV file containing the values. JSON: 2D array. CSV: rows/columns. Alternative to inline values parameter.
--formulas2D array of formulas to set - include '=' prefix (e.g., [['=A1+B1', '=SUM(A:A)'], ['=C1*2', '=AVERAGE(B:B)']]). Optional if formulasFile is provided.
--formulas-filePath to a JSON file containing the formulas as a 2D array. Alternative to inline formulas parameter.
--source-sheetSource worksheet name for copy operations (required for: copy, copy-values, copy-formulas)
--source-rangeSource range address for copy operations (e.g., 'A1:D10') (required for: copy, copy-values, copy-formulas)
--target-sheetTarget worksheet name for copy operations (required for: copy, copy-values, copy-formulas)
--target-rangeTarget range address - can be single cell for paste destination (e.g., 'A1') (required for: copy, copy-values, copy-formulas)
--format-codeNumber format code in US locale (e.g., '#,##0.00' for numbers, 'mm/dd/yyyy' for dates, '0.00%' for percentages, 'General' for default, '@' for text) (required for: set-number-format)
--formats2D array of format codes - same dimensions as target range (e.g., [['#,##0.00', '0.00%'], ['mm/dd/yyyy', 'General']]). Optional if formatsFile is provided.
--formats-filePath to a JSON file containing 2D array of format codes. Alternative to inline formats parameter.
--cell-addressSingle cell address (e.g., 'B5') - expands to contiguous data region around this cell (required for: get-current-region)

rangeedit

Range editing operations: insert/delete cells, rows, and columns; find/replace text; sort data. Use range for values/formulas/copy/clear operations. INSERT/DELETE CELLS: Specify shift direction to control how surrounding cells move. - Insert: 'Down' or 'Right' - Delete: 'Up' or 'Left' INSERT/DELETE ROWS: Use row range like '5:10' to insert/delete rows 5-10. INSERT/DELETE COLUMNS: Use column range like 'B:D' to insert/delete columns B-D. FIND/REPLACE: Search within the specified range with optional case/cell matching. - Find returns up to 10 matching cell addresses with total count. - Replace modifies all matches by default. SORT: Specify sortColumns as array of {columnIndex: 1, ascending: true} objects. Column indices are 1-based relative to the range.

Actions: insert-cells, delete-cells, insert-rows, delete-rows, insert-columns, delete-columns, find, replace, sort

ParameterDescription
--sheet-nameName of the worksheet containing the range (required)
--range-addressCell range address where cells will be inserted (e.g., 'A1:D10') (required)
--insert-shiftDirection to shift existing cells: 'Down' or 'Right' (required for: insert-cells)
--delete-shiftDirection to shift remaining cells: 'Up' or 'Left' (required for: delete-cells)
--search-valueText or value to search for (required for: find)
--find-optionsSearch options: matchCase (default: false), matchEntireCell (default: false), searchFormulas (default: true) (required for: find)
--find-valueText or value to search for (required for: replace)
--replace-valueText or value to replace matches with (required for: replace)
--replace-optionsReplace options: matchCase (default: false), matchEntireCell (default: false), replaceAll (default: true) (required for: replace)
--sort-columnsArray of sort specifications: [{columnIndex: 1, ascending: true}, ...] - columnIndex is 1-based relative to range (required for: sort)
--has-headersWhether the range has a header row to exclude from sorting (default: true)

rangeformat

Range formatting operations: apply styles, set fonts/colors/borders, add data validation, merge cells, auto-fit dimensions. Use range for values/formulas/copy/clear operations. STYLES: Use built-in style names like 'Heading 1', 'Good', 'Bad', 'Currency', 'Percent', etc. For consistent, professional formatting, prefer set-style with built-in styles over format-range. FONT/COLOR FORMATTING: Specify individual formatting properties: - Colors as hex '#RRGGBB' (e.g., '#FF0000' for red, '#00FF00' for green) - Font sizes as points (e.g., 12, 14, 16) - Alignment: 'left', 'center', 'right' (horizontal), 'top', 'middle', 'bottom' (vertical) DATA VALIDATION: Restrict cell input with validation rules: - Types: 'list', 'whole', 'decimal', 'date', 'time', 'textLength', 'custom' - For list validation, formula1 is the list source (e.g., '=$A$1:$A$10' or '"Option1,Option2,Option3"') - Operators: 'between', 'notBetween', 'equal', 'notEqual', 'greaterThan', 'lessThan', 'greaterThanOrEqual', 'lessThanOrEqual' MERGE: Combines cells into one. Only top-left cell value is preserved.

Actions: set-style, get-style, format-range, validate-range, get-validation, remove-validation, auto-fit-columns, auto-fit-rows, merge-cells, unmerge-cells, get-merge-info

ParameterDescription
--sheet-nameName of the worksheet containing the range (required)
--range-addressCell range address (e.g., 'A1:D10') (required)
--style-nameBuilt-in or custom style name (e.g., 'Heading 1', 'Good', 'Bad', 'Currency', 'Percent'). Use 'Normal' to reset. (required for: set-style)
--font-nameFont family name (e.g., 'Arial', 'Calibri', 'Times New Roman')
--font-sizeFont size in points (e.g., 10, 11, 12, 14, 16)
--boldWhether to apply bold formatting
--italicWhether to apply italic formatting
--underlineWhether to apply underline formatting
--font-colorFont (foreground) color as hex '#RRGGBB' (e.g., '#FF0000' for red)
--fill-colorCell fill (background) color as hex '#RRGGBB' (e.g., '#FFFF00' for yellow)
--border-styleBorder line style (e.g., 'thin', 'medium', 'thick', 'dashed', 'dotted')
--border-colorBorder color as hex '#RRGGBB'
--border-weightBorder weight (e.g., 'hairline', 'thin', 'medium', 'thick')
--horizontal-alignmentHorizontal text alignment: 'left', 'center', 'right', 'justify', 'fill'
--vertical-alignmentVertical text alignment: 'top', 'middle', 'bottom', 'justify'
--wrap-textWhether to wrap text within cells
--orientationText rotation in degrees (-90 to 90, or 255 for vertical)
--validation-typeData validation type: 'list', 'whole', 'decimal', 'date', 'time', 'textLength', 'custom' (required for: validate-range)
--validation-operatorValidation comparison operator: 'between', 'notBetween', 'equal', 'notEqual', 'greaterThan', 'lessThan', 'greaterThanOrEqual', 'lessThanOrEqual'
--formula1First validation formula/value - for list validation use range '=$A$1:$A$10' or inline '"A,B,C"'
--formula2Second validation formula/value - required only for 'between' and 'notBetween' operators
--show-input-messageWhether to show input message when cell is selected (default: false)
--input-titleTitle for the input message popup
--input-messageText for the input message popup
--show-error-alertWhether to show error alert on invalid input (default: true)
--error-styleError alert style: 'stop' (prevents entry), 'warning' (allows override), 'information' (allows entry)
--error-titleTitle for the error alert popup
--error-messageText for the error alert popup
--ignore-blankWhether to allow blank cells in validation (default: true)
--show-dropdownWhether to show dropdown arrow for list validation (default: true)

rangelink

Hyperlink and cell protection operations for Excel ranges. Use range for values/formulas, rangeformat for styling. HYPERLINKS: - 'add-hyperlink': Add a clickable hyperlink to a cell (URL can be web, file, or mailto) - 'remove-hyperlink': Remove hyperlink(s) from cells while keeping the cell content - 'list-hyperlinks': Get all hyperlinks on a worksheet - 'get-hyperlink': Get hyperlink details for a specific cell CELL PROTECTION: - 'set-cell-lock': Lock or unlock cells (only effective when sheet protection is enabled) - 'get-cell-lock': Check if cells are locked Note: Cell locking only takes effect when the worksheet is protected.

Actions: add-hyperlink, remove-hyperlink, list-hyperlinks, get-hyperlink, set-cell-lock, get-cell-lock

ParameterDescription
--sheet-nameName of the worksheet (required)
--cell-addressSingle cell address (e.g., 'A1') (required for: add-hyperlink, get-hyperlink)
--urlHyperlink URL (web: 'https://...', file: 'file:///...', email: 'mailto:...') (required for: add-hyperlink)
--display-textText to display in the cell (optional, defaults to URL)
--tooltipTooltip text shown on hover (optional)
--range-addressCell range address to remove hyperlinks from (e.g., 'A1:D10') (required for: remove-hyperlink, set-cell-lock, get-cell-lock)
--lockedLock status: true = locked (protected when sheet protection enabled), false = unlocked (editable) (required for: set-cell-lock)

worksheet

Worksheet lifecycle management: create, rename, copy, delete, move, list sheets. Use range for data operations. Use sheetstyle for tab colors and visibility. ATOMIC OPERATIONS: 'copy-to-file' and 'move-to-file' don't require a session - they open/close files automatically. POSITIONING: For 'move', 'copy-to-file', 'move-to-file' - use 'before' OR 'after' (not both) to position the sheet relative to another. If neither specified, moves to end.

Actions: list, create, rename, copy, delete, move, copy-to-file, move-to-file

ParameterDescription
--file-pathOptional file path when batch contains multiple workbooks. If omitted, uses primary workbook.
--sheet-nameName for the new worksheet (required for: create, delete, move)
--old-nameCurrent name of the worksheet (required for: rename)
--new-nameNew name for the worksheet (required for: rename)
--source-nameName of the source worksheet (required for: copy)
--target-nameName for the copied worksheet (required for: copy)
--before-sheetOptional: Name of sheet to position before
--after-sheetOptional: Name of sheet to position after
--source-fileFull path to the source workbook (required for: copy-to-file, move-to-file)
--source-sheetName of the sheet to copy (required for: copy-to-file, move-to-file)
--target-fileFull path to the target workbook (required for: copy-to-file, move-to-file)
--target-sheet-nameOptional: New name for the copied sheet (default: keeps original name)

worksheetstyle

Worksheet styling operations for tab colors and visibility. Use sheet for lifecycle operations (create, rename, copy, delete, move). TAB COLORS: Use RGB values (0-255 each) to set custom tab colors for visual organization. VISIBILITY LEVELS: - 'visible': Normal visible sheet - 'hidden': Hidden but accessible via Format > Sheet > Unhide - 'veryhidden': Only accessible via VBA (protection against casual unhiding)

Actions: set-tab-color, get-tab-color, clear-tab-color, set-visibility, get-visibility, show, hide, very-hide

ParameterDescription
--sheet-nameName of the worksheet to color (required)
--redRed color component (0-255) (required for: set-tab-color)
--greenGreen color component (0-255) (required for: set-tab-color)
--blueBlue color component (0-255) (required for: set-tab-color)
--visibilityVisibility level: 'visible', 'hidden', or 'veryhidden' (required for: set-visibility)

slicer

Slicer visual filters for PivotTables and Excel Tables. PIVOTTABLE SLICERS: create-slicer, list-slicers, set-slicer-selection, delete-slicer. TABLE SLICERS: create-table-slicer, list-table-slicers, set-table-slicer-selection, delete-table-slicer. NAMING: Auto-generate descriptive names like {FieldName}Slicer (e.g., RegionSlicer). SELECTION: selectedItems as list of strings. Empty list clears filter (shows all items). Set clearFirst=false to add to existing selection.

Actions: create-slicer, list-slicers, set-slicer-selection, delete-slicer, create-table-slicer, list-table-slicers, set-table-slicer-selection, delete-table-slicer

ParameterDescription
--pivot-table-nameName of the PivotTable to create slicer for (required for: create-slicer)
--field-nameName of the field to use for the slicer (required for: create-slicer)
--slicer-nameName for the new slicer (required for: create-slicer, set-slicer-selection, delete-slicer, create-table-slicer, set-table-slicer-selection, delete-table-slicer)
--destination-sheetWorksheet where slicer will be placed (required for: create-slicer, create-table-slicer)
--positionTop-left cell position for the slicer (e.g., "H2") (required for: create-slicer, create-table-slicer)
--selected-itemsItems to select (show in PivotTable) (required for: set-slicer-selection, set-table-slicer-selection)
--clear-firstIf true, clears existing selection before setting new items (default: true)
--table-nameName of the Excel Table (required for: create-table-slicer)
--column-nameName of the column to use for the slicer (required for: create-table-slicer)

table

Excel Tables (ListObjects) - lifecycle and data operations. Tables provide structured references, automatic formatting, and Data Model integration. BEST PRACTICE: Use 'list' to check existing tables before creating. Prefer 'append'/'resize'/'rename' over delete+recreate to preserve references. WARNING: Deleting tables used as PivotTable sources or in Data Model relationships will break those objects. DATA MODEL WORKFLOW: To analyze worksheet data with DAX/Power Pivot: 1. Create or identify an Excel Table on a worksheet 2. Use 'add-to-datamodel' to add the table to Power Pivot 3. Then use datamodel to create DAX measures on it DAX-BACKED TABLES: Create tables populated by DAX EVALUATE queries: - 'create-from-dax': Create a new table backed by a DAX query (e.g., SUMMARIZE, FILTER) - 'update-dax': Update the DAX query for an existing DAX-backed table - 'get-dax': Get the DAX query info for a table (check if it's DAX-backed) Related: tablecolumn (filter/sort/columns), datamodel (DAX measures, evaluate queries)

Actions: list, create, rename, delete, read, resize, toggle-totals, set-column-total, append, get-data, set-style, add-to-data-model, create-from-dax, update-dax, get-dax

ParameterDescription
--sheet-nameName of the worksheet to create the table on (required for: create, create-from-dax)
--table-nameName for the new table (must be unique in workbook) (required for: create, rename, delete, read, resize, toggle-totals, set-column-total, append, get-data, set-style, add-to-data-model, create-from-dax, update-dax, get-dax)
--rangeCell range address for the table (e.g., 'A1:D10') (required for: create)
--has-headersTrue if first row contains column headers (default: true)
--table-styleTable style name (e.g., 'TableStyleMedium2', 'TableStyleLight1'). Optional. (required for: set-style)
--new-nameNew name for the table (must be unique in workbook) (required for: rename)
--new-rangeNew range address (e.g., 'A1:F20') (required for: resize)
--show-totalsTrue to show totals row, false to hide (required for: toggle-totals)
--column-nameName of the column to set total function on (required for: set-column-total)
--total-functionTotals function name: Sum, Count, Average, Min, Max, CountNums, StdDev, Var, None (required for: set-column-total)
--rows2D array of row data to append - column order must match table columns. Optional if rowsFile is provided.
--rows-filePath to a JSON or CSV file containing the rows to append. JSON: 2D array. CSV: rows/columns. Alternative to inline rows parameter.
--visible-onlyTrue to return only visible (non-filtered) rows; false for all rows (default: false)
--dax-queryDAX EVALUATE query (e.g., 'EVALUATE Sales' or 'EVALUATE SUMMARIZE(...)') (required for: create-from-dax, update-dax)
--target-cellTarget cell address for table placement (default: 'A1')

tablecolumn

Table column, filtering, and sorting operations for Excel Tables (ListObjects). Use table for table-level lifecycle and data operations. FILTERING: - 'apply-filter': Simple criteria filter (e.g., ">100", "=Active", "<>Closed") - 'apply-filter-values': Filter by exact values (provide list of values to include) - 'clear-filters': Remove all active filters - 'get-filters': See current filter state SORTING: - 'sort': Single column sort (ascending/descending) - 'sort-multi': Multi-column sort (provide list of {columnName, ascending} objects) COLUMN MANAGEMENT: - 'add-column'/'remove-column'/'rename-column': Modify table structure NUMBER FORMATS: Use US locale format codes (e.g., '#,##0.00', '0%', 'yyyy-mm-dd')

Actions: apply-filter, apply-filter-values, clear-filters, get-filters, add-column, remove-column, rename-column, get-structured-reference, sort, sort-multi, get-column-number-format, set-column-number-format

ParameterDescription
--table-nameName of the Excel table (required)
--column-nameName of the column to filter (required for: apply-filter, apply-filter-values, add-column, remove-column, sort, get-column-number-format, set-column-number-format)
--criteriaFilter criteria string (e.g., '>100', '=Active', '<>Closed') (required for: apply-filter)
--valuesList of exact values to include in the filter (required for: apply-filter-values)
--position1-based column position (optional, defaults to end of table)
--old-nameCurrent column name (required for: rename-column)
--new-nameNew column name (required for: rename-column)
--regionTable region: 'Data', 'Headers', 'Totals', or 'All' (required for: get-structured-reference)
--ascendingSort order: true = ascending (A-Z, 0-9), false = descending (default: true)
--sort-columnsList of sort specifications: [{columnName: 'Col1', ascending: true}, ...] - applied in order (required for: sort-multi)
--format-codeNumber format code in US locale (e.g., '#,##0.00', '0%', 'yyyy-mm-dd') (required for: set-column-number-format)

vba

VBA scripts (requires .xlsm and VBA trust enabled). PREREQUISITES: - Workbook must be macro-enabled (.xlsm) - VBA trust must be enabled for automation RUN: procedureName format is 'Module.Procedure' (e.g., 'Module1.MySub').

Actions: list, view, import, update, run, delete

ParameterDescription
--module-nameName of the VBA module (required for: view, import, update, delete)
--vba-codeVBA code to import (required for: import, update)
--procedure-nameName of the procedure to run (e.g., "Module1.MySub") (required for: run)
--timeoutOptional timeout for execution
--parametersOptional parameters to pass to the procedure (required for: run)

Common Pitfalls

--values-file Must Be an Existing File

--values-file expects a path to an existing JSON or CSV file on disk. Do NOT pass inline JSON as the value — the CLI will look for a file at that path and fail with "File not found". If you don't have a file, use --values with inline JSON instead.

--timeout Must Be Greater Than Zero

When using --timeout, the value must be a positive integer (seconds). --timeout 0 is invalid and will error. Omit --timeout entirely to use the default (300 seconds for most operations).

Power Query Operations Are Slow

powerquery create, powerquery refresh, and powerquery evaluate may take 30+ seconds depending on data volume. Either omit --timeout (uses 5-minute default) or set a generous value like --timeout 120.

JSON Values Format

--values takes a 2D JSON array wrapped in single quotes:

powershell
# CORRECT: 2D array with single-quote wrapper
--values '[["Name","Age"],["Alice",30],["Bob",25]]'

# WRONG: Not a 2D array
--values '["Alice",30]'

# WRONG: Object instead of array
--values '{"Name":"Alice","Age":30}'

Reference Documentation

  • @references/behavioral-rules.md - Core execution rules and LLM guidelines
  • @references/anti-patterns.md - Common mistakes to avoid
  • @references/workflows.md - Data Model constraints and patterns

Installation

powershell
dotnet tool install --global Sbroenne.ExcelMcp.CLI