Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ Two authentication methods are supported:
- Automatic method selection for SharePoint vs OneDrive files
- **sharepoint_excel**
- Read or search Excel files in SharePoint
- Search mode: find cells containing specific text with `query` parameter
- Read mode: get data from specific sheets/ranges with `sheet` and `cell_range` parameters
- **Search mode**: find cells containing specific text with `query` parameter
- **Multiple keyword AND search**: use space-separated keywords (e.g., `"budget forecast"` finds cells containing both)
- **Row context**: set `include_surrounding_cells=True` to get entire row data (reduces API calls from N+1 to 1)
- **Read mode**: get data from specific sheets/ranges with `sheet` and `cell_range` parameters
- **Automatic header inclusion**: when `cell_range` is specified, frozen rows (headers) are automatically included by default
- Set `include_frozen_rows=False` to get only the specified range
- For sheets with `frozen_rows=0`, use `expand_axis_range=True` to include row 1 (for columns) or column A (for rows)
Expand Down
6 changes: 4 additions & 2 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ stdioとHTTPの両方のトランスポートに対応しています。
- SharePoint/OneDriveファイルに応じた自動メソッド選択
- **sharepoint_excel**
- SharePoint上のExcelファイルの読み取りと検索
- 検索モード: `query`パラメータで特定テキストを含むセルを検索
- 読み取りモード: `sheet`と`cell_range`パラメータで特定シート/範囲を取得
- **検索モード**: `query`パラメータで特定テキストを含むセルを検索
- **複数キーワードAND検索**: スペース区切りでキーワード指定(例: `"予算 報告"`で両方を含むセルを検索)
- **行コンテキスト**: `include_surrounding_cells=True`で行全体のデータを取得(API呼び出しをN+1から1に削減)
- **読み取りモード**: `sheet`と`cell_range`パラメータで特定シート/範囲を取得
- **ヘッダー自動追加**: `cell_range`指定時、デフォルトで固定行(ヘッダー)を自動的に含める
- `include_frozen_rows=False`を指定すると、指定範囲のみを取得
- `frozen_rows=0`のシートでは、`expand_axis_range=True`で1行目(列の場合)またはA列(行の場合)から自動取得
Expand Down
138 changes: 137 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,10 @@ The `sharepoint_excel` tool allows you to read and search Excel files in SharePo
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `file_path` | str | Required | Excel file path |
| `query` | str \| None | None | Search keyword (enables search mode) |
| `query` | str \| None | None | Search keyword (space-separated for AND search) |
| `sheet` | str \| None | None | Sheet name (get specific sheet only) |
| `cell_range` | str \| None | None | Cell range (e.g., "A1:D10") |
| `include_surrounding_cells` | bool | False | Get entire row data for each match in search mode |

### Basic Workflow

Expand Down Expand Up @@ -275,6 +276,141 @@ result = sharepoint_excel(
)
```

### Advanced Search Features

#### Multiple Keyword Search (AND Logic)

Search for cells containing all of the specified keywords (space-separated):

```python
# Find cells containing both "budget" AND "report"
result = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="budget report"
)
```

**Response:**
```json
{
"file_path": "/sites/finance/Shared Documents/report.xlsx",
"mode": "search",
"query": "budget report",
"match_count": 2,
"matches": [
{"sheet": "Sheet1", "coordinate": "A1", "value": "Budget Report 2024"},
{"sheet": "Summary", "coordinate": "C3", "value": "Annual Budget Report"}
]
}
```

**Use cases:**
- Narrow down search results: `"簾舞 連絡先"` finds cells with both keywords
- Best practice: Start with single keyword, add more if results are too broad

#### Search with Row Context

Get entire row data for each match in a single API call:

```python
# Search and get row context
result = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="Total Revenue",
include_surrounding_cells=True
)
```

**Response structure:**
```json
{
"file_path": "/sites/finance/Shared Documents/report.xlsx",
"mode": "search",
"query": "Total Revenue",
"match_count": 1,
"matches": [
{
"sheet": "Sheet1",
"coordinate": "B10",
"value": "Total Revenue",
"row_data": [
{"value": "2024", "coordinate": "A10"},
{"value": "Total Revenue", "coordinate": "B10"},
{"value": 1500000, "coordinate": "C10"},
{"value": "USD", "coordinate": "D10"}
]
}
]
}
```

**When to use:**
- `include_surrounding_cells=False` (default): Locate cells only
- `include_surrounding_cells=True`: Get immediate context without follow-up read (96% API call reduction)

#### Combining Multiple Keywords with Row Context

```python
# Search with multiple keywords (AND) and get row context
result = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="revenue forecast",
include_surrounding_cells=True
)
```

#### Search Best Practices and Limitations

**Query Guidelines:**
- Query cannot be empty or whitespace-only
- Use specific keywords to reduce match count
- Combine multiple keywords with spaces for AND search (e.g., `"budget 2024"`)

**Performance Considerations:**
- Search is limited to **1000 matches maximum**
- Warning issued at **500+ matches** - consider refining query
- Use `include_surrounding_cells=True` only when row context is needed
- For large result sets, narrow down with more specific keywords

**Error Handling:**
- If row data retrieval fails, match is still returned with `row_data_error` field
- Check response `warnings` array for actionable feedback

**Examples:**

```python
# Good: Specific keywords
result = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="Q4 revenue forecast"
)

