diff --git a/packages/engine-formula/src/basics/date.ts b/packages/engine-formula/src/basics/date.ts index 0bcf9b53ecf..9a3b3201de2 100644 --- a/packages/engine-formula/src/basics/date.ts +++ b/packages/engine-formula/src/basics/date.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -export const DEFFAULT_DATE_FORMAT = 'yyyy/mm/dd'; +export const DEFFAULT_DATE_FORMAT = 'yyyy-mm-dd;@'; /** * Excel stores dates as sequential serial numbers so they can be used in calculations. By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,447 days after January 1, 1900. diff --git a/packages/engine-formula/src/engine/ast-node/suffix-node.ts b/packages/engine-formula/src/engine/ast-node/suffix-node.ts index c3cb14d3bd6..2a5f047ecd2 100644 --- a/packages/engine-formula/src/engine/ast-node/suffix-node.ts +++ b/packages/engine-formula/src/engine/ast-node/suffix-node.ts @@ -63,6 +63,9 @@ export class SuffixNode extends BaseAstNode { value as BaseValueObject, new NumberValueObject(100) ) as FunctionVariantType; + + // set number format + result.setPattern('0.00%'); } else if (this._operatorString === suffixToken.POUND) { result = this._handlerPound(value); } else { diff --git a/packages/engine-formula/src/models/formula-data.model.ts b/packages/engine-formula/src/models/formula-data.model.ts index 33a5d56b461..62d3a9085e9 100644 --- a/packages/engine-formula/src/models/formula-data.model.ts +++ b/packages/engine-formula/src/models/formula-data.model.ts @@ -185,6 +185,10 @@ export class FormulaDataModel extends Disposable { return this._numfmtItemMap; } + getNumfmtValue(unitId: string, sheetId: string, row: number, column: number) { + return this._numfmtItemMap[unitId]?.[sheetId]?.[row]?.[column]; + } + setNumfmtItemMap(value: INumfmtItemMap) { this._numfmtItemMap = value; } diff --git a/packages/sheets-formula/src/controllers/formula-clipboard.controller.ts b/packages/sheets-formula/src/controllers/formula-clipboard.controller.ts index c05ed52fae0..1d212693b51 100644 --- a/packages/sheets-formula/src/controllers/formula-clipboard.controller.ts +++ b/packages/sheets-formula/src/controllers/formula-clipboard.controller.ts @@ -61,6 +61,7 @@ export class FormulaClipboardController extends Disposable { private _pasteFormulaHook(): ISheetClipboardHook { const specialPasteFormulaHook: ISheetClipboardHook = { id: SPECIAL_PASTE_FORMULA, + priority: 10, specialPasteInfo: { label: 'specialPaste.formula', }, @@ -96,6 +97,7 @@ export class FormulaClipboardController extends Disposable { private _pasteWithFormulaHook(): ISheetClipboardHook { const specialPasteFormulaHook: ISheetClipboardHook = { id: DEFAULT_PASTE_FORMULA, + priority: 10, onPasteCells: (pasteFrom, pasteTo, data, payload) => { const copyInfo = { copyType: payload.copyType || COPY_TYPE.COPY, diff --git a/packages/sheets-numfmt/package.json b/packages/sheets-numfmt/package.json index fe51234bd4e..9caf4f14f4d 100644 --- a/packages/sheets-numfmt/package.json +++ b/packages/sheets-numfmt/package.json @@ -54,6 +54,7 @@ "peerDependencies": { "@univerjs/core": "workspace:*", "@univerjs/design": "workspace:*", + "@univerjs/engine-formula": "workspace:*", "@univerjs/engine-numfmt": "workspace:*", "@univerjs/engine-render": "workspace:*", "@univerjs/sheets": "workspace:*", @@ -70,6 +71,7 @@ "@types/react": "^18.2.53", "@univerjs/core": "workspace:*", "@univerjs/design": "workspace:*", + "@univerjs/engine-formula": "workspace:*", "@univerjs/engine-numfmt": "workspace:*", "@univerjs/engine-render": "workspace:*", "@univerjs/shared": "workspace:*", diff --git a/packages/sheets-numfmt/src/menu/menu.ts b/packages/sheets-numfmt/src/menu/menu.ts index 948f2ea5a2e..c780b344d3f 100644 --- a/packages/sheets-numfmt/src/menu/menu.ts +++ b/packages/sheets-numfmt/src/menu/menu.ts @@ -28,6 +28,7 @@ import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from ' import type { IAccessor } from '@wendellhu/redi'; import { merge, Observable } from 'rxjs'; +import { FormulaDataModel } from '@univerjs/engine-formula'; import { MENU_OPTIONS } from '../base/const/MENU-OPTIONS'; import { AddDecimalCommand } from '../commands/commands/add-decimal.command'; import { SetCurrencyCommand } from '../commands/commands/set-currency.command'; @@ -96,6 +97,7 @@ export const FactoryOtherMenuItem = (componentManager: ComponentManager) => { return (_accessor: IAccessor) => { const numfmtService = _accessor.get(INumfmtService); + const formulaDataModel = _accessor.get(FormulaDataModel); const univerInstanceService = _accessor.get(IUniverInstanceService); const commandService = _accessor.get(ICommandService); const localeService = _accessor.get(LocaleService); @@ -121,11 +123,14 @@ export const FactoryOtherMenuItem = (componentManager: ComponentManager) => { const range = selections[0].range; const row = range.startRow; const col = range.startColumn; + const numfmtValue = numfmtService.getValue(workbook.getUnitId(), worksheet.getSheetId(), row, col); + const numfmtValueByFormula = formulaDataModel.getNumfmtValue(workbook.getUnitId(), worksheet.getSheetId(), row, col); + + const pattern = numfmtValue?.pattern || numfmtValueByFormula; let value: string = localeService.t('sheet.numfmt.general'); - if (numfmtValue) { - const pattern = numfmtValue.pattern; + if (pattern) { const item = MENU_OPTIONS.filter((item) => typeof item === 'object' && item.pattern).find( (item) => isPatternEqualWithoutDecimal(pattern, (item as { pattern: string }).pattern) ); diff --git a/packages/sheets-numfmt/vite.config.ts b/packages/sheets-numfmt/vite.config.ts index 8e4292cd0a5..44482821f80 100644 --- a/packages/sheets-numfmt/vite.config.ts +++ b/packages/sheets-numfmt/vite.config.ts @@ -8,6 +8,7 @@ export default ({ mode }) => createViteConfig({ '@univerjs/core', '@univerjs/design', '@univerjs/engine-formula', + '@univerjs/engine-numfmt', '@univerjs/engine-render', '@univerjs/sheets', '@univerjs/sheets-ui', @@ -24,6 +25,7 @@ export default ({ mode }) => createViteConfig({ '@univerjs/core': 'UniverCore', '@univerjs/design': 'UniverDesign', '@univerjs/engine-formula': 'UniverEngineFormula', + '@univerjs/engine-numfmt': 'UniverEngineNumfmt', '@univerjs/engine-render': 'UniverEngineRender', '@univerjs/sheets': 'UniverSheets', '@univerjs/sheets-ui': 'UniverSheetsUi', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 56f9cb183dd..46854f01cae 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -803,6 +803,9 @@ importers: '@univerjs/design': specifier: workspace:* version: link:../design + '@univerjs/engine-formula': + specifier: workspace:* + version: link:../engine-formula '@univerjs/engine-numfmt': specifier: workspace:* version: link:../engine-numfmt