Feat: Add create_excel_table function for native Excel table support. Closes #34

This commit is contained in:
Haris Musa
2025-06-10 22:40:59 +05:00
parent de38958edc
commit 4d5b53379a
3 changed files with 118 additions and 0 deletions

View File

@ -25,6 +25,7 @@ from excel_mcp.chart import create_chart_in_sheet as create_chart_impl
from excel_mcp.workbook import get_workbook_info
from excel_mcp.data import write_data
from excel_mcp.pivot import create_pivot_table as create_pivot_table_impl
from excel_mcp.tables import create_excel_table as create_table_impl
from excel_mcp.sheet import (
copy_sheet,
delete_sheet,
@ -350,6 +351,31 @@ def create_pivot_table(
logger.error(f"Error creating pivot table: {e}")
raise
@mcp.tool()
def create_table(
filepath: str,
sheet_name: str,
data_range: str,
table_name: str = None,
table_style: str = "TableStyleMedium9"
) -> str:
"""Creates a native Excel table from a specified range of data."""
try:
full_path = get_excel_path(filepath)
result = create_table_impl(
filepath=full_path,
sheet_name=sheet_name,
data_range=data_range,
table_name=table_name,
table_style=table_style
)
return result["message"]
except DataError as e:
return f"Error: {str(e)}"
except Exception as e:
logger.error(f"Error creating table: {e}")
raise
@mcp.tool()
def copy_worksheet(
filepath: str,