범위 테마

테이블이 표시된 방법을 제공합니다. Univer는 미리 설정 테마 세트를 제공하며, 자체 테마를 정의할 수 있습니다.

기본 제공 테마

기본 테마는 default라는 이름이며 Excel Table default style를 따릅니다. theme 속성을 통해 적용됩니다. Univer는 색상 테마 세트를 제공합니다. Facade API 아래 목록은 현재 지원되는 테마입니다.

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const themes = fWorkbook.getRegisteredRangeThemes()console.log(themes) // ['default', 'light-blue', 'light-grey', 'light-red', 'light-orange', 'light-yellow', 'light-green', 'light-azure', 'light-indigo', 'light-purple', 'light-magenta', 'middle-blue', 'middle-grey', 'middle-red', 'middle-orange', 'middle-yellow', 'middle-green', 'middle-azure', 'middle-indigo', 'middle-purple', 'middle-magenta', 'dark-blue', 'dark-grey', 'dark-red', 'dark-orange', 'dark-yellow', 'dark-green', 'dark-azure', 'dark-indigo', 'dark-purple', 'dark-magenta']

테마 설정

범위 테마는 스냅 샷 또는 Facade API를 통해 두 가지 방법으로 설정할 수 있습니다.

스냅샷으로 테마 설정

Univer 상점은 열쇠 SHEET_RANGE_THEME_MODEL_PLUGIN의 밑에 스냅샷 자원에 있는 테마를 배열합니다. 자료 구조는 다음과 같이 입니다:

TypeScript
interface IRangeThemeRangeInfo {  range: IRange  unitId: string  subUnitId: string}interface IRangeThemeStyleRule {  rangeInfo: IRangeThemeRangeInfo  themeName: string}interface ISheetRangeThemeModelJSON {  // JSON storing the range and theme information for setting themes, the key is the id, please ensure it is not repeated, the value is the corresponding range information and template name.  rangeThemeStyleRuleMap: Record<string, IRangeThemeStyleRule>  // JSON storing the themes, the key is the theme name, and the value is the serialized JSON of the theme.  rangeThemeStyleMapJson: Record<string, IRangeThemeStyleJSON>}

Facade API로 테마 설정

Facade API를 통해 테마를 설정하고 Univer가 제공하는 직렬화 및 deserialization 메소드와 테마 정보를 저장하는 것이 좋습니다.

다음 APIs는 테마 워크플로우를 다룹니다:

TypeScript
// Get the currently supported themesconst fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getActiveSheet()const themes = fWorkbook.getRegisteredRangeThemes()// Set the default theme for A1:E20const fRange = fWorksheet.getRange('A1:E20')fRange.useThemeStyle('default') // 使用默认主题// Get the currently used themeconst currentTheme = fRange.getUsedThemeStyle()// Clear the theme stylefRange.useThemeStyle(undefined)fRange.removeThemeStyle(currentTheme)

사용자 지정 테마

내장 테마를 넘어, Univer는 또한 사용자 정의 테마를 지원합니다:

TypeScript
// Create a custom themeconst fWorkbook = univerAPI.getActiveWorkbook()const rangeThemeStyle = fWorkbook.createRangeThemeStyle('MyTheme', {  secondRowStyle: {    bg: {      rgb: 'rgb(214,231,241)',    },  },})fWorkbook.registerRangeTheme(rangeThemeStyle)// Use the custom theme for A1:E20const fWorksheet = fWorkbook.getActiveSheet()const fRange = fWorksheet.getRange('A1:E20')// Make sure the theme is registered, otherwise it will throw an error.fRange.useThemeStyle('MyTheme')

다음 호출은 등록 된 테마를 제거합니다.

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()fWorkbook.unregisterRangeTheme('MyTheme')

RangeThemeStyle 클래스

범위 테마는 RangeThemeStyle 클래스에 내장되어 있으며, 다음과 같은 속성을 사용자 정의 할 수 있습니다.

  • name: 테마 이름
  • wholeStyle : 전체 범위의 스타일
  • firstRowStyle: 첫번째 줄을 위한 작풍
  • secondRowStyle : 두 번째 행의 스타일
  • headerRowStyle : 헤더 행의 스타일
  • lastRowStyle: 마지막 줄을 위한 작풍
  • firstColumnStyle: 첫번째 란을 위한 작풍
  • secondColumnStyle : 두 번째 열에 대한 스타일
  • headerColumnStyle : 헤더 컬럼의 스타일
  • lastColumnStyle: 마지막 란을 위한 작풍

각 스타일은 RangeThemeStyle 클래스의 getXXX/setXXX 방법의 일치 쌍을 가지고 있습니다. 예를 들어:

TypeScript
const rangeThemeStyle = new RangeThemeStyle('MyTheme')rangeThemeStyle.setSecondRowStyle({  bg: {    rgb: 'rgb(214,231,241)',  },})

구성자에 옵션을 전달할 수 있습니다.

TypeScript
/** * @constructor * @param {string} name The name of the range theme style, it used to identify the range theme style. * @param {IRangeThemeStyleJSON} [options] The options to initialize the range theme style. */class RangeThemeStyle {};// For example:const rangeThemeStyle = new RangeThemeStyle('MyTheme', {  secondRowStyle: {    bg: {      rgb: 'rgb(214,231,241)',    },  },})

몇몇 작풍이 정의될 때, 그들은 우선권의 뒤에 오는 순서에 적용합니다:

lastRowStyle > headerRowStyle > lastColumnStyle > headerColumnStyle > secondRowStyle > firstRowStyle > secondColumnStyle > firstColumnStyle > wholeStyle

range theme와 셀 자체 스타일 충돌이 발생하면 셀 스타일이 우선합니다. 동일한 스타일 속성을 정의 할 때 충돌이 발생합니다. 예를 들어, 셀은 red에 배경을 설정하고 range theme는 blue로 설정하면 셀은 red를 유지합니다.

이 가이드는 어떠셨나요?

© 2026 DreamNum Co., Ltd.