{"data":{"slug":"github-claude-office-skills-skills-excel-automation-fc8b7f7d45ca","title":"Excel Automation Skill","summary":"Advanced Excel automation using xlwings for live interaction, VBA execution, and complex workflows.","url":"https:\/\/skillshunter.net\/skills\/github-claude-office-skills-skills-excel-automation-fc8b7f7d45ca","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-claude-office-skills-skills-excel-automation-fc8b7f7d45ca","markdown_url":"https:\/\/skillshunter.net\/skills\/github-claude-office-skills-skills-excel-automation-fc8b7f7d45ca.md","download_url":"https:\/\/skillshunter.net\/skills\/github-claude-office-skills-skills-excel-automation-fc8b7f7d45ca\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"This skill requires Excel to be installed and may have limited support on macOS for certain features. VBA execution requires proper trust settings in Excel.","instructions":"---\n# \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n# CLAUDE OFFICE SKILL - Enhanced Metadata v2.0\n# \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\n\n# Basic Information\nname: excel-automation\ndescription: \">\"\nversion: \"1.0\"\nauthor: claude-office-skills\nlicense: MIT\n\n# Categorization\ncategory: spreadsheet\ntags:\n  - excel\n  - automation\n  - macro\n  - workflow\ndepartment: All\n\n# AI Model Compatibility\nmodels:\n  recommended:\n    - claude-sonnet-4\n    - claude-opus-4\n  compatible:\n    - claude-3-5-sonnet\n    - gpt-4\n    - gpt-4o\n\n# MCP Tools Integration\nmcp:\n  server: office-mcp\n  tools:\n    - read_xlsx\n    - create_xlsx\n    - apply_formula\n    - pivot_table\n\n# Skill Capabilities\ncapabilities:\n  - automation\n  - data_processing\n  - reporting\n\n# Language Support\nlanguages:\n  - en\n  - zh\n---\n\n# Excel Automation Skill\n\n## Overview\n\nThis skill enables advanced Excel automation using **xlwings** - a library that can interact with live Excel instances. Unlike openpyxl (file-only), xlwings can control Excel in real-time, execute VBA, update dashboards, and automate complex workflows.\n\n## How to Use\n\n1. Describe the Excel automation task you need\n2. Specify if you need live Excel interaction or file processing\n3. I'll generate xlwings code and execute it\n\n**Example prompts:**\n- \"Update this live Excel dashboard with new data\"\n- \"Run this VBA macro and get the results\"\n- \"Create an Excel add-in for data validation\"\n- \"Automate monthly report generation with live charts\"\n\n## Domain Knowledge\n\n### xlwings vs openpyxl\n\n| Feature | xlwings | openpyxl |\n|---------|---------|----------|\n| Requires Excel | Yes | No |\n| Live interaction | Yes | No |\n| VBA execution | Yes | No |\n| Speed (large files) | Fast | Slow |\n| Server deployment | Limited | Easy |\n\n### xlwings Fundamentals\n\n```python\nimport xlwings as xw\n\n# Connect to active Excel workbook\nwb = xw.Book.caller()  # From Excel add-in\nwb = xw.books.active   # Active workbook\n\n# Open specific file\nwb = xw.Book('path\/to\/file.xlsx')\n\n# Create new workbook\nwb = xw.Book()\n\n# Get sheet\nsheet = wb.sheets['Sheet1']\nsheet = wb.sheets[0]\n```\n\n### Working with Ranges\n\n#### Reading and Writing\n```python\n# Single cell\nsheet['A1'].value = 'Hello'\nvalue = sheet['A1'].value\n\n# Range\nsheet['A1:C3'].value = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\ndata = sheet['A1:C3'].value  # Returns list of lists\n\n# Named range\nsheet['MyRange'].value = 'Named data'\n\n# Expand range (detect data boundaries)\nsheet['A1'].expand().value  # All connected data\nsheet['A1'].expand('table').value  # Table format\n```\n\n#### Dynamic Ranges\n```python\n# Current region (like Ctrl+Shift+End)\ndata = sheet['A1'].current_region.value\n\n# Used range\nused = sheet.used_range.value\n\n# Last row with data\nlast_row = sheet['A1'].end('down').row\n\n# Resize range\nrng = sheet['A1'].resize(10, 5)  # 10 rows, 5 columns\n```\n\n### Formatting\n```python\n# Font\nsheet['A1'].font.bold = True\nsheet['A1'].font.size = 14\nsheet['A1'].font.color = (255, 0, 0)  # RGB red\n\n# Fill\nsheet['A1'].color = (255, 255, 0)  # Yellow background\n\n# Number format\nsheet['B1'].number_format = '$#,##0.00'\n\n# Column width\nsheet['A:A'].column_width = 20\n\n# Row height\nsheet['1:1'].row_height = 30\n\n# Autofit\nsheet['A:D'].autofit()\n```\n\n### Excel Features\n\n#### Charts\n```python\n# Add chart\nchart = sheet.charts.add(left=100, top=100, width=400, height=250)\nchart.set_source_data(sheet['A1:B10'])\nchart.chart_type = 'column_clustered'\nchart.name = 'Sales Chart'\n\n# Modify existing chart\nchart = sheet.charts['Sales Chart']\nchart.chart_type = 'line'\n```\n\n#### Tables\n```python\n# Create Excel Table\nrng = sheet['A1'].expand()\ntable = sheet.tables.add(source=rng, name='SalesTable')\n\n# Refresh table\ntable.refresh()\n\n# Access table data\ntable_data = table.data_body_range.value\n```\n\n#### Pictures\n```python\n# Add picture\nsheet.pictures.add('logo.png', left=10, top=10, width=100, height=50)\n\n# Update picture from matplotlib\nimport matplotlib.pyplot as plt\nfig, ax = plt.subplots()\nax.plot([1, 2, 3], [1, 4, 9])\nsheet.pictures.add(fig, name='MyPlot', update=True)\n```\n\n### VBA Integration\n```python\n# Run VBA macro\nwb.macro('MacroName')()\n\n# With arguments\nwb.macro('MyMacro')('arg1', 'arg2')\n\n# Get return value\nresult = wb.macro('CalculateTotal')(100, 200)\n\n# Access VBA module\nvb_code = wb.api.VBProject.VBComponents('Module1').CodeModule.Lines(1, 10)\n```\n\n### User Defined Functions (UDFs)\n```python\n# Define a UDF (in Python file)\nimport xlwings as xw\n\n@xw.func\ndef my_sum(x, y):\n    \"\"\"Add two numbers\"\"\"\n    return x + y\n\n@xw.func\n@xw.arg('data', ndim=2)\ndef my_array_func(data):\n    \"\"\"Process array data\"\"\"\n    import numpy as np\n    return np.sum(data)\n\n# These become Excel functions: =my_sum(A1, B1)\n```\n\n### Application Control\n```python\n# Excel application settings\napp = xw.apps.active\napp.screen_updating = False  # Speed up\napp.calculation = 'manual'   # Manual calc\napp.display_alerts = False   # Suppress dialogs\n\n# Perform operations...\n\n# Restore\napp.screen_updating = True\napp.calculation = 'automatic'\napp.display_alerts = True\n```\n\n## Best Practices\n\n1. **Disable Screen Updating**: For batch operations\n2. **Use Arrays**: Read\/write entire ranges, not cell-by-cell\n3. **Manual Calculation**: Turn off auto-calc during data loading\n4. **Close Connections**: Properly close workbooks when done\n5. **Error Handling**: Handle Excel not being installed\n\n## Common Patterns\n\n### Performance Optimization\n```python\nimport xlwings as xw\n\ndef batch_update(data, workbook_path):\n    app = xw.App(visible=False)\n    try:\n        app.screen_updating = False\n        app.calculation = 'manual'\n        \n        wb = app.books.open(workbook_path)\n        sheet = wb.sheets['Data']\n        \n        # Write all data at once\n        sheet['A1'].value = data\n        \n        app.calculation = 'automatic'\n        wb.save()\n    finally:\n        wb.close()\n        app.quit()\n```\n\n### Dashboard Update\n```python\ndef update_dashboard(data_dict):\n    wb = xw.books.active\n    \n    # Update data sheet\n    data_sheet = wb.sheets['Data']\n    for name, values in data_dict.items():\n        data_sheet[name].value = values\n    \n    # Refresh all charts\n    dashboard = wb.sheets['Dashboard']\n    for chart in dashboard.charts:\n        chart.refresh()\n    \n    # Update timestamp\n    from datetime import datetime\n    dashboard['A1'].value = f'Last Updated: {datetime.now()}'\n```\n\n### Report Generator\n```python\ndef generate_monthly_report(month, data):\n    template = xw.Book('template.xlsx')\n    \n    # Fill data\n    sheet = template.sheets['Report']\n    sheet['B2'].value = month\n    sheet['A5'].value = data\n    \n    # Run calculations\n    template.app.calculate()\n    \n    # Export to PDF\n    sheet.api.ExportAsFixedFormat(0, f'report_{month}.pdf')\n    \n    template.save(f'report_{month}.xlsx')\n```\n\n## Examples\n\n### Example 1: Live Dashboard Update\n```python\nimport xlwings as xw\nimport pandas as pd\nfrom datetime import datetime\n\n# Connect to running Excel\nwb = xw.books.active\ndashboard = wb.sheets['Dashboard']\ndata_sheet = wb.sheets['Data']\n\n# Fetch new data (simulated)\nnew_data = pd.DataFrame({\n    'Date': pd.date_range('2024-01-01', periods=30),\n    'Sales': [1000 + i*50 for i in range(30)],\n    'Costs': [600 + i*30 for i in range(30)]\n})\n\n# Update data sheet\ndata_sheet['A1'].value = new_data\n\n# Calculate profit\ndata_sheet['D1'].value = 'Profit'\ndata_sheet['D2'].value = '=B2-C2'\ndata_sheet['D2'].expand('down').value = data_sheet['D2'].formula\n\n# Update KPIs on dashboard\ndashboard['B2'].value = new_data['Sales'].sum()\ndashboard['B3'].value = new_data['Costs'].sum()\ndashboard['B4'].value = new_data['Sales'].sum() - new_data['Costs'].sum()\ndashboard['A1'].value = f'Updated: {datetime.now().strftime(\"%Y-%m-%d %H:%M\")}'\n\n# Refresh charts\nfor chart in dashboard.charts:\n    chart.api.Refresh()\n\nprint(\"Dashboard updated!\")\n```\n\n### Example 2: Batch Processing Multiple Files\n```python\nimport xlwings as xw\nfrom pathlib import Path\n\ndef process_sales_files(folder_path, output_path):\n    \"\"\"Consolidate multiple Excel files into one summary.\"\"\"\n    \n    app = xw.App(visible=False)\n    app.screen_updating = False\n    \n    try:\n        # Create summary workbook\n        summary_wb = xw.Book()\n        summary_sheet = summary_wb.sheets[0]\n        summary_sheet.name = 'Consolidated'\n        \n        headers = ['File', 'Total Sales', 'Total Units', 'Avg Price']\n        summary_sheet['A1'].value = headers\n        \n        row = 2\n        for file in Path(folder_path).glob('*.xlsx'):\n            wb = app.books.open(str(file))\n            data_sheet = wb.sheets['Sales']\n            \n            # Extract summary\n            total_sales = data_sheet['B:B'].api.SpecialCells(11).Value  # xlCellTypeConstants\n            total_units = data_sheet['C:C'].api.SpecialCells(11).Value\n            \n            # Calculate and write\n            summary_sheet[f'A{row}'].value = file.name\n            summary_sheet[f'B{row}'].value = sum(total_sales) if isinstance(total_sales, (list, tuple)) else total_sales\n            summary_sheet[f'C{row}'].value = sum(total_units) if isinstance(total_units, (list, tuple)) else total_units\n            summary_sheet[f'D{row}'].value = f'=B{row}\/C{row}'\n            \n            wb.close()\n            row += 1\n        \n        # Format summary\n        summary_sheet['A1:D1'].font.bold = True\n        summary_sheet['B:D'].number_format = '$#,##0.00'\n        summary_sheet['A:D'].autofit()\n        \n        summary_wb.save(output_path)\n        \n    finally:\n        app.quit()\n    \n    print(f\"Consolidated {row-2} files to {output_path}\")\n\n# Usage\nprocess_sales_files('\/path\/to\/sales\/', 'consolidated_sales.xlsx')\n```\n\n### Example 3: Excel Add-in with UDFs\n```python\n# myudfs.py - Place in xlwings project\n\nimport xlwings as xw\nimport numpy as np\n\n@xw.func\n@xw.arg('data', pd.DataFrame, index=False, header=False)\n@xw.ret(expand='table')\ndef GROWTH_RATE(data):\n    \"\"\"Calculate period-over-period growth rate\"\"\"\n    values = data.iloc[:, 0].values\n    growth = np.diff(values) \/ values[:-1] * 100\n    return [['Growth %']] + [[g] for g in growth]\n\n@xw.func\n@xw.arg('range1', np.array, ndim=2)\n@xw.arg('range2', np.array, ndim=2)\ndef CORRELATION(range1, range2):\n    \"\"\"Calculate correlation between two ranges\"\"\"\n    return np.corrcoef(range1.flatten(), range2.flatten())[0, 1]\n\n@xw.func\ndef SENTIMENT(text):\n    \"\"\"Basic sentiment analysis (placeholder)\"\"\"\n    positive = ['good', 'great', 'excellent', 'amazing']\n    negative = ['bad', 'poor', 'terrible', 'awful']\n    \n    text_lower = text.lower()\n    pos_count = sum(word in text_lower for word in positive)\n    neg_count = sum(word in text_lower for word in negative)\n    \n    if pos_count > neg_count:\n        return 'Positive'\n    elif neg_count > pos_count:\n        return 'Negative'\n    return 'Neutral'\n```\n\n## Limitations\n\n- Requires Excel to be installed\n- Limited support on macOS for some features\n- Not suitable for server-side processing\n- VBA features require trust settings\n- Performance varies with Excel version\n\n## Installation\n\n```bash\npip install xlwings\n\n# For add-in functionality\nxlwings addin install\n```\n\n## Resources\n\n- [xlwings Documentation](https:\/\/docs.xlwings.org\/)\n- [GitHub Repository](https:\/\/github.com\/xlwings\/xlwings)\n- [UDF Tutorial](https:\/\/docs.xlwings.org\/en\/stable\/udfs.html)\n- [Excel VBA Reference](https:\/\/docs.microsoft.com\/en-us\/office\/vba\/api\/overview\/excel)\n","use_cases":["Update live Excel dashboards with new data","Run VBA macros and retrieve results","Create Excel add-ins for data validation","Automate monthly report generation with live charts"],"limitations":["Requires Excel to be installed","Limited support on macOS for some features","Not suitable for server-side processing","VBA features require trust settings","Performance varies with Excel version"],"compatibility":[],"setup_tip":"```bash\npip install xlwings\n\n# For add-in functionality\nxlwings addin install\n```","sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/claude-office-skills\/skills\/blob\/9c4c7d5cd2813a8936bf2c9fdb174ea883b85a11\/excel-automation\/SKILL.md","source_commit":"9c4c7d5cd2813a8936bf2c9fdb174ea883b85a11","license":"MIT","version":null,"listing_approved_at":"2026-11-15","created_at":"2026-11-14T16:59:17.000000Z","updated_at":"2026-11-15T18:51:31.000000Z","seo_title":"Excel Automation Skill for Live Data Updates","seo_description":"Automate Excel tasks with live interaction, VBA execution, and complex workflows using xlwings.","seo_keywords":["Excel automation","Live Excel updates","VBA macro execution","Excel dashboard automation","xlwings integration"]}}