Skip to main content
Glama

format_cell

Set cell formatting in Excel files, including font styles, fill colors, and borders, for precise customization of spreadsheets.

Instructions

セルの書式(フォント、塗りつぶし、罫線)を設定します

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cellYesセル位置(例: A1)
filePathYesExcelファイルのパス
formatYesセルの書式設定
sheetNameYesワークシート名

Implementation Reference

  • The core handler function that loads the Excel workbook, retrieves the worksheet and cell, applies font, fill, and border formatting using ExcelJS, saves the file, and returns a success message.
    async function formatCell(filePath: string, sheetName: string, cell: string, format: any): Promise<string> { try { const workbook = await loadWorkbook(filePath); const worksheet = workbook.getWorksheet(sheetName); if (!worksheet) { throw new Error(`ワークシート '${sheetName}' が見つかりません。`); } const targetCell = worksheet.getCell(cell); // フォント設定 if (format.font) { const fontFormat: any = {}; if (format.font.bold !== undefined) fontFormat.bold = format.font.bold; if (format.font.size) fontFormat.size = format.font.size; if (format.font.color) { fontFormat.color = { argb: format.font.color }; } targetCell.font = fontFormat; } // 背景色設定 if (format.fill) { if (format.fill.type === 'pattern') { const fillFormat: any = { type: 'pattern', pattern: format.fill.pattern || 'solid' }; if (format.fill.fgColor) { fillFormat.fgColor = { argb: format.fill.fgColor }; } if (format.fill.bgColor) { fillFormat.bgColor = { argb: format.fill.bgColor }; } targetCell.fill = fillFormat; } else { // 簡単な背景色設定 targetCell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: format.fill.fgColor || format.fill } }; } } // 罫線設定 if (format.border) { targetCell.border = format.border; } await workbook.xlsx.writeFile(filePath); return `セル ${cell} の書式を設定しました。`; } catch (error) { throw new McpError(ErrorCode.InternalError, `セル書式設定エラー: ${error}`); } }
  • Zod schema defining the input structure for the format_cell tool, including filePath, sheetName, cell, and detailed format options for font, fill, and border.
    const FormatCellSchema = z.object({ filePath: z.string().describe("Excelファイルのパス"), sheetName: z.string().describe("ワークシート名"), cell: z.string().describe("セル位置(例: A1)"), format: z.object({ font: z.object({ bold: z.boolean().optional().describe("太字設定"), italic: z.boolean().optional().describe("斜体設定"), size: z.number().optional().describe("フォントサイズ"), color: z.string().optional().describe("フォント色(ARGB形式)"), }).optional().describe("フォント設定"), fill: z.object({ type: z.literal("pattern").describe("塗りつぶしタイプ"), pattern: z.string().describe("パターン(solid等)"), fgColor: z.string().describe("前景色(ARGB形式)"), }).optional().describe("塗りつぶし設定"), border: z.object({ top: z.object({ style: z.string(), color: z.string() }).optional(), left: z.object({ style: z.string(), color: z.string() }).optional(), bottom: z.object({ style: z.string(), color: z.string() }).optional(), right: z.object({ style: z.string(), color: z.string() }).optional(), }).optional().describe("罫線設定"), }).describe("セルの書式設定"), });
  • src/index.ts:501-505 (registration)
    Tool registration in the ListTools response, providing name, description, and input schema reference.
    { name: "format_cell", description: "セルの書式(フォント、塗りつぶし、罫線)を設定します", inputSchema: zodToJsonSchema(FormatCellSchema) },
  • src/index.ts:555-558 (registration)
    Wrapper function in the toolImplementations map that parses input arguments using the schema and delegates to the formatCell handler. Used by the CallToolRequestSchema handler.
    format_cell: async (args: any) => { const { filePath, sheetName, cell, format } = FormatCellSchema.parse(args); return await formatCell(filePath, sheetName, cell, format); },

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