Skip to main content
Glama
marekrost

mcp-server-spreadsheet

copy_range

Copy a rectangular cell block to another location within a spreadsheet. Moves raw values between sheets or positions, overwriting existing destination data.

Instructions

Copy a rectangular block of cells to another location.

Copies raw values only. The destination can be on the same sheet or a different sheet in the same workbook. Existing values at the destination are overwritten.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesPath to the spreadsheet file
source_rangeYesRange to copy from in A1 notation, e.g. 'A1:C5'
dest_startYesTop-left cell of the destination, e.g. 'E1'. The copied block expands right and down from here.
sheetNoSource sheet name. Defaults to the first sheet if omitted.
dest_sheetNoDestination sheet name. Defaults to the same sheet as the source if omitted.

Implementation Reference

  • The 'copy_range' tool handler, which copies values from a source range to a destination starting cell.
    def copy_range(
        file: Annotated[str, Field(description="Path to the spreadsheet file")],
        source_range: Annotated[str, Field(description="Range to copy from in A1 notation, e.g. 'A1:C5'")],
        dest_start: Annotated[str, Field(description="Top-left cell of the destination, e.g. 'E1'. The copied block expands right and down from here.")],
        sheet: Annotated[str | None, Field(description="Source sheet name. Defaults to the first sheet if omitted.")] = None,
        dest_sheet: Annotated[str | None, Field(description="Destination sheet name. Defaults to the same sheet as the source if omitted.")] = None,
    ) -> str:
        """Copy a rectangular block of cells to another location.
    
        Copies raw values only. The destination can be on the same sheet or
        a different sheet in the same workbook. Existing values at the
        destination are overwritten.
        """
        wb = load_workbook(file)
        src_ws = _resolve_sheet(wb, sheet)
        dst_ws = _resolve_sheet(wb, dest_sheet) if dest_sheet else src_ws
    
        min_col, min_row, max_col, max_row = parse_range(source_range)
        dest_row, dest_col = parse_cell(dest_start)
    
        for r in range(min_row, max_row + 1):
            for c in range(min_col, max_col + 1):
                val = src_ws.cell_value(r, c)
                dst_ws.set_cell(
                    dest_row + (r - min_row),
                    dest_col + (c - min_col),
                    val,
                )
        wb.save(file)
        return f"Copied {source_range} to {dest_start}"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/marekrost/mcp-server-spreadsheet'

If you have feedback or need assistance with the MCP directory API, please join our Discord server