Skip to main content
Glama

set_range_values

Set a 2D array of data into a specified Excel range. Define the start cell, sheet name, and file path to populate values efficiently. Ideal for structured data entry in spreadsheets.

Instructions

指定された範囲に2次元配列のデータを設定します

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes対象のExcelファイルの絶対パス
sheetNameYes対象のワークシート名
startCellYesデータ入力を開始するセル位置(例: A1)。ここから右下方向にデータが入力されます
valuesYes2次元配列のデータ。外側の配列が行、内側の配列が列を表します。例: [["商品名", "価格"], ["商品A", 1000]]

Implementation Reference

  • Core handler function that implements the logic to set a 2D array of values into an Excel worksheet starting from a given cell position.
    async function setRangeValues(filePath: string, sheetName: string, startCell: string, values: any[][]): Promise<string> {
      try {
        validateCellAddress(startCell);
        
        if (!Array.isArray(values) || values.length === 0) {
          throw new Error("valuesは空でない2次元配列である必要があります");
        }
        
        // 2次元配列の検証
        for (let i = 0; i < values.length; i++) {
          if (!Array.isArray(values[i])) {
            throw new Error(`${i+1}行目が配列ではありません。2次元配列を指定してください`);
          }
        }
        
        const workbook = await loadWorkbook(filePath);
        const worksheet = workbook.getWorksheet(sheetName);
        if (!worksheet) {
          throw new Error(`ワークシート '${sheetName}' が見つかりません。利用可能なシート: ${getSheetNames(workbook)}`);
        }
        
        const startCellObj = worksheet.getCell(startCell);
        const startRow = startCellObj.row;
        const startCol = startCellObj.col;
        
        for (let i = 0; i < values.length; i++) {
          for (let j = 0; j < values[i].length; j++) {
            worksheet.getCell(startRow + i, startCol + j).value = values[i][j];
          }
        }
        
        await workbook.xlsx.writeFile(filePath);
        
        return `範囲 ${startCell} から ${values.length}行 x ${values[0].length}列 のデータを設定しました。`;
      } catch (error) {
        throw new McpError(ErrorCode.InternalError, `範囲値設定エラー: ${error}`);
      }
    }
  • Zod schema defining the input parameters and validation for the set_range_values tool.
    const SetRangeValuesSchema = z.object({
      filePath: z.string().describe("対象のExcelファイルの絶対パス"),
      sheetName: z.string().describe("対象のワークシート名"),
      startCell: z.string().describe("データ入力を開始するセル位置(例: A1)。ここから右下方向にデータが入力されます"),
      values: z.array(z.array(z.union([z.string(), z.number(), z.boolean()]))).describe("2次元配列のデータ。外側の配列が行、内側の配列が列を表します。例: [[\"商品名\", \"価格\"], [\"商品A\", 1000]]"),
    });
  • src/index.ts:492-495 (registration)
    Registration of the tool in the list_tools response, including name, description, and input schema.
      name: "set_range_values",
      description: "指定された範囲に2次元配列のデータを設定します",
      inputSchema: zodToJsonSchema(SetRangeValuesSchema)
    },
  • src/index.ts:547-550 (registration)
    Tool implementation registration in the toolImplementations map, which handles argument parsing and delegates to the core handler.
    set_range_values: async (args: any) => {
      const { filePath, sheetName, startCell, values } = SetRangeValuesSchema.parse(args);
      return await setRangeValues(filePath, sheetName, startCell, values);
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states what the tool does, not behavioral traits. It doesn't disclose whether this overwrites existing data, requires file permissions, has file size limits, or what happens on success/failure. For a write operation with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence, zero waste. Every word contributes to the core purpose. The description is appropriately sized and front-loaded with the essential action.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a write operation with 4 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what happens to existing data in the range, error conditions, or return values. The schema covers parameter documentation well, but behavioral context is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, providing good documentation for all 4 parameters. The description adds minimal value beyond the schema - it mentions '2次元配列のデータ' which aligns with the values parameter schema, but doesn't provide additional context about parameter interactions or edge cases.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('設定します' - sets) and resource ('2次元配列のデータ' - 2D array data) with the target ('指定された範囲' - specified range). It distinguishes from siblings like set_cell_value (single cell) and get_range_values (read operation), but doesn't explicitly mention Excel/worksheet context which is only in the schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives like set_cell_value (for single cells) or add_worksheet (for creating sheets). The description implies it's for writing 2D arrays to ranges, but doesn't provide explicit comparison or exclusion criteria.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/SuperPyonchiX/excel_mcp_server'

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