Skip to content

API

Import

ts
import {
  OfficeExcel,
  createOfficeExcelYWebSocketCommandAdapter,
  type OfficeExcelPublicApi,
  type OfficeExcelWorkbookSnapshot,
} from '@norio-office/office-excel'

Props

PropTypeDefaultDescription
modelValue / v-modelOfficeExcelWorkbookSnapshot | nullnullFull workbook data bound from outside. Passing null creates a default workbook.
titlestringOnline SpreadsheetDefault workbook title and one source for export file names.
sheetNamestringSheet1Default sheet name, only used when no modelValue is provided.
rowCountnumber40Initial row count for the default sheet.
colCountnumber26Initial column count for the default sheet.
mode'tabs' | 'menu'tabsToolbar display mode.
readonlybooleanfalseView-only mode. Allows selection, sheet switching, copy, and export.
disabledbooleanfalseDisables internal interaction.
widthnumber | stringundefinedComponent width. Numbers are treated as pixels.
heightnumber | stringundefinedComponent height. Numbers are treated as pixels.
toolbarOfficeExcelToolbarOptions | nullnullToolbar visibility configuration.
permissionsOfficeExcelPermissions | nullnullFeature permissions.
backgroundImagesOfficeExcelBackgroundImage[][]External background image list.
collaborationOfficeExcelCollaborationOptions | nullnullOptional collaboration configuration.

Collaboration

ts
type OfficeExcelCollaborationRole = 'owner' | 'editor' | 'commenter' | 'viewer'

interface OfficeExcelCollaborationUser {
  userId?: string
  displayName: string
  color?: string
}

interface OfficeExcelCollaborationOptions {
  enabled?: boolean
  mode?: 'server-authoritative'
  workbookId?: string
  clientId?: string
  token?: string
  endpoint?: string
  role?: OfficeExcelCollaborationRole
  document?: unknown
  provider?: OfficeExcelCollaborationProvider | null
  user?: OfficeExcelCollaborationUser | null
  submitCommand?: (envelope: OfficeExcelCollaborationCommandEnvelope) =>
    void | OfficeExcelCollaborationCommandResult | Promise<void | OfficeExcelCollaborationCommandResult>
  uploadAsset?: (file: File, context: OfficeExcelAssetContext) => Promise<OfficeExcelAssetReference>
  resolveAsset?: (asset: OfficeExcelAssetReference, context: OfficeExcelAssetContext) => Promise<OfficeExcelResolvedAsset>
}
FieldDescription
enabledEnables the collaboration integration. When false, the component runs as a local single-user spreadsheet.
workbookIdStable workbook or room ID. Keep it identical for all clients opening the same file.
clientIdStable client instance ID. The same user opening two windows must use two different values.
documentExternal Y.Doc. The component writes the workbook mirror into it and reads remote Yjs updates back.
providerExternal Yjs provider. The component uses provider.awareness for remote selections and online user state; the command adapter can reuse its WebSocket.
submitCommandSubmits local semantic commands to the backend. The recommended implementation is commandAdapter.submitCommand(envelope) from createOfficeExcelYWebSocketCommandAdapter(provider).
uploadAssetUploads large assets such as images in collaboration mode. Avoid writing base64 blobs directly into Y.Doc.
resolveAssetResolves asset references into real binary content when exporting .xlsx.
ts
interface OfficeExcelCollaborationCommandAck {
  type: 'command.ack'
  requestId: string
  opId?: string
  workbookId: string
  accepted: true
  serverSeq?: number
}

interface OfficeExcelCollaborationCommandReject {
  type: 'command.reject'
  requestId: string
  opId?: string
  workbookId: string
  accepted: false
  code: 'INVALID_COMMAND' | 'STALE_TARGET' | 'CONFLICT' | 'SERVER_ERROR'
  reason: string
}

Return standard command.reject results to the component instead of throwing. The component clears pending state, rolls back the optimistic local change, and emits collaboration-command-reject.

Collaboration commands use the WebSocket command channel, not an HTTP command endpoint. The built-in adapter sends a y-websocket-compatible binary message with messageType=100 and a JSON command payload, then matches backend command.ack / command.reject responses by requestId. HTTP is still suitable for image, background, watermark, and attachment asset services.

Toolbar

ts
type OfficeExcelToolbarTabId =
  | 'start'
  | 'insert'
  | 'data'
  | 'formula'
  | 'collab'
  | 'view'
  | 'efficiency'

interface OfficeExcelToolbarOptions {
  visibleTabs?: OfficeExcelToolbarTabId[]
  hiddenTabs?: OfficeExcelToolbarTabId[]
  visibleCommands?: string[]
  hiddenCommands?: string[]
}

