# Export and Import Google Sheets

Plan an Excel-to-Google-Sheets export offline, create a spreadsheet from an ExcelDocument, import a Google Sheet, and replace an existing one safely.

**Packages**

- [OfficeIMO.Excel.GoogleSheets](https://www.nuget.org/packages/OfficeIMO.Excel.GoogleSheets) `dotnet add package OfficeIMO.Excel.GoogleSheets`
- [OfficeIMO.GoogleWorkspace](https://www.nuget.org/packages/OfficeIMO.GoogleWorkspace) `dotnet add package OfficeIMO.GoogleWorkspace`

**Works with**

- .NET
- [PowerShell](/docs/pswriteoffice/install/) `Install-Module PSWriteOffice`

**Target frameworks**

netstandard2.0, net8.0, net10.0, net472

**APIs**

- [`ExcelDocument`](/api/excel/officeimo-excel-exceldocument/)
- [`GoogleSheetsSaveOptions`](/api/excel-google-sheets/officeimo-excel-googlesheets-googlesheetssaveoptions/)
- [`GoogleServiceAccountCredentialSource`](/api/google-workspace/officeimo-googleworkspace-googleserviceaccountcredentialsource/)
- [`GoogleWorkspaceSession`](/api/google-workspace/officeimo-googleworkspace-googleworkspacesession/)
- [`ExcelSheet`](/api/excel/officeimo-excel-excelsheet/)
- [`GoogleDriveFileLocation`](/api/google-workspace/officeimo-googleworkspace-googledrivefilelocation/)
- [`GoogleSheetsImportOptions`](/api/excel-google-sheets/officeimo-excel-googlesheets-googlesheetsimportoptions/)
- [`GoogleSheetsImportResult`](/api/excel-google-sheets/officeimo-excel-googlesheets-googlesheetsimportresult/)
- [`GoogleSheetsReplaceOptions`](/api/excel-google-sheets/officeimo-excel-googlesheets-googlesheetsreplaceoptions/)
- [`GoogleSheetsTranslationPlan`](/api/excel-google-sheets/officeimo-excel-googlesheets-googlesheetstranslationplan/)
- [`GoogleSpreadsheetReference`](/api/excel-google-sheets/officeimo-excel-googlesheets-googlespreadsheetreference/)
- [`GoogleWorkspaceImportMode`](/api/google-workspace/officeimo-googleworkspace-googleworkspaceimportmode/)

**Cmdlets**

- [`Export-OfficeExcelGoogleSpreadsheet`](/api/powershell/export-officeexcelgooglespreadsheet/)
- [`New-OfficeExcelGoogleSheetsOptions`](/api/powershell/new-officeexcelgooglesheetsoptions/)
- [`New-OfficeGoogleWorkspaceSession`](/api/powershell/new-officegoogleworkspacesession/)

**Limits**

Excel print layout has no Google Sheets equivalent and is not exported. [OfficeIMO.Excel.GoogleSheets support matrix](/compatibility/#package-excel-googlesheets)

**Verified**

Examples compiled against the source on 2026-11-14

**Data**

- [OfficeIMO.Excel.GoogleSheets API index](/api/excel-google-sheets/index.json)
- [OfficeIMO.GoogleWorkspace API index](/api/google-workspace/index.json)
- [PSWriteOffice command catalog](/data/powershell/commands.json)
- [Capability catalog (JSON)](/data/capabilities.json)

`OfficeIMO.Excel.GoogleSheets` translates an `ExcelDocument` into Google Sheets API requests and imports spreadsheets back. Value-heavy writes are kept apart from structural requests and both are chunked. Formula handling is explicit: fail, keep with a warning, or write the cached value.

## Check what an export would change

### C#

```csharp
using OfficeIMO.Excel;
using OfficeIMO.Excel.GoogleSheets;
using OfficeIMO.GoogleWorkspace;

using ExcelDocument workbook = ExcelDocument.Load("revenue.xlsx");

GoogleSheetsTranslationPlan plan = workbook.BuildGoogleSheetsPlan(new GoogleSheetsSaveOptions { Title = "Quarterly revenue" });

foreach (TranslationNotice notice in plan.Report.Notices) {
    Console.WriteLine($"{notice.Severity} {notice.Code} {notice.Path}: {notice.Message}");
}
```

### PowerShell

```powershell
$options = New-OfficeExcelGoogleSheetsOptions -Title 'Quarterly revenue' -UnsupportedFormula PreserveWithWarning
Export-OfficeExcelGoogleSpreadsheet -Path .\revenue.xlsx -Options $options -Mode Plan
```

## Create a Google Sheet from Excel

### C#

```csharp
using OfficeIMO.Excel;
using OfficeIMO.Excel.GoogleSheets;
using OfficeIMO.GoogleWorkspace;

using var credentials = GoogleServiceAccountCredentialSource.FromFile("service-account.json");
var session = new GoogleWorkspaceSession(credentials, new GoogleWorkspaceSessionOptions { DefaultFolderId = "folder-id" });

using ExcelDocument workbook = ExcelDocument.Create();
ExcelSheet summary = workbook.AddSheet("Summary");
summary.Cell(1, 1).SetValue("Quarter");
summary.Cell(1, 2).SetValue("Revenue");
summary.Cell(2, 1).SetValue("Q1");
summary.Cell(2, 2).SetValue(125000);

var options = new GoogleSheetsSaveOptions { Title = "Quarterly revenue" };
options.Identity.WriteDeveloperMetadata = true;

GoogleSpreadsheetReference created = await workbook.ExportToGoogleSheetsAsync(session, options);
Console.WriteLine(created.WebViewLink);
```

### PowerShell

```powershell
$session = New-OfficeGoogleWorkspaceSession -KeyPath .\Secrets\reporting.json -Scope Spreadsheets, DriveFile
try {
    $options = New-OfficeExcelGoogleSheetsOptions -Title 'Quarterly revenue' -FolderId 'folder-id'
    Export-OfficeExcelGoogleSpreadsheet -Path .\revenue.xlsx -Session $session -Options $options -FailOnLoss
} finally {
    $session.CredentialSource.Dispose()
}
```

## Import a Google Sheet and replace it safely

Native import accepts ranges and a Sheets field mask; `DriveExport` mode converts to XLSX for broader fidelity. For a replacement, pass the Drive version you imported.

### C#

```csharp
using OfficeIMO.Excel.GoogleSheets;
using OfficeIMO.GoogleWorkspace;

using var credentials = GoogleServiceAccountCredentialSource.FromFile("service-account.json");
var session = new GoogleWorkspaceSession(credentials);

GoogleSheetsImportResult current = await session.ImportGoogleSheetAsync(
    "spreadsheet-id",
    new GoogleSheetsImportOptions { Mode = GoogleWorkspaceImportMode.Native, Ranges = new[] { "Summary!A1:Z500" } });

using (current.Document) {
    var replace = new GoogleSheetsSaveOptions {
        Location = new GoogleDriveFileLocation { ExistingFileId = current.Source.FileId },
        Replace = new GoogleSheetsReplaceOptions { ExpectedDriveVersion = current.Source.DriveVersion }
    };
    await current.Document.ExportToGoogleSheetsAsync(session, replace);
}
```

### PowerShell

```powershell
$options = New-OfficeExcelGoogleSheetsOptions -SpreadsheetId $spreadsheetId -ExpectedDriveVersion $driveVersion
Export-OfficeExcelGoogleSpreadsheet -Path .\revenue.xlsx -Session $session -Options $options
```

<!-- PowerForge markdown source sha256:A79348E54B682AC8DEC8FE9D886A829F146C8E0F6EE8542A0E149C0646FCA69A; title=True -->

<!-- PowerForge markdown artifact sha256:4EC86F83300DE91E34743D6DC9AD4D9FBFF150A7515160915FFEF9E370036CE9 -->
