feat: add SharePoint / OneDrive Excel exporter - #1730
Open
singhankur wants to merge 1 commit into
Open
Conversation
Add SharePointExporter for exporting query results to an Excel workbook on SharePoint or OneDrive using the Microsoft Graph API. Features: - OAuth2 Authorization Code flow via MSAL (token stored per user, auto-refreshed using the offline_access scope) - Writes to the user's OneDrive by default; accepts an optional SharePoint site URL to target a team site document library - Optional folder path within the drive - Creates the workbook (.xlsx) if it doesn't exist, using openpyxl for the initial empty file upload - Streams result rows in configurable batches (default 1,000 rows) to stay within Graph API request limits - Returns the webUrl of the workbook for display in the UI Configuration (environment variables set by the admin): SHAREPOINT_CLIENT_ID — Azure AD app registration client ID SHAREPOINT_TENANT_ID — Tenant ID, or "common" for multi-tenant SHAREPOINT_CLIENT_SECRET — Client secret Adds requirements/exporter/sharepoint.txt with msal and openpyxl.
singhankur
force-pushed
the
feat/sharepoint-exporter
branch
from
July 29, 2026 08:29
a7d4cb1 to
ff1f16b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
SharePointExporterthat exports query results to an Excel workbook on SharePoint or OneDrive via the Microsoft Graph API.webUrlso users can open it directly from the Querybook UIFiles changed
querybook/server/lib/export/exporters/sharepoint_exporter.pySharePointExporterclassrequirements/exporter/sharepoint.txtmsal+openpyxldependenciesplugins/exporter_plugin/__init__.pyHow it works
Auth — MSAL Authorization Code flow. On first export the user is redirected to Microsoft login; the token (including refresh token via
offline_access) is stored in user properties and refreshed transparently on subsequent calls.Drive resolution — defaults to the user's OneDrive. If a SharePoint site URL is provided, the Graph API resolves the site's default document library.
Workbook lifecycle — checks for an existing file at the specified path; if absent, uploads a minimal
openpyxl-generated.xlsxas the initial content.Writing data — uses the Graph API Excel workbook range PATCH endpoint (
/workbook/worksheets/{name}/range(address='A1:Z1000')), batching rows in chunks of 1,000 to stay within API limits.Configuration
An Azure AD app registration is required. Set three environment variables:
Then register the exporter in
plugins/exporter_plugin/__init__.py:Test plan
Files.ReadWriteandSites.ReadWrite.Alldelegated permissionsfolder_pathset — verify file lands in the correct subfolder🤖 Generated with Claude Code