Import & Export
Overview
Slides import and export is a Pro capability. The browser client registers the shared exchange client plus the Slides exchange client, while conversion, task polling, storage, and signed download URLs are provided by your Pro deployment.
import { UniverExchangeClientPlugin } from '@univerjs-pro/exchange-client'import ExchangeClientEnUS from '@univerjs-pro/exchange-client/locale/en-US'import { UniverSlidesExchangeClientPlugin } from '@univerjs-pro/slides-exchange-client'import SlidesExchangeClientEnUS from '@univerjs-pro/slides-exchange-client/locale/en-US'import '@univerjs-pro/exchange-client/lib/index.css'import '@univerjs-pro/exchange-client/facade'import '@univerjs-pro/slides-exchange-client/facade'univer.registerPlugin(UniverExchangeClientPlugin)univer.registerPlugin(UniverSlidesExchangeClientPlugin)Installation
pnpm add @univerjs-pro/exchange-client @univerjs-pro/slides-exchange-clientnpm install @univerjs-pro/exchange-client @univerjs-pro/slides-exchange-clientyarn add @univerjs-pro/exchange-client @univerjs-pro/slides-exchange-clientbun add @univerjs-pro/exchange-client @univerjs-pro/slides-exchange-clientConfigure endpoints
@univerjs-pro/slides-exchange-client depends on @univerjs-pro/exchange-client. Put server URLs on the shared exchange client, then register the Slides client to add PPTX menu operations. Import the shared CSS and @univerjs-pro/slides-exchange-client/facade when using the Facade API.
univer.registerPlugin(UniverExchangeClientPlugin, { uploadFileServerUrl: '/universer-api/stream/file/upload', importServerUrl: '/universer-api/exchange/{type}/import', exportServerUrl: '/universer-api/exchange/{type}/export', getTaskServerUrl: '/universer-api/exchange/task/{taskID}', signUrlServerUrl: '/universer-api/file/{fileID}/sign-url', downloadEndpointUrl: location.origin, maxTimeoutTime: 120000,})univer.registerPlugin(UniverSlidesExchangeClientPlugin)The {type} placeholder is filled with UniverInstanceType.UNIVER_SLIDE. Import can return either a server-side unit id or a snapshot JSON. Export uploads a slide snapshot to the exchange service, waits for the task result, signs the returned file id, and downloads the PPTX file.
Facade API
Import the facade package once in plugin mode:
import '@univerjs-pro/exchange-client/facade'import '@univerjs-pro/slides-exchange-client/facade'Import a PPTX into a server-side unit:
const unitId = await univerAPI.importSlideToUnitIdAsync(file)Import a PPTX as local slide data:
const slideData = await univerAPI.importSlideToSnapshotAsync(file)if (slideData) { univerAPI.createPresentation(slideData)}Export the current slide deck:
const presentation = univerAPI.getActivePresentation()const file = await univerAPI.exportSlideBySnapshotAsync(presentation.save())Export a server-side slide unit:
const file = await univerAPI.exportSlideByUnitIdAsync(unitId)Menu behavior
The Slides exchange client contributes PPTX menu actions:
ImportPPTXOperationimports to an existing unit when the current URL has aunitquery parameter; otherwise it imports to a local snapshot.ExportPPTXOperationexports the current slide deck by snapshot.
You can pass a menu config to UniverSlidesExchangeClientPlugin when you need to merge custom menu visibility or ordering.
Related setup
- Register
UniverSlidesPluginbefore the exchange client so Slides units are available. - Use Pro server APIs for authentication, storage, conversion, task polling, and signed download URLs.
- Keep print, table, and chart packages enabled if imported PPTX files may contain those elements.
How is this guide?