Skip to content

Feat/issue 47 expand axis range option#57

Merged
k-ibaraki merged 3 commits intomainfrom
feat/issue-47-expand-axis-range-option
Feb 10, 2026
Merged

Feat/issue 47 expand axis range option#57
k-ibaraki merged 3 commits intomainfrom
feat/issue-47-expand-axis-range-option

Conversation

@k-ibaraki
Copy link
Copy Markdown
Member

issue

変更内容

確認したこと

スクリーンショット

補足事項

PR時のセルフチェック

  • 関数や変数の命名は一目で分かるものになってますか?
  • コメントは適切な量で、誰が見ても分かるコメントになってますか?
  • PR内容に関するテストは書きましたか?
  • PR内容に付随する各種ドキュメントは一緒に修正しましたか?
  • IssueをCloseする場合、完了の定義は満たせていますか?

k-ibaraki and others added 2 commits February 10, 2026 22:13
- Distinguish frozen_rows reset cases in header_detection
  - Add 'ignored_due_to_limit' status for frozen_rows exceeding limit
  - Keep 'no_frozen_rows' status for sheets without frozen rows
- Add warning when sheet_name not found in search_cells
  - Consistent with parse_to_json warning behavior
- Improve documentation and comments
  - Add single cell behavior to _expand_axis_range docstring
  - Add compatibility notes for _cells private attribute usage

These changes improve error clarity and maintainability without
affecting the core functionality.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Changed "Context Efficiency" section to prioritize LLM usability over
brevity. Key points:
- LLM's ability to use tools correctly is the top priority
- Complex tools require detailed descriptions for correct usage
- Token cost is acceptable if it ensures LLM doesn't misuse tools
- Avoid verbose phrasing, but never sacrifice clarity for brevity

This lesson came from attempting to shorten the sharepoint_excel tool
description, which caused LLM to provide incorrect responses. The
original detailed description was necessary for proper functionality.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 10, 2026 14:08
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @k-ibaraki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

このプルリクエストは、Excelファイル処理の堅牢性と情報提供を向上させることを目的としています。具体的には、指定されたシートが見つからない場合の警告処理を追加し、凍結行の検出ロジックを改善して、ヘッダー検出に関するより詳細な情報を提供するようにしました。また、LLMツール記述に関する内部ガイドラインを更新し、LLMがツールを正しく使用するための明確性を重視するようになりました。

Highlights

  • LLMツール記述ガイドラインの更新: CLAUDE.md内のLLMツール記述に関するガイドラインを更新し、簡潔さよりもLLMがツールを正しく使用できるような明確性と詳細さを優先するよう変更しました。
  • Excelシート検索の警告機能追加: 指定されたExcelシートが見つからない場合に警告を生成し、代わりにすべてのシートを検索するフォールバックメカニズムを導入しました。この警告はJSON出力に含まれます。
  • ヘッダー検出ロジックの改善: Excelファイルのヘッダー検出ロジックを強化し、凍結行が制限を超過して無視されたケースと、元々凍結行がないケースとで、より具体的な情報を提供するようにしました。
  • 内部コメントの追加: openpyxlライブラリのプライベート属性_cellsの使用に関する注意コメントをコードに追加しました。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • CLAUDE.md
    • ツール記述の「Context Efficiency」ガイドラインを更新し、LLMの使いやすさを最優先するよう変更しました。
    • 簡潔すぎる記述がLLMの誤用につながるという教訓を追加しました。
  • src/sharepoint_excel.py
    • search_cells関数にwarningsリストを初期化しました。
    • 指定されたシートが見つからない場合に警告メッセージをwarningsリストに追加するようにしました。
    • search_cellsのJSON出力に、警告が存在する場合にwarningsフィールドを含めるように変更しました。
    • _scan_sheetおよび_build_merged_cell_cache関数に、_cellsopenpyxlのプライベート属性であることに関する注意コメントを追加しました。
    • _parse_sheet関数にfrozen_rows_ignoredフラグを導入しました。
    • _parse_sheet関数内のヘッダー検出ロジックを修正し、凍結行が制限超過で無視されたケースと、元々凍結行がないケースとで異なるステータスとノートを返すようにしました。
    • _expand_axis_range関数のドキュメント文字列を更新し、単一セル(例: C5 -> C1:C5)の拡張例を追加しました。
Activity
  • これまでのところ、このプルリクエストにはレビューコメントや特別な活動はありません。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

このプルリクエストは、主にExcelの軸範囲を拡張するオプションを追加し、いくつかの改善を行っています。主な変更点として、search_cellsでシートが見つからない場合に警告を返す機能、frozen_rowsが上限を超えて無視された場合に具体的なフィードバックを返す機能の追加、そして_expand_axis_rangeが単一セルを拡張できるようになった点が挙げられます。全体的に良い改善ですが、_parse_sheet関数内にコードの重複が見られたため、リファクタリングを提案するコメントを1件追加しました。

Comment thread src/sharepoint_excel.py
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

SharePoint 上の Excel 解析における利用時の混乱を減らすために、警告情報の付与や expand_axis_range 周辺の説明・判定を拡充している点は良い対応です。Excel 解析結果の「なぜその挙動になったか」を返しやすくする方向性で、全体の可観測性が上がっています。

Changes:

  • search_cells() で指定シートが存在しない場合に警告(warnings)を返すように変更
  • freeze_panes の DoS 対策で frozen_rows を無視したケースを header_detection.status で区別
  • openpyxl のプライベート属性 _cells 利用に関する注意書きと、_expand_axis_range() の説明を追記
  • CLAUDE.md の “Context Efficiency” ガイドラインを更新

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/sharepoint_excel.py 解析・検索結果に警告/ステータス情報を追加し、expand_axis_range/freeze_panes 周辺の説明と挙動を改善
CLAUDE.md ツール説明の明確さを優先する方針に更新
Comments suppressed due to low confidence (1)

src/sharepoint_excel.py:507

  • header_detection の追加条件が expand_axis_range フラグの真偽だけで制御されていますが、expand_axis_range=True でも矩形範囲などでは実際に 1行目/A列 が含まれず、警告(header_detection)が抑制されてしまいます。effective_range を計算・拡張した後に、実際に範囲が row=1 / col=A を含むかで header_detection の要否を判定する方が挙動が一貫します。
        # frozen_rows=0 かつ cell_range指定時、expand_axis_range=Falseの場合のみ警告
        # expand_axis_range=Trueの場合は1行目/A列が含まれるため警告不要
        if frozen_rows == 0 and cell_range and not expand_axis_range:
            if frozen_rows_ignored:
                # 上限超過で無視されたケース
                sheet_data["header_detection"] = {
                    "status": "ignored_due_to_limit",
                    "frozen_rows": 0,
                    "note": "This sheet has frozen rows but they exceed the limit and were ignored. Headers are not automatically included.",
                    "suggestions": [
                        "Read 'A1:Z5' to check header structure",
                        "Or retry with expand_axis_range=True to include row 1 (for columns) or column A (for rows)",
                    ],
                }
            else:
                # 元々frozen_rowsが0のケース
                sheet_data["header_detection"] = {
                    "status": "no_frozen_rows",
                    "frozen_rows": 0,
                    "note": "This sheet has no frozen rows. Headers are not automatically included.",
                    "suggestions": [
                        "If headers are needed, read 'A1:Z5' to check header structure",
                        "Or retry with expand_axis_range=True to include row 1 (for columns) or column A (for rows)",
                    ],
                }

        # セル範囲の正規化・拡張(cell_rangeがある場合)
        # マージセル情報のキャッシュに使用するため、先に計算する
        effective_range_for_merge = None
        header_range = None  # ヘッダー範囲(再利用のため事前に初期化)
        if cell_range:
            sheet_data["requested_range"] = cell_range
            effective_range = self._normalize_column_range(cell_range, sheet)
            if expand_axis_range:
                expanded_range = self._expand_axis_range(effective_range)
                if expanded_range != effective_range:
                    logger.info(
                        "Expanded axis range '%s' -> '%s' (sheet=%s)",
                        effective_range,
                        expanded_range,
                        sheet.title,
                    )
                    effective_range = expanded_range


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/sharepoint_excel.py
Comment on lines 67 to 84
@@ -76,6 +77,9 @@ def search_cells(
self._scan_sheet(workbook[sn], sn, query, matches)
else:
# sheet_name が存在しない場合は「指定なし」と同じ扱いで全シート検索
warnings.append(
f"Sheet '{sheet_name}' not found. Searching all sheets instead."
)
for sn in workbook.sheetnames:
self._scan_sheet(workbook[sn], sn, query, matches)
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

search_cells() の sheet_name 判定が完全一致のみで、parse_to_json() が使っている _resolve_sheet_name()(trim/casefold 解決や候補提示)と挙動が不整合です。その結果、大小文字/前後空白の違いだけでも「not found」扱いになり、全シート走査にフォールバックして性能面のリスクが出ます。search_cells() 側も _resolve_sheet_name() を使い、解決できない場合は candidates/available_sheets を返す(必要なら cell_range 相当の条件がない限り全走査はしない等)に揃えるのが安全です。

Copilot uses AI. Check for mistakes.
Comment thread src/sharepoint_excel.py
Comment on lines 79 to +102
@@ -85,17 +89,17 @@ def search_cells(

logger.info(f"Found {len(matches)} matches for query '{query}'")

return json.dumps(
{
"file_path": file_path,
"mode": "search",
"query": query,
"match_count": len(matches),
"matches": matches,
},
ensure_ascii=False,
indent=2,
)
result = {
"file_path": file_path,
"mode": "search",
"query": query,
"match_count": len(matches),
"matches": matches,
}
if warnings:
result["warnings"] = warnings

return json.dumps(result, ensure_ascii=False, indent=2)
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sheet_name が存在しない場合に warnings を返す仕様が追加されていますが、この分岐をカバーするテストが現状見当たりません(warnings キーの有無・内容、フォールバック時の match_count など)。既存の tests/test_sharepoint_excel.py に search_cells(sheet_name="NonExistent") のケースを追加して、後方互換(warnings が無い時は出力されない/される等)も含めて固定したいです。

Copilot uses AI. Check for mistakes.
Comment thread src/sharepoint_excel.py
@k-ibaraki k-ibaraki merged commit f72438e into main Feb 10, 2026
1 check passed
@k-ibaraki k-ibaraki deleted the feat/issue-47-expand-axis-range-option branch February 10, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants