Sbroenne.ExcelMcp.CLI 1.3.3

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global Sbroenne.ExcelMcp.CLI --version 1.3.3
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local Sbroenne.ExcelMcp.CLI --version 1.3.3
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=Sbroenne.ExcelMcp.CLI&version=1.3.3
                    
nuke :add-package Sbroenne.ExcelMcp.CLI --version 1.3.3
                    

ExcelMcp.CLI - Command-Line Interface for Excel Automation

NuGet Downloads License: MIT

A professional command-line tool for Excel development workflows, Power Query management, VBA automation, and data operations.

Control Microsoft Excel from your terminal - manage worksheets, Power Query M code, DAX measures, PivotTables, Excel Tables, VBA macros, and more. Perfect for CI/CD pipelines, automated testing, and reproducible Excel workflows.

➡️ Learn more and see examples


🚀 Quick Start

# Install globally (requires .NET 8 SDK)
dotnet tool install --global Sbroenne.ExcelMcp.CLI

# Verify installation
excelcli --version

# Get help
excelcli --help

Update to Latest Version

dotnet tool update --global Sbroenne.ExcelMcp.CLI

Uninstall

dotnet tool uninstall --global Sbroenne.ExcelMcp.CLI

✨ Key Features

🔧 Excel Development Automation

  • Power Query Management - Export, import, update, and version control M code
  • VBA Development - Manage VBA modules, run macros, automated testing
  • Data Model & DAX - Create measures, manage relationships, Power Pivot operations
  • PivotTable Automation - Create, configure, and manage PivotTables programmatically

📊 Data Operations

  • Worksheet Management - Create, rename, copy, delete sheets with tab colors and visibility
  • Range Operations - Read/write values, formulas, formatting, validation
  • Excel Tables - Lifecycle management, filtering, sorting, structured references
  • Connection Management - OLEDB, ODBC, Text, Web connections with testing

🛡️ Production Ready

  • Zero Corruption Risk - Uses Excel's native COM API (not file manipulation)
  • Error Handling - Comprehensive validation and helpful error messages
  • CI/CD Integration - Perfect for automated workflows and testing
  • Windows Native - Optimized for Windows Excel automation

📋 Command Categories

ExcelMcp.CLI provides 150 commands across 13 categories:

Category Commands Examples
Batch Mode 3 batch-begin, batch-commit, batch-list
File Operations 1 create-empty
Worksheets 13 sheet-list, sheet-create, sheet-rename, sheet-set-tab-color
Power Query 9 pq-list, pq-create, pq-export, pq-refresh, pq-update-mcode
Ranges 44 range-get-values, range-set-values, range-copy, range-find, range-merge-cells, range-add-hyperlink
Excel Tables 23 table-create, table-filter, table-sort, table-add-column, table-get-column-format
PivotTables 12 pivot-create-from-range, pivot-add-row-field, pivot-refresh, pivot-delete
QueryTables 8 querytable-list, querytable-get, querytable-refresh, querytable-create-from-connection
Data Model 15 dm-create-measure, dm-create-relationship, dm-refresh
Connections 11 conn-list, conn-import, conn-refresh, conn-test
Named Ranges 6 namedrange-create, namedrange-get, namedrange-set
VBA 5 vba-list, vba-import, vba-run, vba-export

Note: Recent expansion added 41 new commands (33 Range operations, 3 QueryTable methods, 2 Table methods, 3 Batch commands). 7 PivotTable operations are planned for future releases.


⚡ Batch Mode for High Performance

NEW: Batch mode enables 75-90% faster execution for multi-operation workflows by keeping a single Excel instance open.

Perfect for RPA scenarios where you need to make bulk changes to a workbook.

How It Works

# 1. Start a batch session
excelcli batch-begin data.xlsx
# Output: Batch ID: 550e8400-e29b-41d4-a716-446655440000

# 2. Use the batch ID with any commands (all use same Excel instance)
excelcli sheet-create data.xlsx "NewSheet" --batch-id 550e8400-e29b-41d4-a716-446655440000
excelcli pq-list data.xlsx --batch-id 550e8400-e29b-41d4-a716-446655440000
excelcli range-set-values data.xlsx NewSheet A1 "data.csv" --batch-id 550e8400-e29b-41d4-a716-446655440000

# 3. Commit the batch (saves and closes)
excelcli batch-commit 550e8400-e29b-41d4-a716-446655440000

# Or discard changes without saving
excelcli batch-commit 550e8400-e29b-41d4-a716-446655440000 --no-save

Batch Commands

Command Description
batch-begin <file.xlsx> Start batch session, returns batch ID
batch-commit <batch-id> Commit batch (saves by default)
batch-commit <batch-id> --no-save Discard changes
batch-list List all active batch sessions

Benefits

  • 75-90% faster - Single Excel instance for multiple operations
  • Explicit lifecycle - Full control over when to save/discard
  • RPA-friendly - Perfect for automated workflows
  • Backward compatible - All commands work with or without batch mode

💡 Common Use Cases

Power Query Development

# Export all queries for version control
excelcli pq-list data.xlsx
excelcli pq-export data.xlsx "Sales Data" sales-query.pq
excelcli pq-export data.xlsx "Customer Data" customer-query.pq

# Import updated query from file
excelcli pq-import data.xlsx "Sales Data" sales-query-optimized.pq

# Refresh all queries
excelcli pq-refresh data.xlsx "Sales Data"

VBA Module Management

# List all VBA modules
excelcli vba-list macros.xlsm

# Export module for version control
excelcli vba-export macros.xlsm "DataProcessor" processor.vba

# Import updated module
excelcli vba-import macros.xlsm "DataProcessor" processor-v2.vba

# Run a macro with parameters
excelcli vba-run macros.xlsm "ProcessData" "Sheet1" "A1:D100"

Data Model & DAX

# Create a DAX measure
excelcli dm-create-measure sales.xlsx Sales "TotalRevenue" "SUM(Sales[Amount])" Currency

# Create relationship between tables
excelcli dm-create-relationship sales.xlsx Sales CustomerID Customers ID

# List all measures
excelcli dm-list-measures sales.xlsx

# Refresh Data Model
excelcli dm-refresh sales.xlsx

Excel Table Operations

# Create table from range
excelcli table-create data.xlsx Sheet1 SalesTable A1:E100

# Apply filters
excelcli table-apply-filter data.xlsx SalesTable Amount ">1000"
excelcli table-apply-filter-values data.xlsx SalesTable Region "North,South,East"

# Sort by column
excelcli table-sort data.xlsx SalesTable Amount desc

# Add calculated column
excelcli table-add-column data.xlsx SalesTable "Total" 5

PivotTable Automation

# Create PivotTable from range
excelcli pivot-create-from-range sales.xlsx Data A1:D100 Analysis A1 SalesPivot

# Configure fields
excelcli pivot-add-row-field sales.xlsx SalesPivot Region
excelcli pivot-add-column-field sales.xlsx SalesPivot Year
excelcli pivot-add-value-field sales.xlsx SalesPivot Amount Sum "Total Sales"
excelcli pivot-add-filter-field sales.xlsx SalesPivot Category

# Manage PivotTable lifecycle
excelcli pivot-get sales.xlsx SalesPivot
excelcli pivot-list-fields sales.xlsx SalesPivot
excelcli pivot-remove-field sales.xlsx SalesPivot Year
excelcli pivot-delete sales.xlsx SalesPivot

# Create from Data Model (for large datasets)
excelcli pivot-create-from-datamodel sales.xlsx ConsumptionMilestones Analysis A1 MilestonesPivot

# Refresh PivotTable
excelcli pivot-refresh sales.xlsx SalesPivot

Batch Mode for RPA Workflows

# Example: Automated report generation with batch mode

# Start batch session
BATCH_ID=$(excelcli batch-begin report.xlsx | grep "Batch ID:" | cut -d' ' -f3)

# Create multiple sheets (all use same Excel instance - 75-90% faster!)
excelcli sheet-create report.xlsx "Sales" --batch-id $BATCH_ID
excelcli sheet-create report.xlsx "Customers" --batch-id $BATCH_ID
excelcli sheet-create report.xlsx "Summary" --batch-id $BATCH_ID

# Import data
excelcli range-set-values report.xlsx Sales A1 "sales.csv" --batch-id $BATCH_ID
excelcli range-set-values report.xlsx Customers A1 "customers.csv" --batch-id $BATCH_ID

# Add Power Query for transformations
excelcli pq-create report.xlsx "CleanSales" "clean-sales.pq" --batch-id $BATCH_ID

# Create PivotTable
excelcli pivot-create-from-range report.xlsx Sales A1:E1000 Summary A1 SalesPivot --batch-id $BATCH_ID

# Commit all changes at once
excelcli batch-commit $BATCH_ID

# Check active batches
excelcli batch-list

QueryTable Operations

# List all QueryTables in workbook
excelcli querytable-list data.xlsx

# Get QueryTable details
excelcli querytable-get data.xlsx "WebData"

# Refresh QueryTables
excelcli querytable-refresh data.xlsx "WebData"
excelcli querytable-refresh-all data.xlsx

# Delete QueryTable
excelcli querytable-delete data.xlsx "WebData"

