Skip to content

Add support for creating Excel Tables programmatically #24

@sbroenne

Description

@sbroenne

Feature Request: Excel Tables + Tool Naming Refactoring (v1.1.0)

Problem

Currently, ExcelMcp does not support creating Excel Tables programmatically. When building Excel files via automation, we need to:

  1. Create worksheets
  2. Populate data
  3. Create Excel Tables from those ranges

Without this, users must manually create tables in Excel Desktop or use unreliable workarounds.

Additionally, MCP tool names have redundant excel_ prefix that can be simplified.


📋 Implementation Plan (v1.1.0)

Phase 1: Tool Naming Refactoring (6-8 hours) - PR #1

Remove redundant excel_ prefix from all 9 MCP tools:

Tools to rename:

  1. excel_filefile
  2. excel_powerquerypowerquery
  3. excel_worksheetworksheet
  4. excel_parameterparameter
  5. excel_cellcell
  6. excel_vbavba
  7. excel_datamodeldatamodel
  8. excel_connectionconnection
  9. excel_versionversion

Phase 2: Excel Tables Implementation (32-39 hours) - PR #2

Complete Excel Tables feature with security built-in:

Core Operations (CRUD):

  • List() - List all tables in workbook
  • Create() - Convert range to table
  • Rename() - Rename existing table
  • Delete() - Convert table back to range
  • GetInfo() - Get table details (columns, rows, style)

CLI Commands:

  • table-list
  • table-create
  • table-rename
  • table-delete
  • table-info

MCP Tool:

  • Tool name: table (clean, no prefix)
  • Actions: list, create, rename, delete, info

Security Built-In:

  • ✅ PathValidator for all file operations
  • ✅ Table name validation (no spaces, reserved names, invalid chars)
  • ✅ Range validation (prevent DOS attacks)
  • ✅ Null-safe HeaderRowRange/DataBodyRange access
  • ✅ Proper COM cleanup after Unlist()

🎯 Use Cases

Power Query Integration

// Power Query references tables by name
let
    Source = Excel.CurrentWorkbook(){[Name="DiscountsTable"]}[Content],
    FilteredRows = Table.SelectRows(Source, each [Active] = "Yes")
in
    FilteredRows

PivotTable Data Sources

Excel Tables auto-expand and provide named references for PivotTables.

Structured References

// Instead of: =VLOOKUP(A2, $B$2:$D$100, 3, FALSE)
// Use: =VLOOKUP([@CustomerID], CustomersTable, 3, FALSE)

🔧 Technical Implementation

Example Usage

CLI:

# Create table
excelcli table-create "sales.xlsx" "Data" "SalesTable" "A1:F100"

# List tables
excelcli table-list "sales.xlsx"

# Get table info
excelcli table-info "sales.xlsx" "SalesTable"

MCP Server:

table({
  action: "create",
  excelPath: "sales.xlsx",
  sheetName: "Data",
  tableName: "SalesTable",
  range: "A1:F100"
})

COM Interop Pattern

// With security built-in
filePath = PathValidator.ValidateExistingFile(filePath, nameof(filePath));
var (isValid, errorMessage) = ValidateTableName(tableName);

var listObject = worksheet.ListObjects.Add(
    1,  // xlSrcRange
    range,
    null,
    1   // xlYes (has headers)
);
listObject.Name = tableName;
listObject.TableStyle = "TableStyleMedium2";

⏱️ Timeline

  • Phase 1: 6-8 hours (Tool Naming)
  • Phase 2: 32-39 hours (Excel Tables)
  • Total: 38-47 hours across 2 PRs

Acceptance Criteria

Phase 1:

  • All 9 MCP tools renamed (no excel_ prefix)
  • server.json updated
  • Documentation updated
  • All existing tests pass

Phase 2:

  • Full CRUD operations on Excel Tables
  • PathValidator in all methods
  • Table name validation (spaces, reserved names, invalid chars)
  • Null-safe access to HeaderRowRange/DataBodyRange
  • COM cleanup after Unlist()
  • Security tests pass (path traversal, name validation)
  • Integration tests pass (full CRUD workflow)
  • OnDemand tests pass (no Excel.exe leaks)
  • Documentation complete

📚 Related

  • Comments: Complete implementation specification in comments below
  • Version: v1.1.0 (non-breaking enhancement)
  • Assigned: GitHub Copilot Coding Agent

Priority: High - Fundamental Excel automation capability for Power Query integration

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions