在 Angular 中整合

請先閱讀安裝和基本使用。下面的範例在 Angular 元件中掛載 Univer Pdfs,容器需要指定明確的高度。

整合步驟

  1. 在 ngAfterViewInit 中建立 Univer 例項。
  2. 在 ngOnDestroy 中銷燬該例項。

外掛設定

UniverUIPlugin

  • container
    string | HTMLElement
    編輯器掛載的 DOM 元素或元素 ID。

UniverLicensePlugin

  • license
    string
    用戶端授權檔的內容。

範例程式碼

TypeScript
import type { AfterViewInit, ElementRef, OnDestroy } from '@angular/core'import { Component, ViewChild } from '@angular/core'import { UniverLicensePlugin } from '@univerjs-pro/license'import { UniverPdfsPlugin } from '@univerjs-pro/pdfs'import { UniverPdfsUIPlugin } from '@univerjs-pro/pdfs-ui'import PdfsUIzhTW from '@univerjs-pro/pdfs-ui/locale/zh-TW'import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import { FUniver } from '@univerjs/core/facade'import DesignzhTW from '@univerjs/design/locale/zh-TW'import { UniverUIPlugin } from '@univerjs/ui'import UIzhTW from '@univerjs/ui/locale/zh-TW'import '@univerjs/design/lib/index.css'import '@univerjs/ui/lib/index.css'import '@univerjs-pro/pdfs-ui/lib/index.css'import '@univerjs-pro/pdfs/facade'@Component({  selector: 'app-univer',  standalone: true,  template: '<div #container style="height: 600px"></div>',})export class UniverComponent implements AfterViewInit, OnDestroy {  @ViewChild('container') containerRef!: ElementRef<HTMLDivElement>  private univer?: Univer  ngAfterViewInit() {    const container = this.containerRef.nativeElement    const univer = new Univer({      locale: LocaleType.ZH_TW,      locales: {        [LocaleType.ZH_TW]: mergeLocales(          DesignzhTW,          UIzhTW,          PdfsUIzhTW,        ),      },    })    univer.registerPlugin(UniverLicensePlugin, {      license: 'your license.txt',    })    univer.registerPlugin(UniverUIPlugin, { container })    univer.registerPlugin(UniverPdfsPlugin)    univer.registerPlugin(UniverPdfsUIPlugin)    const univerAPI = FUniver.newAPI(univer)    univerAPI.createPdf({ name: 'Untitled PDF' })    this.univer = univer  }  ngOnDestroy() {    this.univer?.dispose()  }}

你覺得這篇文檔如何?

© 2026 DreamNum Co., Ltd.