Skip to content

LoadTo silently fails when worksheet with target name already exists #170

@sbroenne

Description

@sbroenne

Issue Description

When using LoadTo to load a Power Query to a worksheet, if a sheet with that name already exists, the operation appears to succeed but the query remains in "Connection Only" mode. This results in silent failure where the user believes data was loaded but it's actually not visible anywhere.

Steps to Reproduce

  1. Create a worksheet named "Milestone Export" in Excel
  2. Create a Power Query named "Milestone Export" (connection-only initially)
  3. Use ExcelMcp to load the query to a worksheet:
    excel_powerquery(action: 'LoadTo', queryName: 'Milestone Export', targetSheet: 'Milestone Export')
    
  4. Expected: Query loads data to the existing "Milestone Export" sheet, or fails with a clear error
  5. Actual: Operation reports success but query remains in "Connection Only" mode with no data loaded

Root Cause

When a sheet with the target name already exists, Excel silently fails to change the query's load configuration. The ExcelMcp tool reports success (based on the COM call succeeding), but the actual load destination isn't changed.

Observed Behavior

LoadTo returns:

"success": true,
"queryName": "Milestone Export",
"loadDestination": "LoadToTable",
"worksheetName": "Milestone Export",
"configurationApplied": true,
"dataRefreshed": true,
"rowsLoaded": 60

However, checking the load configuration shows:

"loadMode": "ConnectionOnly",
"targetSheet": null

The query never actually loaded to the sheet.

Workaround

Delete the target worksheet first, then use LoadTo:

# Delete existing sheet with same name
excel_worksheet(action: 'Delete', sheetName: 'Milestone Export')

# Now LoadTo will work correctly
excel_powerquery(action: 'LoadTo', queryName: 'Milestone Export', targetSheet: 'Milestone Export')

Impact

  • Silent Data Loss: Users believe data is loaded when it isn't
  • Misleading Success Response: ExcelMcp reports success, making the issue hard to detect
  • Confusing UX: No error or warning that the sheet name conflict prevented loading

Proposed Solutions

  1. Auto-delete conflicting sheet: When LoadTo detects a sheet with the target name exists, automatically delete it before loading
  2. Return accurate status: Verify the load configuration was actually changed and return failure if it wasn't
  3. Add overwrite parameter: Let users explicitly control whether to overwrite existing sheets
  4. Better error detection: Check for sheet name conflicts and return a clear error message

Environment

  • ExcelMcp Server: Latest version
  • Excel: Excel 365
  • Scenario: Power Query using LoadTo when target sheet name already exists

Related

This issue was discovered while debugging consumption milestone generation. The query appeared to refresh successfully, but no data was visible because the query remained connection-only due to a pre-existing sheet with the same name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions