Skip to main content

Read and write Excel files in OneDrive using Microsoft Graph API

Project description

Excel Graph API

Read and write Excel files stored in OneDrive using Microsoft Graph API.

Installation

pip install excel-graph-api

Setup

  1. Get an access token from Graph Explorer
  2. Sign in and consent to Files.ReadWrite.All permission
  3. Create a config.json file:
{
    "access_token": "YOUR_TOKEN_HERE",
    "default_file": "Book.xlsx"
}

Usage

Read from Excel

from excel_graph_api import ExcelClient

client = ExcelClient()
data = client.read_range("Book.xlsx", "Sheet1", "A1:C10")
print(data)

Write to Excel

from excel_graph_api import ExcelClient

client = ExcelClient()
client.write_range("Book.xlsx", "Sheet1", "A1:B2", [
    ["Name", "Score"],
    ["Alice", 95]
])

Append to Table

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

excel_graph_api-1.0.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

excel_graph_api-1.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file excel_graph_api-1.0.0.tar.gz.

File metadata

  • Download URL: excel_graph_api-1.0.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for excel_graph_api-1.0.0.tar.gz
Algorithm Hash digest
SHA256 aac8c85fb726ba9d02908bbd36651f3dd7a6126fdde09ae0d3b7300fea6fbee7
MD5 0c1ceb6082e7bec1b5d5fa730c704f53
BLAKE2b-256 441446dfd7f324f8d6f06a1ede49853cad281b41fd0072c0cd93194edbaa28dd

See more details on using hashes here.

File details

Details for the file excel_graph_api-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for excel_graph_api-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ce59a6dc20f95798d83e9f45a5f5bc33771ef5a2cdb81381b4d97941d7d872e
MD5 83a40a912cf0c353fba65013d606ffca
BLAKE2b-256 9445164ebae5dbb53d346dd0b7ce27ec14a70b0493cb075e5bf34f111676f335

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page