FRangeLegacy
| packages | @univerjs/sheets-numfmt |
|---|
APIs
getNumberFormat
Get the number formatting of the top-left cell of the given range. Empty cells return an empty string.
Signature
getNumberFormat(): stringReturns
- (
string) — The number format of the top-left cell of the range.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
// Get the number format of the top-left cell of the A1:B2 range.
const fRange = fWorksheet.getRange('A1:B2')
console.log(fRange.getNumberFormat())getNumberFormats
Returns the number formats for the cells in the range.
Signature
getNumberFormats(): string[][]Returns
- (
string[][]) — A two-dimensional array of number formats.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
// Get the number formats of the A1:B2 range.
const fRange = fWorksheet.getRange('A1:B2')
console.log(fRange.getNumberFormats())setNumberFormat
Set the number format of the range.
Signature
setNumberFormat(pattern: string): FRangeParameters
pattern(string) — - The number format pattern.
Returns
- (
FRange) — The FRange instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
// Set the number format of the A1 cell to '#,##0.00'.
const fRange = fWorksheet.getRange('A1')
fRange.setValue(1234.567).setNumberFormat('#,##0.00')
console.log(fRange.getDisplayValue()) // 1,234.57setNumberFormats
Sets a rectangular grid of number formats (must match dimensions of this range).
Signature
setNumberFormats(patterns: string[][]): FRangeParameters
patterns(string[][]) — - A two-dimensional array of number formats.
Returns
- (
FRange) — The FRange instance for chaining.
Examples
const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
// Set the number formats of the A1:B2 range.
const fRange = fWorksheet.getRange('A1:B2')
fRange.setValues([
[1234.567, 0.1234],
[45658, 0.9876],
]).setNumberFormats([
['#,##0.00', '0.00%'],
['yyyy-MM-DD', ''],
])
console.log(fRange.getDisplayValues()) // [['1,234.57', '12.34%'], ['2025-01-01', 0.9876]]