Skip to content

Excel (Workbooks)

Read, write, and analyze Excel workbooks in OneDrive / SharePoint via the Graph workbook API — tables, worksheets, ranges, named items, formulas, and sessions. Every example uploads the bundled sample workbook and cleans up afterwards, so it is safe to re-run.


Prerequisites

Permission Description Reference
Files.ReadWrite All workbook operations (sessions, tables, ranges, formulas) Files permissions

All examples authenticate with username/password (client_id, username, password from tests.settings) and default to the sample workbook at examples/data/Financial Sample.xlsx.


How the workbook API fits together

graph TD
    WB["DriveItem<br/>(.xlsx)"] --> W["Workbook"]
    W --> S["Sessions<br/>(consistent view)"]
    W --> WS["Worksheets"]
    W --> T["Tables"]
    W --> R["Ranges"]
    W --> N["Named items"]
    W --> F["Functions"]

    WS --> T
    WS --> R
    R --> N

Which example to use: start a session for any multi-step automation (workbook_sessions.py), read tables and data (read_table.py), manage tables (tables.py), work with worksheets (worksheets.py), read/write cell ranges and named items (ranges.py), or compute with Excel formulas (formulas.py).


Examples

Operation File API
Read workbook tables and data read_table.py table list
Workbook sessions (create/refresh/close) workbook_sessions.py create session
Manage tables (add, rows, sort) tables.py table add
Worksheets (add, protect, delete) worksheets.py worksheet list
Ranges and named items ranges.py range update
Excel functions (ABS, POWER, DAYS) formulas.py functions resource

API reference