Skip to content

Commit 7ad8487

Browse files
authored
Merge pull request #39 from ncdcdev/feat/remove-dead-include-formatting-param
refactor: 未使用のinclude_formattingパラメータを削除
2 parents 68d1f81 + af57d3c commit 7ad8487

9 files changed

Lines changed: 28 additions & 156 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI
22

33
on:
44
pull_request:
5-
branches: [ main ]
5+
branches: [ main, feat/refine-excel-reading ]
66
push:
77
branches: [ main ]
88

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ Two authentication methods are supported:
3535
- Read or search Excel files in SharePoint
3636
- Search mode: find cells containing specific text with `query` parameter
3737
- Read mode: get data from specific sheets/ranges with `sheet` and `cell_range` parameters
38-
- Response includes data in `rows` and structure info (`freeze_panes`, `merged_ranges`) when available
39-
- Default: value + coordinate (structural info such as merged ranges is included when present)
40-
- Optional: include_formatting currently does not change the output; structural info is still included only when present
38+
- Response includes cell data in `rows` (value and coordinate) and structural information when available
39+
- Structural info: sheet name, dimensions, freeze_panes (when present), merged_ranges (when merged cells exist)
4140
- No Excel Services dependency - uses direct file download + openpyxl parsing
4241

4342
### OneDrive Support

README_ja.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ stdioとHTTPの両方のトランスポートに対応しています。
3535
- SharePoint上のExcelファイルの読み取りと検索
3636
- 検索モード: `query`パラメータで特定テキストを含むセルを検索
3737
- 読み取りモード: `sheet``cell_range`パラメータで特定シート/範囲を取得
38-
- 構造情報(`freeze_panes`)とデータを `rows` で常に返却し、結合セルがある場合は `merged_ranges` も含めて返却
39-
- デフォルト: 値と座標のみ(結合セルがある場合は merged / merged_ranges を追加)
40-
- オプション: include_formatting を指定しても返却内容(値・座標・結合セル情報など)は変わらない(結合セル情報は結合セルが存在する場合にのみ付与)
38+
- レスポンスには`rows`内のセルデータ(値と座標)と構造情報(利用可能な場合)を含む
39+
- 構造情報: シート名、dimensions、freeze_panes(存在する場合)、merged_ranges(結合セルが存在する場合)
4140
- Excel Services不要 - 直接ファイルダウンロード+openpyxl解析方式
4241

4342
### OneDrive対応

docs/usage.md

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ The `sharepoint_excel` tool allows you to read and search Excel files in SharePo
208208
| `query` | str \| None | None | Search keyword (enables search mode) |
209209
| `sheet` | str \| None | None | Sheet name (get specific sheet only) |
210210
| `cell_range` | str \| None | None | Cell range (e.g., "A1:D10") |
211-
| `include_formatting` | bool | False | Does not change the output currently (merged info is always included when present) |
212211

213212
### Basic Workflow
214213

@@ -276,19 +275,6 @@ result = sharepoint_excel(
276275
)
277276
```
278277

279-
#### 5. include_formatting flag (no output changes yet)
280-
```python
281-
# include_formatting flag (currently does not change output)
282-
result = sharepoint_excel(
283-
file_path="/sites/finance/Shared Documents/report.xlsx",
284-
sheet="Sheet1",
285-
include_formatting=True
286-
)
287-
```
288-
289-
Note: `include_formatting=true` currently does not return colors/width/height/types.
290-
Merged cell info (`merged` / `merged_ranges`) is always included when present.
291-
292278
### JSON Output Format
293279

294280
#### Read Mode (Default)
@@ -336,10 +322,9 @@ Merged cell info (`merged` / `merged_ranges`) is always included when present.
336322
}
337323
```
338324

339-
#### Formatting (include_formatting behavior)
325+
#### Merged Cells
340326

341-
In the current implementation, `include_formatting=true` does not change the output.
342-
Merged cell info (`merged` / `merged_ranges`) is included regardless of `include_formatting`.
327+
When merged cells exist, the response includes merged cell information:
343328

344329
```json
345330
{
@@ -380,12 +365,10 @@ Merged cell info (`merged` / `merged_ranges`) is included regardless of `include
380365
- **value**: Cell value (string, number, date, formula, etc.)
381366
- **coordinate**: Cell position (e.g., "A1", "B2")
382367

383-
**When merged cells exist (included regardless of include_formatting):**
368+
**When merged cells exist:**
384369
- **merged**: Merged cell information (range, position)
385370
- **merged_ranges**: Merged ranges list per sheet (range + anchor info)
386371

