# How to Export Google Drive Files in Different Formats Using gogcli

> Export Google Drive files to PDF, DOCX, CSV, XLSX, PPTX, or TXT using gogcli. Learn how to convert documents, spreadsheets, and presentations with the gog docs export command.

- Repository: [Peter Steinberger/gogcli](https://github.com/steipete/gogcli)
- Tags: how-to-guide
- Published: 2026-02-19

---

**Use the `gog docs export`, `gog sheets export`, or `gog slides export` sub-commands with the `--format` flag to convert Google Workspace files to PDF, DOCX, CSV, XLSX, PPTX, or TXT, while binary files use `gog drive download` without format conversion.**

The `gogcli` tool by steipete provides a command-line interface for exporting Google Drive files in various formats. Whether you need to convert Google Docs to Microsoft Word format or download Sheets as CSV, understanding how to export Drive files in different formats using `gogcli` streamlines your document workflow.

## Understanding the gogcli Export Architecture

The export system in `gogcli` relies on a layered architecture that separates service-specific command handling from generic Drive export logic.

### The Core Export Function

At the heart of the system is the `exportViaDrive` function in [`internal/cmd/export_via_drive.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/export_via_drive.go). This function handles validation, resolves target files, determines the correct MIME type for export, and manages the download stream. It accepts an `exportViaDriveOptions` struct that specifies the expected MIME type, file kind label, and default format for each service.

### Service-Specific Wrappers

Each Google Workspace service implements a thin wrapper command that delegates to the core exporter:

- `DocsExportCmd` in [`internal/cmd/docs.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/docs.go) calls `exportViaDrive` with document-specific options
- `SheetsExportCmd` in [`internal/cmd/sheets.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/sheets.go) handles spreadsheet exports
- `SlidesExportCmd` in [`internal/cmd/slides.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/slides.go) manages presentation exports

## Export Google Docs to PDF, DOCX, and TXT

Google Docs support three export formats via the `--format` flag. The mapping logic resides in [`internal/cmd/drive.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/drive.go) within the `driveExportMimeTypeForFormat` function.

To export a Google Doc to PDF (default):

```bash
gog docs export <DOC_ID> --out ~/Downloads/mydoc.pdf

```

To export to Microsoft Word format:

```bash
gog docs export <DOC_ID> --format docx --out ~/Downloads/mydoc.docx

```

To export to plain text:

```bash
gog docs export <DOC_ID> --format txt --out ~/Downloads/mydoc.txt

```

The system validates that the file's MIME type matches `application/vnd.google-apps.document` before proceeding with the export.

## Export Google Sheets to CSV, XLSX, and PDF

Spreadsheets support CSV, Excel, and PDF formats. The `SheetsExportCmd` in [`internal/cmd/sheets.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/sheets.go) passes `expectedMime: "application/vnd.google-apps.spreadsheet"` to the exporter.

Export to CSV:

```bash
gog sheets export <SHEET_ID> --format csv --out ~/Downloads/data.csv

```

Export to Excel format:

```bash
gog sheets export <SHEET_ID> --format xlsx --out ~/Downloads/data.xlsx

```

Export to PDF:

```bash
gog sheets export <SHEET_ID> --format pdf --out ~/Downloads/data.pdf

```

## Export Google Slides to PPTX and PDF

Presentations support PowerPoint and PDF exports via `SlidesExportCmd` in [`internal/cmd/slides.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/slides.go).

Export to PowerPoint:

```bash
gog slides export <SLIDES_ID> --format pptx --out ~/Downloads/presentation.pptx

```

Export to PDF:

```bash
gog slides export <SLIDES_ID> --format pdf --out ~/Downloads/presentation.pdf

```

## Export Google Drawings to PNG and PDF

For Google Drawings, use the generic `drive download` command with the `--format` flag:

Export to PNG (default):

```bash
gog drive download <DRAWING_ID> --format png --out ~/Downloads/drawing.png

```

Export to PDF:

```bash
gog drive download <DRAWING_ID> --format pdf --out ~/Downloads/drawing.pdf

```

The [`drive.go`](https://github.com/steipete/gogcli/blob/main/drive.go) file contains the `driveExportMimeTypeForFormat` function that maps drawing formats to `image/png` or `application/pdf` MIME types.

## Download Binary Files Without Format Conversion

For non-Workspace files (ZIP, images, PDFs uploaded as binaries), use `gog drive download` without the `--format` flag:

```bash
gog drive download <FILE_ID> --out ~/Downloads/archive.zip

```

The `downloadDriveFile` function in [`internal/cmd/drive.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/drive.go) detects that the file is not a Google Workspace type (lacks the `application/vnd.google-apps.` prefix) and uses the `Files.Get` endpoint with `alt=media` instead of `Files.Export`.

## Summary

- **Use service-specific commands** (`gog docs export`, `gog sheets export`, `gog slides export`) for Google Workspace files to ensure proper MIME type validation and format conversion.
- **Specify formats** with the `--format` flag; supported values include `pdf`, `docx`, `txt`, `csv`, `xlsx`, `pptx`, and `png`.
- **Use `gog drive download`** for Google Drawings or binary files; omit `--format` for non-Workspace files to stream raw bytes.
- **Core implementation** resides in [`internal/cmd/export_via_drive.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/export_via_drive.go) and [`internal/cmd/drive.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/drive.go), with service wrappers in [`internal/cmd/docs.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/docs.go), [`sheets.go`](https://github.com/steipete/gogcli/blob/main/sheets.go), and [`slides.go`](https://github.com/steipete/gogcli/blob/main/slides.go).

## Frequently Asked Questions

### What export formats does gogcli support for Google Docs?

`gogcli` supports exporting Google Docs to `pdf` (default), `docx` (Microsoft Word), and `txt` (plain text). The `driveExportMimeTypeForFormat` function in [`internal/cmd/drive.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/drive.go) maps these format strings to their respective MIME types: `application/pdf`, `application/vnd.openxmlformats-officedocument.wordprocessingml.document`, and `text/plain`.

### Can I export Google Sheets to Excel format using gogcli?

Yes. Use the command `gog sheets export <ID> --format xlsx --out file.xlsx`. The exporter validates that the file is a Google Spreadsheet (`application/vnd.google-apps.spreadsheet`) and maps the `xlsx` format to `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` before calling the Drive API export endpoint.

### How does gogcli handle binary file downloads differently from Google Workspace exports?

For binary files (non-Google Workspace files), `gogcli` uses the `Files.Get` endpoint with `alt=media` to stream raw bytes directly. For Google Workspace files (Docs, Sheets, Slides, Drawings), it uses the `Files.Export` endpoint with a specific MIME type derived from the `--format` flag. This logic is implemented in the `downloadDriveFile` function within [`internal/cmd/drive.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/drive.go).

### Where is the core export logic implemented in the gogcli source code?

The core export logic resides in [`internal/cmd/export_via_drive.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/export_via_drive.go), specifically the `exportViaDrive` function (lines 26-122). This function handles ID normalization, path expansion, file resolution, MIME type validation, and delegates to `downloadDriveFile` in [`internal/cmd/drive.go`](https://github.com/steipete/gogcli/blob/main/internal/cmd/drive.go) for the actual HTTP request. Service-specific wrappers like `DocsExportCmd`, `SheetsExportCmd`, and `SlidesExportCmd` live in their respective files ([`docs.go`](https://github.com/steipete/gogcli/blob/main/docs.go), [`sheets.go`](https://github.com/steipete/gogcli/blob/main/sheets.go), [`slides.go`](https://github.com/steipete/gogcli/blob/main/slides.go)) and configure the options passed to the core exporter.