导入导出
通过 @univerjs-pro/boards-exchange-client,画板可以导入 Mermaid 源码并导出 PPTX 文件。
支持的格式
下表列出本页前端 API 支持的格式。Office 文件转换还需要后端支持对应的文档类型和格式。
| 导入 | 导出 |
|---|---|
| Mermaid 源码文本 | .pptx |
Mermaid 导入通过 insertMermaidAsync 将源码插入为画板元素,不是 Office 文件导入。导出 API 生成 .pptx,需要转换后端;它们不提供 PPTX 导入或图片、PDF 导出。宿主应用自行注册的其他导出目标属于独立能力。
先注册画板运行时
TypeScript
univer.registerPlugin(UniverBoardsPlugin)univer.registerPlugin(UniverBoardsUIPlugin)univer.registerPlugin(UniverBoardsExchangeClientPlugin)在导入可能包含可选元素的数据之前,请先注册相应的元素插件:
TypeScript
univer.registerPlugin(UniverBoardsTablePlugin)univer.registerPlugin(UniverBoardsTableUIPlugin)univer.registerPlugin(UniverBoardsMindPlugin)univer.registerPlugin(UniverBoardsMindUIPlugin)快照交接
如需实现应用级持久化,请保存并恢复画板快照:
TypeScript
const board = univerAPI.getActiveBoard()const snapshot = board.getData()univer.createUnit(UniverInstanceType.UNIVER_BOARD, snapshot)Facade 导出与 Mermaid 导入
TypeScript
import '@univerjs-pro/exchange-client/facade'import '@univerjs-pro/boards-exchange-client/facade'const file = await univerAPI.exportBoardByUnitIdAsync(board.getId())if (file) univerAPI.downloadFile(file, 'board', 'pptx')await board.insertMermaidAsync('flowchart LR\n A[草稿] --> B[评审]')你觉得这篇文档如何?