Univer
Univer Sheet
Features
Default Style

Sheet Default Style 0.4.2+

📊 Univer Sheet

We provide two levels of default styles: the default style of the worksheet and the default style of the column or row. Both can be set through the IWorksheetData interface or the Facade API.

Configuration

By default, the column style takes precedence over the row style. You can change this behavior by setting isRowStylePrecedeColumnStyle during registration.

  univer.registerPlugin(UniverSheetsPlugin, {
      isRowStylePrecedeColumnStyle: true,
  });

Set Default Style

There are two ways to set the default style of a worksheet:

  1. Through the IWorksheetData interface
    interface IWorksheetData{
        // other
        /**
         * @property {Nullable<IStyleData>} [defaultStyle] - Default style data of Worksheet.
         */
        defaultStyle?: Nullable<IStyleData>;
 
    }
 
    interface IRowData{
        // other
        /**
         * style data
         */
        s?: Nullable<IStyleData>;
    }
 
    interface IColumnData{
      // other
      /**
       * style data
       */
      s?: Nullable<IStyleData>;
    }
  1. Set through the Facade API
  const fworkbook = univerAPI.getActiveWorkbook()
  const fworksheet = fworkbook.getActiveSheet()
  const defaultStyle = {
      bg: {
          rgb: 'red'
      }
  }
  const defaultColumnStyle = {
      bg: {
          rgb: 'blue'
      }
  }
  // set default style
  fworksheet.setDefaultStyle(defaultStyle)
  // set default column style
  fworksheet.setColumnDefaultStyle(3, defaultColumnStyle)
  // reset the column default style
  fworksheet.setColumnDefaultStyle(3, undefined)
 
  // set row default style
  fworksheet.setRowDefaultStyle(1, defaultColumnStyle)

Copyright © 2021-2024 DreamNum Co,Ltd. All Rights Reserved.