387-
Note: `include_formatting` currently does not add formatting fields.
388-
389372
### Additional Metadata
390373

391374
Depending on the request, the response can include metadata such as `response_kind`, `data_included`, `requested_sheet`, `requested_range`, `freeze_panes`, `frozen_rows`, `frozen_cols`, `effective_range`, `sheet_resolution`, and `available_sheets`.

docs/usage_ja.md

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ results = sharepoint_docs_search(
208208
| `query` | str \| None | None | 検索キーワード(検索モードを有効化) |
209209
| `sheet` | str \| None | None | シート名(特定シートのみ取得) |
210210
| `cell_range` | str \| None | None | セル範囲(例: "A1:D10") |
211-
| `include_formatting` | bool | False | 指定しても返却内容は変わらない(結合セル情報は常に含まれる) |
212211

213212
### 基本的なワークフロー
214213

@@ -276,19 +275,6 @@ result = sharepoint_excel(
276275
)
277276
```
278277

279-
#### 5. include_formatting の指定(現状は返却内容は変わらない)
280-
```python
281-
# include_formatting を指定(現状は返却内容は変わらない)
282-
result = sharepoint_excel(
283-
file_path="/sites/finance/Shared Documents/report.xlsx",
284-
sheet="Sheet1",
285-
include_formatting=True
286-
)
287-
```
288-
289-
※ 現状 `include_formatting=true` を指定しても、色/幅/高さ/型などの書式情報は返しません。
290-
結合セル情報(`merged` / `merged_ranges`)は、シート内に結合セルがある場合に含まれます。
291-
292278
### JSON出力形式
293279

294280
#### 読み取りモード(デフォルト)
@@ -336,10 +322,9 @@ result = sharepoint_excel(
336322
}
337323
```
338324

339-
#### 書式情報(include_formatting の挙動)
325+
#### 結合セル
340326

341-
現在の実装では `include_formatting=true` を指定しても返却内容は変わりません。
342-
結合セル情報(`merged` / `merged_ranges`)は `include_formatting` の有無に関係なく返ります。
327+
結合セルが存在する場合、レスポンスには結合セル情報が含まれます:
343328

344329
```json
345330
{
@@ -380,12 +365,10 @@ result = sharepoint_excel(
380365
- **value**: セル値(文字列、数値、日付、数式など)
381366
- **coordinate**: セル位置(例: "A1"、"B2")
382367

383-
**結合セルがある場合(include_formattingに関係なく返る)**
368+
**結合セルがある場合**
384369
- **merged**: 結合セル情報(範囲、位置)
385370
- **merged_ranges**: シート内の結合範囲一覧(範囲とアンカー情報)
386371

387-
`include_formatting` は指定しても返却内容は変わりません(追加の書式情報は返さない)。
388-
389372
### 追加で返るメタ情報
390373

391374
レスポンスには必要に応じて `response_kind` / `data_included` / `requested_sheet` / `requested_range` / `freeze_panes` / `frozen_rows` / `frozen_cols` / `effective_range` / `sheet_resolution` / `available_sheets` などのメタ情報が含まれます。
@@ -428,7 +411,7 @@ data = sharepoint_excel(file_path=file_path, sheet="Sheet1", cell_range="A1:D20"
428411

429412
**結合セルの確認**
430413
```python
431-
# Excelデータを取得(include_formattingの有無に関係なく結合情報が含まれる
414+
# Excelデータを取得(結合セルがある場合は結合情報が含まれる
432415
json_data = sharepoint_excel(file_path=file_path)
433416
data = json.loads(json_data)
434417

src/server.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ def sharepoint_excel(
453453
query: str | None = None,
454454
sheet: str | None = None,
455455
cell_range: str | None = None,
456-
include_formatting: bool = False,
457456
ctx: Context | None = None,
458457
) -> str:
459458
"""
@@ -464,19 +463,14 @@ def sharepoint_excel(
464463
query: 検索キーワード(指定すると検索モード)
465464
sheet: シート名(特定シートのみ取得)
466465
cell_range: セル範囲(例: "A1:D10")
467-
include_formatting: 書式情報を含めるか
468-
現状は指定しても返却内容は変わらない
469-
※結合セル情報(merged / merged_ranges)は常に含まれる
470-
※追加の書式情報(data_type / fill / width / height)は返さない
471466
ctx: FastMCP context (injected automatically)
472467
473468
Returns:
474469
JSON文字列
475470
"""
476471
logging.info(
477472
f"SharePoint Excel operation: {file_path} "
478-
f"(query={query}, sheet={sheet}, cell_range={cell_range}, "
479-
f"include_formatting={include_formatting})"
473+
f"(query={query}, sheet={sheet}, cell_range={cell_range})"
480474
)
481475

482476
try:
@@ -493,7 +487,6 @@ def sharepoint_excel(
493487
# 読み取りモード
494488
return parser.parse_to_json(
495489
file_path,
496-
include_formatting=include_formatting,
497490
sheet_name=sheet,
498491
cell_range=cell_range,
499492
)
@@ -532,14 +525,13 @@ def register_tools():
532525
if config.is_tool_enabled("sharepoint_excel"):
533526
mcp.tool(
534527
description=(
535-
"Read or search Excel file in SharePoint. "
536-
"Use 'query' parameter to search for specific content and find cell locations. "
537-
"Use 'sheet' and 'cell_range' parameters to read specific sections. "
538-
"The response includes structure info (sheet name, dimensions, and, when present, freeze_panes and merged_ranges) and data in 'rows'. "
539-
"Merged cell info is included when present. "
540-
"'include_formatting' currently does not change the output. "
541-
"Workflow: 1) Search with query to find relevant cells, "
542-
"2) Read specific cell_range based on search results."
528+
"Read or search Excel files in SharePoint. "
529+
"Search mode: use 'query' parameter to find cells containing specific text (returns cell locations). "
530+
"Read mode: use 'sheet' and 'cell_range' parameters to retrieve data from specific sections. "
531+
"Response includes cell data in 'rows' (value and coordinate) and structural information "
532+
"(sheet name, dimensions, freeze_panes when present, merged_ranges when merged cells exist). "
533+
"Recommended workflow: 1) Search with query to locate relevant content, "
534+
"2) Read specific range based on search results."
543535
)
544536
)(sharepoint_excel)
545537
logging.info("Registered tool: sharepoint_excel")

src/sharepoint_excel.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def search_cells(
104104
def parse_to_json(
105105
self,
106106
file_path: str,
107-
include_formatting: bool = False,
108107
sheet_name: str | None = None,
109108
cell_range: str | None = None,
110109
) -> str:
@@ -113,20 +112,17 @@ def parse_to_json(
113112
114113
Args:
115114
file_path: Excelファイルのパス
116-
include_formatting: 書式情報を含めるかどうか
117-
現状は指定しても返却内容は変わらない。
118-
- value / coordinate は常に返す
119-
- 結合セルがある場合は merged を追加し、merged_ranges を返す
120-
※ data_type / fill / width / height は返さない
121115
sheet_name: 特定シートのみ取得(Noneで全シート)
122116
cell_range: セル範囲指定(例: "A1:D10")
123117
124118
Returns:
125-
JSON文字列(全シート・全セルのデータ)
119+
JSON文字列
120+
- 各セルのデータ: value(値)、coordinate(座標)
121+
- 構造情報: シート名、dimensions(範囲)
122+
- 条件付き構造情報: freeze_panes(存在する場合)、merged_ranges(結合セルが存在する場合)
126123
"""
127124
logger.info(
128-
f"Parsing Excel file: {file_path} "
129-
f"(include_formatting={include_formatting}, sheet={sheet_name}, range={cell_range})"
125+
f"Parsing Excel file: {file_path} (sheet={sheet_name}, range={cell_range})"
130126
)
131127

132128
try:
@@ -202,7 +198,6 @@ def parse_to_json(
202198
sheet = workbook[name]
203199
sheet_data = self._parse_sheet(
204200
sheet,
205-
include_formatting,
206201
cell_range,
207202
)
208203
result["sheets"].append(sheet_data)
@@ -291,15 +286,13 @@ def _scan_sheet(
291286
def _parse_sheet(
292287
self,
293288
sheet,
294-
include_formatting: bool,
295289
cell_range: str | None = None,
296290
) -> dict[str, Any]:
297291
"""
298292
シートを解析してdict形式で返す
299293
300294
Args:
301295
sheet: openpyxl Worksheet
302-
include_formatting: 書式情報を含めるかどうか
303296
cell_range: セル範囲指定(例: "A1:D10")
304297
305298
Returns:
@@ -391,7 +384,6 @@ def _parse_sheet(
391384
all_rows.extend(
392385
self._parse_rows(
393386
rows_to_process,
394-
include_formatting,
395387
merged_cell_map,
396388
merged_anchor_value_map,
397389
)
@@ -419,7 +411,6 @@ def _parse_sheet(
419411
all_rows.extend(
420412
self._parse_rows(
421413
rows_to_process,
422-
include_formatting,
423414
merged_cell_map,
424415
merged_anchor_value_map,
425416
)
@@ -601,7 +592,6 @@ def _expand_axis_range(self, range_str: str) -> str:
601592
def _parse_cell(
602593
self,
603594
cell,
604-
include_formatting: bool,
605595
merged_cell_map: dict[str, str] | None = None,
606596
merged_anchor_value_map: dict[str, Any] | None = None,
607597
) -> dict[str, Any]:
@@ -610,7 +600,6 @@ def _parse_cell(
610600
611601
Args:
612602
cell: openpyxl Cell
613-
include_formatting: 書式情報を含めるかどうか
614603
merged_cell_map: マージセル座標からマージ範囲へのマップ(パフォーマンス最適化用)
615604
merged_anchor_value_map: マージ範囲 -> アンカー値 のマップ(結合セルの値埋め用)
616605
@@ -638,15 +627,12 @@ def _parse_cell(
638627
if anchor_value is not None:
639628
cell_data["value"] = anchor_value
640629

641-
# 書式情報(オプション)
642-
# 現運用では fill/width/height/data_type は返さない。
643-
# include_formatting を指定しても返却内容は変わらない。
630+
# 書式情報(fill/width/height/data_type)は現在サポートされていません
644631
return cell_data
645632

646633
def _parse_rows(
647634
self,
648635
rows: tuple[tuple[Cell, ...], ...],
649-
include_formatting: bool,
650636
merged_cell_map: dict[str, str] | None = None,
651637
merged_anchor_value_map: dict[str, Any] | None = None,
652638
) -> list[list[dict[str, Any]]]:
@@ -655,7 +641,6 @@ def _parse_rows(
655641
656642
Args:
657643
rows: 行データのタプル
658-
include_formatting: 書式情報を含めるか
659644
merged_cell_map: マージセル情報
660645
merged_anchor_value_map: マージ範囲 -> アンカー値
661646
@@ -667,7 +652,6 @@ def _parse_rows(
667652
row_data = [
668653
self._parse_cell(
669654
cell,
670-
include_formatting,
671655
merged_cell_map,
672656
merged_anchor_value_map,
673657
)

tests/test_server.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ def test_excel_read_default(
222222
# デフォルトでは全パラメータがデフォルト値で呼ばれる
223223
mock_excel_parser.parse_to_json.assert_called_once_with(
224224
"/sites/test/Shared Documents/test.xlsx",
225-
include_formatting=False,
226225
sheet_name=None,
227226
cell_range=None,
228227
)
@@ -262,7 +261,6 @@ def test_excel_with_sheet_parameter(
262261

263262
mock_excel_parser.parse_to_json.assert_called_once_with(
264263
"/sites/test/Shared Documents/test.xlsx",
265-
include_formatting=False,
266264
sheet_name="Sheet2",
267265
cell_range=None,
268266
)
@@ -284,32 +282,10 @@ def test_excel_with_cell_range_parameter(
284282

285283
mock_excel_parser.parse_to_json.assert_called_once_with(
286284
"/sites/test/Shared Documents/test.xlsx",
287-
include_formatting=False,
288285
sheet_name="Sheet1",
289286
cell_range="A1:D10",
290287
)
291288

292-
@pytest.mark.unit
293-
def test_excel_with_formatting(
294-
self, mock_config, mock_sharepoint_client, mock_excel_parser
295-
):
296-
"""書式情報ありのテスト"""
297-
with patch(
298-
"src.server._get_sharepoint_client", return_value=mock_sharepoint_client
299-
):
300-
with patch("src.server.config", mock_config):
301-
sharepoint_excel(
302-
file_path="/sites/test/Shared Documents/test.xlsx",
303-
include_formatting=True,
304-
)
305-
306-
mock_excel_parser.parse_to_json.assert_called_once_with(
307-
"/sites/test/Shared Documents/test.xlsx",
308-
include_formatting=True,
309-
sheet_name=None,
310-
cell_range=None,
311-
)
312-
313289
@pytest.mark.unit
314290
def test_excel_with_real_json(
315291
self, mock_config, mock_sharepoint_client, mock_excel_parser

0 commit comments

Comments
 (0)