Common tab IDs: start, insert, data, formula, collab, view, efficiency.

Common command IDs include copy, cut, paste, font-size, font-color, fill-color, bold, italic, underline, download, image, watermark, filter, sort, import-data, zoom, gridlines, background, export-image, collab-lock-cells, and collab-claim-cells.

Secondary collaboration command IDs include collab-lock-selected-cells, collab-unlock-selected-cells, collab-enable-cell-claim, collab-release-selected-cell-claim, collab-disable-cell-claim-keep, and collab-disable-cell-claim-release.

Permissions

ts
interface OfficeExcelPermissions {
  edit?: boolean
  import?: boolean
  export?: boolean
  manageSheets?: boolean
  insertImages?: boolean
  insertCharts?: boolean
  format?: boolean
}
PermissionEffect when false
editDisables cell content editing and write operations.
importDisables internal import entry and importExcel.
exportDisables internal export entry, exportExcel, and downloadJson.
manageSheetsDisables sheet creation, copy, rename, move, delete, hide, pin, and protect actions.
insertImagesDisables image insertion.
insertChartsDisables chart insertion.
formatDisables font, color, border, style template, and number formatting features.

Events

EventPayloadTiming
update:modelValueOfficeExcelWorkbookSnapshotEmits the current workbook for v-model.
changeOfficeExcelChangePayloadWorkbook content changes.
selection-changeOfficeExcelSelectionRangeCurrent selection changes.
readyOfficeExcelReadyPayloadComponent initialization is complete.
errorOfficeExcelErrorPayloadImport, export, load, or runtime errors.
active-sheet-changeOfficeExcelActiveSheetChangePayloadActive sheet changes.
cell-clickOfficeExcelCellEventPayloadCell click.
cell-dblclickOfficeExcelCellEventPayloadCell double click.
cell-edit-startOfficeExcelCellEditEventPayloadCell editing starts.
cell-edit-endOfficeExcelCellEditEventPayloadCell editing ends.
before-exportOfficeExcelBeforeExportPayloadBefore Excel export starts.
after-exportOfficeExcelAfterExportPayloadAfter Excel export succeeds.
before-importOfficeExcelBeforeImportPayloadBefore Excel import starts.
after-importOfficeExcelAfterImportPayloadAfter Excel import succeeds.
collaboration-command-ackOfficeExcelCollaborationCommandAckA collaboration command is accepted by the server.
collaboration-command-rejectOfficeExcelCollaborationCommandRejectA collaboration command is rejected and optimistic local changes are rolled back.
collaboration-errorOfficeExcelErrorPayloadCollaboration command submission or asset handling fails unexpectedly.

Instance API

ts
interface OfficeExcelPublicApi {
  importExcel: (source: OfficeExcelImportExcelInput, options?: OfficeExcelImportExcelOptions) => Promise<OfficeExcelWorkbookSnapshot>
  exportExcel: (options?: OfficeExcelExportExcelOptions | string) => Promise<string>
  exportJson: () => OfficeExcelWorkbookSnapshot
  downloadJson: (options?: OfficeExcelDownloadJsonOptions | string) => string
  getWorkbook: () => OfficeExcelWorkbookSnapshot
  setWorkbook: (workbook: OfficeExcelWorkbookSnapshot, options?: OfficeExcelLoadWorkbookOptions) => void
  serialize: () => string
  load: (snapshot: string | OfficeExcelWorkbookSnapshot, options?: OfficeExcelLoadWorkbookOptions) => void
  getSelection: () => OfficeExcelSelectionRange
  setSelection: (selection: OfficeExcelSelectionRange) => void
  applyCollaborationCommandResult: (result: OfficeExcelCollaborationCommandResult) => void
  getPlainText: {
    (): OfficeExcelPlainTextSheetData[]
    (sheetId: string): string[][]
  }
  getActiveSheetData: () => string[][]
}

importExcel supports Blob, ArrayBuffer, and ArrayBufferView. exportExcel downloads .xlsx. exportJson returns data without downloading. downloadJson downloads a JSON snapshot. getPlainText() returns plain text only and does not include styles, merged cells, images, charts, or watermarks.

Data Model

ts
type OfficeExcelWorkbookSnapshot = OfficeExcelWorkbook

interface OfficeExcelWorkbook {
  title: string
  sheets: OfficeExcelSheet[]
  activeSheetId: string
  watermark: OfficeExcelWatermarkSettings | null
}

The workbook snapshot is the persistence format used by v-model. For long-term storage, prefer saving the whole snapshot instead of manually constructing many internal cell keys.

Built with VitePress