Import and export

If an export fails, see license error codes and task failure handling.

Plugins Info

Bases imports XLSX, XLS, CSV, and TSV and exports XLSX, CSV, and TSV. A common flow is to import an Excel customer list, add fields and views, and then export the table data again.

These APIs require a conversion backend. Complete file exchange integration first and confirm that the backend supports the Bases document type and the required formats.

Supported formats

The table covers the browser APIs described on this page. Converting Office files still requires a backend that supports the same document type and format.

ImportExport
.xls, .xlsx, .csv, .tsv.xlsx, .csv, .tsv

CSV and TSV export a single table, which is selected with tableId. Neither format preserves views, permissions, or any other Base resource. For a complete backup of the application, save a Base snapshot instead.

Install and register

Install these packages in an initialized Bases editor:

Shell
pnpm add @univerjs-pro/exchange-client @univerjs-pro/bases-exchange-client
TypeScript
import { UniverBasesExchangeClientPlugin } from '@univerjs-pro/bases-exchange-client'import { UniverExchangeClientPlugin } from '@univerjs-pro/exchange-client'import '@univerjs-pro/bases/facade'import '@univerjs-pro/bases-exchange-client/facade'import '@univerjs-pro/exchange-client/facade'univer.registerPlugin(UniverExchangeClientPlugin, exchangeConfig)univer.registerPlugin(UniverBasesExchangeClientPlugin)

exchangeConfig contains the application's upload, conversion, task-query, and download settings. The integration guide describes how to prepare it.

UniverExchangeClientPlugin

  • downloadEndpointUrl
    stringDefault: location.origin
    Base URL for file downloads.
  • uploadFileServerUrl
    stringDefault: '/universer-api/stream/file/upload'
    Endpoint that receives uploads.
  • importServerUrl
    stringDefault: '/universer-api/exchange/{type}/import'
    Endpoint that starts an import. Keep the {type} placeholder.
  • exportServerUrl
    stringDefault: '/universer-api/exchange/{type}/export'
    Endpoint that starts an export. Keep the {type} placeholder.
  • getTaskServerUrl
    stringDefault: '/universer-api/exchange/task/{taskID}'
    Endpoint that reports task status. Keep the {taskID} placeholder.
  • signUrlServerUrl
    stringDefault: '/universer-api/file/{fileID}/sign-url'
    Endpoint that signs file URLs. Keep the {fileID} placeholder.
  • maxTimeoutTime
    numberDefault: 120000
    Maximum polling time for a conversion task, in milliseconds.

Configure Excel conversion

UniverBasesExchangeClientPlugin

  • importSourceMode
    ExchangeBaseImportModeDefault: AUTO
    Whether to import Excel tables, worksheets, or both.
  • importFormulaPolicy
    ExchangeBaseFormulaPolicyDefault: CONVERT_THEN_VALUES
    How to treat formulas on import.
  • exportStructureMode
    ExchangeBaseExportModeDefault: TABLES
    Whether to export native Excel tables or worksheet ranges.
  • exportFormulaPolicy
    ExchangeBaseFormulaPolicyDefault: FAIL
    How to treat formulas on export.

To change the conversion behavior, pass options to the Bases exchange plugin. The values below are the defaults, and this registration replaces the one above:

TypeScript
import {  ExchangeBaseExportMode,  ExchangeBaseFormulaPolicy,  ExchangeBaseImportMode,} from '@univerjs-pro/exchange-client'univer.registerPlugin(UniverBasesExchangeClientPlugin, {  importSourceMode: ExchangeBaseImportMode.AUTO,  importFormulaPolicy: ExchangeBaseFormulaPolicy.CONVERT_THEN_VALUES,  exportStructureMode: ExchangeBaseExportMode.TABLES,  exportFormulaPolicy: ExchangeBaseFormulaPolicy.FAIL,})
  • Import source: AUTO imports Excel tables and visible worksheets automatically. TABLES imports Excel tables only, SHEETS imports visible worksheets, and HYBRID imports the Excel tables plus any visible worksheet that has no corresponding Excel table.
  • Export structure: TABLES converts non-empty Base tables into native Excel tables and leaves empty tables as ordinary ranges. RANGES writes every table as an ordinary worksheet range.
  • Formulas: during import, Univer converts the formulas it can and falls back to cached results for formulas that the engine does not support. During export, conversion must succeed unless the policy is changed: VALUES writes cached results only, and TEXT keeps the source formula as text. CONVERT_THEN_VALUES still fails on export when a formula cannot be converted.

Import for editing on the page

The file argument can be a File selected by the user or a URL pointing to a remote file. The call returns a snapshot of Base data that the editor can load:

TypeScript
const snapshot = await univerAPI.importBaseToSnapshotAsync(file)if (snapshot) {  univerAPI.createBase(snapshot)}

Importing a snapshot does not require collaboration, but the file must still be converted on the server. If users need to return to the Base later, store the result of base.save() as described in saving and restoring snapshots.

Export a file

To export the current Base as Excel:

TypeScript
import { ExchangeFormat } from '@univerjs-pro/exchange-client'const base = univerAPI.getActiveBase()if (!base) throw new Error('Open a Base first')const file = await univerAPI.exportBaseBySnapshotAsync(base.save(), ExchangeFormat.XLSX)if (file) {  univerAPI.downloadFile(file, 'database', ExchangeFormat.XLSX)}

CSV and TSV can represent only one table, so pass tableId explicitly when exporting a Base that has more than one table:

TypeScript
const table = base.getTables()[0]if (!table) throw new Error('Create a table first')const file = await univerAPI.exportBaseBySnapshotAsync(  base.save(),  ExchangeFormat.CSV,  table.getId(),)if (file) {  univerAPI.downloadFile(file, table.getName(), ExchangeFormat.CSV)}

For TSV, replace ExchangeFormat.CSV with ExchangeFormat.TSV. File export is intended for exchanging table data. For a full backup, save the Base snapshot; CSV does not preserve views, permissions, or any other resource.

Import a collaborative document

Configure Bases collaboration first, then import the document and load the ID returned by the server:

TypeScript
import '@univerjs-pro/collaboration-client/facade'const unitId = await univerAPI.importBaseToUnitIdAsync(file)if (unitId) {  await univerAPI.getCollaboration().loadBaseAsync(unitId)}

To export a server document, call exportBaseByUnitIdAsync(unitId, format, tableId?). Wait for pending browser edits to finish syncing before exporting.

Verify field and formula conversion with real application files. These methods can return undefined and can throw request or conversion errors, so handle both cases in the UI.

Removal of built-in import/export menus and UI interactions

Note

Starting with version 1.2.0, Univer no longer includes built-in import/export menus and UI interactions. The underlying services and Facade APIs remain available.

If the application still requires the previous import/export menus and UI interactions, the migration example for built-in import/export menus and UI interactions shows how to move them into a custom plugin. The complete source code is available there for online reading or download.

How is this guide?

© 2026 DreamNum Co., Ltd.