# Avoid: Too generic (may hit 1000+ cells)
result = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="data"
)

# Handle large results
import json
result_json = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="budget"
)
result = json.loads(result_json)

if "warnings" in result:
print("Search feedback:", result["warnings"])
# Refine query based on feedback

# Safe row context usage
result = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="Total Revenue Q4",
include_surrounding_cells=True
)
```

### JSON Output Format

#### Read Mode (Default)
Expand Down
138 changes: 137 additions & 1 deletion docs/usage_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,10 @@ results = sharepoint_docs_search(
| パラメータ | 型 | デフォルト | 説明 |
|-----------|------|---------|-------------|
| `file_path` | str | 必須 | Excelファイルのパス |
| `query` | str \| None | None | 検索キーワード(検索モードを有効化) |
| `query` | str \| None | None | 検索キーワード(スペース区切りでAND検索) |
| `sheet` | str \| None | None | シート名(特定シートのみ取得) |
| `cell_range` | str \| None | None | セル範囲(例: "A1:D10") |
| `include_surrounding_cells` | bool | False | 検索モード時、マッチした行の全セルを取得 |

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

Expand Down Expand Up @@ -275,6 +276,141 @@ result = sharepoint_excel(
)
```

### 高度な検索機能

#### 複数キーワード検索(AND論理)

スペース区切りで複数のキーワードを指定して、全てに一致するセルを検索:

```python
# "予算" AND "報告" の両方を含むセルを検索
result = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="予算 報告"
)
```

**レスポンス例:**
```json
{
"file_path": "/sites/finance/Shared Documents/report.xlsx",
"mode": "search",
"query": "予算 報告",
"match_count": 2,
"matches": [
{"sheet": "Sheet1", "coordinate": "A1", "value": "2024年度 予算 報告書"},
{"sheet": "Summary", "coordinate": "C3", "value": "年次予算報告"}
]
}
```

**使用例:**
- 検索結果を絞り込む: `"簾舞 連絡先"`で両方のキーワードを含むセルを検索
- ベストプラクティス: まず単一キーワードで検索し、結果が多すぎる場合はキーワードを追加

#### 行コンテキスト付き検索

マッチしたセルと同じ行の全データを1回のAPI呼び出しで取得:

```python
# 検索と行コンテキスト取得
result = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="売上合計",
include_surrounding_cells=True
)
```

**レスポンス構造:**
```json
{
"file_path": "/sites/finance/Shared Documents/report.xlsx",
"mode": "search",
"query": "売上合計",
"match_count": 1,
"matches": [
{
"sheet": "Sheet1",
"coordinate": "B10",
"value": "売上合計",
"row_data": [
{"value": "2024", "coordinate": "A10"},
{"value": "売上合計", "coordinate": "B10"},
{"value": 1500000, "coordinate": "C10"},
{"value": "円", "coordinate": "D10"}
]
}
]
}
```

**使い分け:**
- `include_surrounding_cells=False`(デフォルト): セル位置の特定のみ
- `include_surrounding_cells=True`: 即座にコンテキスト取得(API呼び出しを96%削減)

#### 複数キーワードと行コンテキストの組み合わせ

```python
# 複数キーワード検索(AND) + 行コンテキスト取得
result = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="売上 予測",
include_surrounding_cells=True
)
```

#### 検索のベストプラクティスと制限事項

**クエリのガイドライン:**
- クエリは空文字列や空白のみは許可されません
- マッチ数を減らすため、具体的なキーワードを使用してください
- スペース区切りで複数キーワードを指定するとAND検索になります(例: `"予算 2024"`)

**パフォーマンスに関する考慮事項:**
- 検索結果は**最大1000件**に制限されています
- **500件以上**でクエリの絞り込みを推奨する警告が表示されます
- `include_surrounding_cells=True` は行コンテキストが必要な場合のみ使用してください
- 大量の結果が返される場合は、より具体的なキーワードで絞り込んでください

**エラーハンドリング:**
- 行データ取得に失敗した場合も、マッチ自体は `row_data_error` フィールド付きで返されます
- レスポンスの `warnings` 配列で実用的なフィードバックを確認できます

**使用例:**

```python
# 良い例: 具体的なキーワード
result = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="Q4 売上 予測"
)

# 避けるべき: 汎用的すぎる(1000件以上ヒットする可能性)
result = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="データ"
)

# 大量結果の処理
import json
result_json = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="予算"
)
result = json.loads(result_json)

if "warnings" in result:
print("検索フィードバック:", result["warnings"])
# フィードバックに基づいてクエリを絞り込む

# 安全な行コンテキスト使用
result = sharepoint_excel(
file_path="/sites/finance/Shared Documents/report.xlsx",
query="合計売上 Q4",
include_surrounding_cells=True
)
```

### JSON出力形式

#### 読み取りモード(デフォルト)
Expand Down
Loading