# Default Style

- Human documentation: [https://docs.univer.ai/guides/sheets/features/core/default-style](https://docs.univer.ai/guides/sheets/features/core/default-style)

- Agent Markdown: [https://docs.univer.ai/guides/sheets/features/core/default-style.md](https://docs.univer.ai/guides/sheets/features/core/default-style.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [sheets/features/core/default-style.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/sheets/features/core/default-style.mdx)

---

We provide two levels of default styles:

1. The default style of the worksheet
2. The default style of the column or row

Both can be set through the [`IWorksheetData`](https://reference.univer.ai/en-US/interfaces/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.

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

## Set Default Style

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

1. Through the [`IWorksheetData`](https://reference.univer.ai/en-US/interfaces/IWorksheetData) interface

```typescript
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>
}
```

2. Set through the Facade API

```typescript
const fworkbook = univerAPI.getActiveWorkbook()
const fworksheet = fworkbook.getActiveSheet()
const defaultStyle = {
  bg: {
    rgb: 'red',
  },
}
const defaultColumnStyle = {
  bg: {
    rgb: 'blue',
  },
}
const defaultRowStyle = {
  bg: {
    rgb: 'green',
  },
}

// set default style
fworksheet.setDefaultStyle(defaultStyle)
// set column D default style
fworksheet.setColumnDefaultStyle(3, defaultColumnStyle)
// reset column D the default style
fworksheet.setColumnDefaultStyle(3, undefined)

// set row default style
fworksheet.setRowDefaultStyle(1, defaultRowStyle)
```

## Shrink text to fit

Use `FRange` to shrink text when it is wider than its cell. The setting applies to every cell in the range; `getShrinkToFit()` reads the top-left cell.

```ts
const range = univerAPI.getActiveWorkbook().getActiveSheet().getRange('A1:C3')

range.setShrinkToFit(true)
const enabled = range.getShrinkToFit()
```
