GuidesUniver SheetsFeaturesHyperlink

HyperLink

Facade APIPaid VersionUniver ServerUniver on Node.jsPreset
--UniverSheetsHyperLinkPreset
  1. The hyperlink feature allows jumping to worksheets and cells, supporting adding, updating, parsing, and removing links.
  2. Supports inserting hyperlinks within rich text.
  3. Hyperlinks support sub-sheets, ranges/cells, defined names, and standard links (http, mailto, etc.).

This feature includes the following plugin packages:

Installation with Presets

import { createUniver, defaultTheme, LocaleType, Tools } from '@univerjs/presets';
import { UniverSheetsCorePreset } from '@univerjs/presets/preset-sheets-core';
import UniverPresetSheetsCoreEnUS from '@univerjs/presets/preset-sheets-core/locales/en-US';
import { UniverSheetsHyperLinkPreset } from '@univerjs/presets/preset-sheets-hyper-link';
import UniverPresetSheetsHyperLinkEnUS from '@univerjs/presets/preset-sheets-hyper-link/locale/en-US';
 
const { univerAPI } = createUniver({
  locale: LocaleType.EN_US,
  locales: {
    enUS: Tools.deepMerge(
      {},
      UniverPresetSheetsCoreEnUS,
      UniverPresetSheetsHyperLinkEnUS 
    ),
  },
  theme: defaultTheme,
  presets: [
    UniverSheetsCorePreset(),
    UniverSheetsHyperLinkPreset()
  ]
});

Advanced Installation

npm install @univerjs/sheets-hyper-link @univerjs/sheets-hyper-link-ui
import { LocaleType, Tools } from '@univerjs/core';
import { UniverSheetsHyperLinkPlugin } from '@univerjs/sheets-hyper-link';
import { UniverSheetsHyperLinkUIPlugin } from '@univerjs/sheets-hyper-link-ui';
import SheetsHyperLinkUIEnUS from '@univerjs/sheets-hyper-link-ui/locale/en-US';
 
import '@univerjs/sheets-hyper-link-ui/lib/index.css';
 
import '@univerjs/sheets-hyper-link/facade';
 
const univer = new Univer({
  theme: defaultTheme,
  locale: LocaleType.EN_US,
  locales: {
    [LocaleType.EN_US]: Tools.deepMerge(
      SheetsHyperLinkUIEnUS
    ),
  },
});
 
univer.registerPlugin(UniverSheetsHyperLinkPlugin);
univer.registerPlugin(UniverSheetsHyperLinkUIPlugin);

Installation for Univer on Node.js

npm install @univerjs/sheets-hyper-link
import { LocaleType, Tools } from '@univerjs/core';
import { UniverSheetsHyperLinkPlugin } from '@univerjs/sheets-hyper-link';
 
import '@univerjs/sheets-hyper-link/facade';
 
const univer = new Univer({
  theme: defaultTheme,
  locale: LocaleType.EN_US,
});
 
univer.registerPlugin(UniverSheetsHyperLinkPlugin);

Facade API

const workbook = univerAPI.getActiveWorkbook();
const sheet = workbook.getActiveSheet();
const range = sheet.getRange(0, 0, 1, 1);
 
// Create a link to jump to a sheet
// The returned link: `#gid=sheetId`
const sheetLink = workbook.createSheetHyperlink(sheet.getSheetId());
 
// Create a link to jump to a range or cell
// The returned link: `#gid=sheetId&range=A1`
const rangeLink = workbook.createSheetHyperlink(sheet.getSheetId(), range.getRange());
// Or
const rangeLink = workbook.createSheetHyperlink(
  sheet.getSheetId(),
  {
    startRow: 0,
    endRow: 0,
    startColumn: 0,
    endColumn: 0
  }
);
 
// Parse the link, returning information including the link's name, handler, and type
const linkInfo = workbook.parseSheetHyperlink('#gid=sheet&range=A1');
 
// Jump to the link
linkInfo.handler();
 
// Or
workbook.navigateToSheetHyperlink('#gid=sheet&range=A1');
const workbook = univerAPI.getActiveWorkbook();
const sheet = workbook.getActiveSheet();
const range = sheet.getRange(0, 0, 1, 1);
 
// Add a link
const url = workbook.createSheetHyperlink(sheet.getSheetId());
const label = '123';
// If the current cell is not empty, the label can be omitted
await range.setHyperLink(url, label);
 
// Query the hyperlink in the current cell
const links = range.getHyperLinks();
 
// Update the hyperlink
range.updateHyperLink(linkId, url, label);
 
// Remove the hyperlink
range.cancelHyperLink(linkId);