semvec/pypi-packages huggingface dataset:
excel-graph-api 1.0.0
Read and write Excel files in OneDrive using Microsoft Graph API
License: MIT
Requires Python: >=3.7
Keywords: excel, onedrive, microsoft, graph, api, spreadsheet

# Excel Graph API

Read and write Excel files stored in OneDrive using Microsoft Graph API.

## Installation

```bash
pip install excel-graph-api
```

## Setup

1. Get an access token from [Graph Explorer](https://developer.microsoft.com/en-us/graph/graph-explorer)
2. Sign in and consent to **Files.ReadWrite.All** permission
3. Create a `config.json` file:

```json
{
    "access_token": "YOUR_TOKEN_HERE",
    "default_file": "Book.xlsx"
}
```

## Usage

### Read from Excel

```python
from excel_graph_api import ExcelClient

client = ExcelClient()
data = client.read_range("Book.xlsx", "Sheet1", "A1:C10")
print(data)
```

### Write to Excel

```python
from excel_graph_api import ExcelClient

client = ExcelClient()
client.write_range("Book.xlsx", "Sheet1", "A1:B2", [
    ["Name", "Score"],
    ["Alice", 95]
])
```

### Append to Table

```python
from excel_graph_api import ExcelClient

client = ExcelClient()
client.append_to_table("Book.xlsx", "SalesTable", [
    ["2024-01-05", "Product A", 100]
])
```

### Import from JSON/CSV

```python
import json
from excel_graph_api import ExcelClient

client = ExcelClient()

# Read JSON
with open("data.json") as f:
    data = json.load(f)

# Convert to rows and write
headers = list(data[0].keys())
rows = [headers] + [[item[h] for h in headers] for item in data]
client.write_range("Book.xlsx", "Sheet1", "A1:C4", rows)
```

## Available Methods

| Method | Description |
|--------|-------------|
| `list_excel_files()` | List all Excel files in OneDrive |
| `list_worksheets(file)` | List sheets in a file |
| `read_range(file, sheet, range)` | Read cell values |
| `write_range(file, sheet, range, values)` | Write cell values |
| `list_tables(file)` | List tables in a file |
| `read_table(file, table)` | Read table rows |
| `append_to_table(file, table, rows)` | Add rows to table |
| `get_table_headers(file, table)` | Get table headers |

## Token Expiry

Access tokens expire after ~1 hour. Refresh from Graph Explorer when you get authentication errors.

## License

MIT