create_workbook_file
Create new spreadsheet files in XLSX, CSV, or ODS format at specified paths for organizing data with customizable sheet names.
Instructions
Create a new empty spreadsheet file at the given path.
The file format is determined by the extension (.xlsx, .csv, or .ods). The file must not already exist. Returns the absolute path of the created file.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | Path where the new file will be created (.csv, .ods, .xlsx). Must not already exist. | |
| sheet_name | No | Name for the initial sheet. Defaults to 'Sheet' for xlsx/ods, 'default' for csv. |
Implementation Reference
- The `create_workbook_file` tool creates an empty spreadsheet file at a specified path, supporting .xlsx, .csv, and .ods formats. It validates that the file does not already exist, initializes the workbook, and saves it.
def create_workbook_file( file: Annotated[str, Field(description=f"Path where the new file will be created ({_EXT_LABEL}). Must not already exist.")], sheet_name: Annotated[str | None, Field(description="Name for the initial sheet. Defaults to 'Sheet' for xlsx/ods, 'default' for csv.")] = None, ) -> str: """Create a new empty spreadsheet file at the given path. The file format is determined by the extension (.xlsx, .csv, or .ods). The file must not already exist. Returns the absolute path of the created file. """ p = Path(file) if p.exists(): raise ValueError(f"File already exists: {file}") wb = create_workbook(file, sheet_name) wb.save(file) return str(p.resolve())