> For the complete documentation index, see [llms.txt](https://integrations.drivetrain.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://integrations.drivetrain.ai/integration-guide/readme/spreadsheets/integrating-with-microsoft-onedrive.md). Agents can also search and read this documentation through its [MCP server](https://integrations.drivetrain.ai/~gitbook/mcp).

# Integrating with Microsoft OneDrive

Connect Microsoft OneDrive to Drivetrain and import file data into planning models. Covers Microsoft 365 admin consent, signing in, and adding files.

Sign in with Microsoft once, then add each file you want as a dataset by pasting its URL. Each URL adds one sheet of an .xlsx workbook, or one .csv file.

## Before you start

* You're a Drivetrain **Admin**.
* You sign in with a **Microsoft account that can open the files** you want to import.
* Files are **.xlsx** or **.csv**.
* Microsoft asks you to approve the Drivetrain app's permissions: `Files.ReadWrite.All` (all files your account can access), `User.Read` and `offline_access`. Drivetrain only reads the files you add; it doesn't change them.

### If your organization requires admin consent

If your Microsoft 365 organization doesn't let users approve apps, a Microsoft 365 admin must approve Drivetrain first:

1. Open [this consent link](https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=e91b7619-1c8c-4455-8071-aedf6ca84954\&response_type=code\&redirect_uri=https://id.drivetrain.ai\&response_mode=query\&scope=offline_access%20Files.ReadWrite.All%20User.Read\&state=service~117) and sign in with the admin account.
2. Tick **Consent on behalf of your organization** and click **Accept**. You're redirected to Drivetrain.

<div align="left"><figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-d13ba4ff9c673bbb3c8258be740d333b6cecddf4%2Fimage.png?alt=media" alt="" width="375"><figcaption></figcaption></figure></div>

## Step 1: Connect your OneDrive account

1. On the **Data** page, click the **+** icon next to **Data**.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-8645a523a904f5f97f2aea4538435c3dbbd081d2%2Fod-1.webp?alt=media" alt=""><figcaption></figcaption></figure>

2. Select **OneDrive**.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-6cbf76de48898096aa9eadb2292c88170ca7b3b2%2Fod-2.webp?alt=media" alt=""><figcaption></figcaption></figure>

3. Click **Connect OneDrive**. You're taken to Microsoft's sign-in page.
4. Sign in, or pick the account that holds the files, and accept the permissions.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-3770361a9b5b1ad15692109fdeae448a43821136%2Fod-4.webp?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-9d805bde36c64d2592ac11dca2d24a39f134c8b4%2Fod-5.webp?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-c639670f227724853efc1f523560206318e0bd31%2Fod-6.webp?alt=media" alt=""><figcaption></figcaption></figure>

You're returned to Drivetrain and the **Add data from OneDrive** window opens.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-645d6fbd5b05a06384bc5c719c0a6336722cda61%2Fod-7.webp?alt=media" alt=""><figcaption></figcaption></figure>

## Step 2: Add a file

1. In OneDrive, open the file in your browser.
2. Copy the URL from the address bar. It must contain `sourcedoc=` and `file=`.

{% hint style="warning" %}
Don't use OneDrive's **Copy link** or **Share** link. It doesn't contain `sourcedoc=` and Drivetrain rejects it.
{% endhint %}

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-d47f1236f5285c8bd81c09233c1104f4c946d800%2Fod-8.webp?alt=media" alt=""><figcaption></figcaption></figure>

3. In Drivetrain, paste the URL. Drivetrain checks that it can open the file (a green tick appears).
4. For an .xlsx file, pick the tab in **Sheet name**.
5. Click **Add**.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-d664550e681b9543c7453611659138e530d90c7d%2Fod-9.webp?alt=media" alt=""><figcaption></figcaption></figure>

The file appears as a dataset under the OneDrive connection once its first sync finishes.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-8123ba2c4f721d1f4ddea763c5669b9cf5c2a64b%2Fod-10.webp?alt=media" alt=""><figcaption></figcaption></figure>

To add more files or tabs, click **Add data** on the connection and repeat.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-82d602ba748e37b6736bc4380d9887060d92ef78%2Fod-11.gif?alt=media" alt=""><figcaption></figcaption></figure>

## Format your file

* The table starts at **cell A1**, and **row 1** holds the column headers. No header may be empty.
* Each tab holds **only one table**.
* Formulas import as the values last saved in the file. Cells with formula errors (such as `#N/A` or `#REF!`) import as blank.
* Drivetrain stops reading a sheet after 1,000 blank rows in a row, so keep the data contiguous.

## Syncing

Each sync re-reads every file you added in full. Files sync automatically with your other data sources. To refresh now, open the connection's **⋮** menu and click **Sync**.

Don't rename or delete a tab you've added: the next sync can't find it and fails. To use a different tab, add it as a new dataset.

## Reconnect or disconnect

* **Reconnect** (for example after a password change or **Refresh token expired**): open the connection's **⋮** menu, click **Edit credentials**, and sign in again.
* **Disconnect:** open the connection's **⋮** menu and click **Remove**.

## Troubleshooting

<details>

<summary>Invalid link. It must contain a sourcedoc</summary>

You pasted a sharing link. Open the file in your browser and copy the URL from the address bar.

</details>

<details>

<summary>The file '…' was not found in SharePoint/OneDrive or is not accessible</summary>

The account you connected can't open the file, or the file was moved or deleted. Check you can open it while signed in as that account, then click **Retry fetching**.

</details>

<details>

<summary>Refresh token expired</summary>

Drivetrain's sign-in to Microsoft expired or was revoked. Open the connection's **⋮** menu, click **Edit credentials**, and sign in again.

</details>

<details>

<summary>The first row of this file is empty</summary>

Drivetrain checks the workbook's **first** sheet, whichever tab you picked. Make sure that sheet's table starts at A1 with headers in row 1, or move a cover sheet behind your data sheets, then add the file again.

</details>

<details>

<summary>We couldn't read the sheets in '…' because the workbook is too large for Microsoft to open</summary>

Remove unused sheets or replace formulas with their values to shrink the file, or save the data as a .csv and add that instead.

</details>

<details>

<summary>Can I refresh data from a OneDrive file?</summary>

Yes. Files sync automatically, and you can sync manually at any time.

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://integrations.drivetrain.ai/integration-guide/readme/spreadsheets/integrating-with-microsoft-onedrive.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
