Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

2.5 KB
Raw Blame
/**
 * Copyright 2023-present DreamNum Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import type { INumfmtLocaleTag } from '@univerjs/core';
import { SheetsNumfmtCellContentController } from '@univerjs/sheets-numfmt';
import { FWorkbook } from '@univerjs/sheets/facade';

export interface IFWorkbookSheetsNumfmtMixin {
    /**
     * Set the locale for number formatting.
     * @param {INumfmtLocaleTag} locale zh_CN,zh_TW,zh_HK,ja,ko,th,cs,da,nl,en,en_AU,en_CA,en_GB,en_IE,fi,fr,fr_CA,fr_CH,de,de_CH,el,hu,is,id,it,it_CH,nb,no,pl,pt,pt_BR,ru,sk,es,es_AR,es_BO,es_CL,es_CO,es_EC,es_MX,es_PY,es_UY,es_VE,sv,tr,cy,az,be,bg,ca,fil,gu,he,hr,hy,ka,kk,kn,lt,lv,ml,mn,mr,my,pa,ro,sl,sr,ta,te,uk,vi,ar,bn,hi
     * @returns {FWorkbook} The FWorkbook instance for chaining.
     * @memberof IFWorkbookNumfmtMixin
     * @example
     * ```ts
     * const fWorkbook = univerAPI.getActiveWorkbook();
     * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
     * if (!fWorksheet) return;
     * const fRange = fWorksheet.getRange('A1');
     * fRange.setValue(1234.567).setNumberFormat('#,##0.00');
     *
     * // Set the locale en_US for number formatting.
     * fWorkbook.setNumfmtLocal('en_US');
     * console.log(fRange.getDisplayValue()); // 1,234.57
     *
     * // Set the locale de_DE for number formatting.
     * fWorkbook.setNumfmtLocal('de_DE');
     * console.log(fRange.getDisplayValue()); // 1.234,57
     * ```
     */
    setNumfmtLocal(locale: INumfmtLocaleTag): FWorkbook;
}
export class FWorkbookSheetsNumfmtMixin extends FWorkbook implements IFWorkbookSheetsNumfmtMixin {
    override setNumfmtLocal(locale: INumfmtLocaleTag): FWorkbook {
        const sheetsNumfmtCellContentController = this._injector.get(SheetsNumfmtCellContentController);
        sheetsNumfmtCellContentController.setNumfmtLocal(locale);
        return this;
    }
}
FWorkbook.extend(FWorkbookSheetsNumfmtMixin);
declare module '@univerjs/sheets/facade' {
    // eslint-disable-next-line ts/naming-convention
    interface FWorkbook extends IFWorkbookSheetsNumfmtMixin { }
}