Worksheet Management

# List all sheets
excelcli sheet-list workbook.xlsx

# Create and configure sheets
excelcli sheet-create workbook.xlsx "Q1 Data"
excelcli sheet-set-tab-color workbook.xlsx "Q1 Data" 0 255 0  # Green
excelcli sheet-hide workbook.xlsx "Calculations"

# Rename sheets
excelcli sheet-rename workbook.xlsx "Sheet1" "Sales Summary"

Range Operations

# Read range data
excelcli range-get-values data.xlsx Sheet1 A1:D10

# Write CSV data to range
excelcli range-set-values data.xlsx Sheet1 A1:C10 data.csv

# Apply formatting
excelcli range-format data.xlsx Sheet1 A1:E1 --bold --font-size 12 --h-align Center
excelcli range-format data.xlsx Sheet1 D2:D100 --fill-color "#FFFF00"

# Set number formats
excelcli range-set-number-format data.xlsx Sheet1 D2:D100 "$#,##0.00"  # Currency
excelcli range-set-number-format data.xlsx Sheet1 E2:E100 "0.00%"      # Percentage

# Add data validation
excelcli range-validate data.xlsx Sheet1 F2:F100 List "Active,Inactive,Pending"

⚙️ System Requirements

Requirement Details Why Required
Windows OS Windows 10/11 or Server 2016+ COM interop is Windows-specific
Microsoft Excel Excel 2016 or later CLI controls actual Excel application
.NET 8 Runtime Download Required to run .NET global tools

Note: ExcelMcp.CLI controls the actual Excel application via COM interop, not just file formats. This provides access to Power Query, VBA runtime, formula engine, and all Excel features, but requires Excel to be installed.


🔒 VBA Operations Setup (One-Time)

VBA commands require "Trust access to the VBA project object model" to be enabled:

  1. Open Excel
  2. Go to File → Options → Trust Center
  3. Click "Trust Center Settings"
  4. Select "Macro Settings"
  5. Check "✓ Trust access to the VBA project object model"
  6. Click OK twice

This is a security setting that must be manually enabled. ExcelMcp.CLI never modifies security settings automatically.

For macro-enabled workbooks, use .xlsm extension:

excelcli create-empty macros.xlsm
excelcli vba-import macros.xlsm "Module1" code.vba

📖 Complete Documentation


🚧 Troubleshooting

Command Not Found After Installation

# Verify .NET tools path is in your PATH environment variable
dotnet tool list --global

# If excelcli is listed but not found, add .NET tools to PATH:
# The default location is: %USERPROFILE%\.dotnet\tools

Excel Not Found

# Error: "Microsoft Excel is not installed"
# Solution: Install Microsoft Excel (any version 2016+)

VBA Access Denied

# Error: "Programmatic access to Visual Basic Project is not trusted"
# Solution: Enable VBA trust (see VBA Operations Setup above)

Permission Issues

# Run PowerShell/CMD as Administrator if you encounter permission errors
# Or install to user directory: dotnet tool install --global Sbroenne.ExcelMcp.CLI

🛠️ Advanced Usage

Scripting & Automation

# PowerShell script example
$files = Get-ChildItem *.xlsx
foreach ($file in $files) {
    excelcli pq-refresh $file.Name "Sales Data"
    excelcli dm-refresh $file.Name
}

CI/CD Integration

# GitHub Actions example
- name: Install ExcelMcp.CLI
  run: dotnet tool install --global Sbroenne.ExcelMcp.CLI

- name: Process Excel Files
  run: |
    excelcli pq-import data.xlsx "Query1" queries/query1.pq
    excelcli pq-refresh data.xlsx "Query1"

Batch Processing

# Process multiple files
for %f in (*.xlsx) do excelcli sheet-read "%f" "Sheet1" >> output.csv


📄 License

MIT License - see LICENSE for details.


🙋 Support


Built with ❤️ for Excel developers and automation engineers

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
1.4.12 0 11/22/2025
1.4.11 0 11/22/2025
1.4.10 168 11/20/2025
1.4.9 179 11/20/2025
1.4.8 168 11/19/2025
1.4.7 169 11/19/2025
1.4.6 175 11/19/2025
1.4.4 183 11/19/2025
1.4.3 206 11/18/2025
1.4.2 219 11/17/2025
1.4.1 223 11/17/2025
1.4.0 223 11/17/2025
1.3.4 236 11/10/2025
1.3.3 238 11/10/2025
1.3.0 181 11/9/2025
1.2.14 179 11/9/2025
1.2.13 182 11/9/2025
1.2.12 182 11/9/2025
1.0.0 173 11/3/2025