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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheet): absolute ref (#937)
Univer2d8bf71bb8f2
diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex a18075657b..97942a3a26 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -101,6 +101,7 @@ export {deserializeRangeWithSheet,getAbsoluteRefTypeWithSingleString,getAbsoluteRefTypeWitString,+ type IAbsoluteRefTypeForRange,serializeRange,serializeRangeToRefString,serializeRangeWithSheet,diff --git a/packages/core/src/sheets/reference.ts b/packages/core/src/sheets/reference.tsindex 84da023cd6..8247ad74ff 100644--- a/packages/core/src/sheets/reference.ts+++ b/packages/core/src/sheets/reference.ts@@ -28,6 +28,11 @@ export interface IGridRangeName {range: IRange;}+export interface IAbsoluteRefTypeForRange {+ startAbsoluteRefType: AbsoluteRefType;+ endAbsoluteRefType?: AbsoluteRefType;+}+/**** @param singleRefString for example A1 or B10, not A1:B10@@ -55,7 +60,7 @@ export function getAbsoluteRefTypeWithSingleString(singleRefString: string) {** @param refString for example A1:B10*/-export function getAbsoluteRefTypeWitString(refString: string) {+export function getAbsoluteRefTypeWitString(refString: string): IAbsoluteRefTypeForRange {const sheetArray = refString.split('!');if (sheetArray.length > 1) {diff --git a/packages/sheets-formula/src/controllers/prompt.controller.ts b/packages/sheets-formula/src/controllers/prompt.controller.tsindex e450935bd5..08d3a27c80 100644--- a/packages/sheets-formula/src/controllers/prompt.controller.ts+++ b/packages/sheets-formula/src/controllers/prompt.controller.ts@@ -14,8 +14,9 @@* limitations under the License.*/-import type { ICommandInfo, IRangeWithCoord, ITextRun, Nullable } from '@univerjs/core';+import type { IAbsoluteRefTypeForRange, ICommandInfo, IRangeWithCoord, ITextRun, Nullable } from '@univerjs/core';import {+ AbsoluteRefType,deserializeRangeWithSheet,Direction,Disposable,@@ -23,6 +24,7 @@ import {DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,DOCS_NORMAL_EDITOR_UNIT_ID_KEY,FOCUSING_EDITOR_INPUT_FORMULA,+ getAbsoluteRefTypeWitString,ICommandService,IContextService,isFormulaString,@@ -1054,6 +1056,8 @@ export class PromptController extends Disposable {let { startRow, endRow, startColumn, endColumn } = range;+ const { startAbsoluteRefType, endAbsoluteRefType } = range;+if (primary) {const {isMerged,@@ -1086,6 +1090,8 @@ export class PromptController extends Disposable {endRow,startColumn,endColumn,+ startAbsoluteRefType,+ endAbsoluteRefType,},});}@@ -1387,19 +1393,33 @@ export class PromptController extends Disposable {}}+ const nodeIndex = Number(id);++ const currentNode = this._formulaInputService.getCurrentSequenceNodeByIndex(nodeIndex);++ let refType: IAbsoluteRefTypeForRange = { startAbsoluteRefType: AbsoluteRefType.NONE };+ if (typeof currentNode !== 'string') {+ const token = (currentNode as ISequenceNode).token;++ refType = getAbsoluteRefTypeWitString(token) as IAbsoluteRefTypeForRange;++ if (refType.endAbsoluteRefType == null) {+ refType.endAbsoluteRefType = refType.startAbsoluteRefType;+ }+ }+const refString = this._getRefString({range: {- startRow,- endRow,- startColumn,- endColumn,+ startRow: Math.min(startRow, endRow),+ endRow: Math.max(startRow, endRow),+ startColumn: Math.min(startColumn, endColumn),+ endColumn: Math.max(startColumn, endColumn),+ ...refType,},primary,style: null,});- const nodeIndex = Number(id);-this._formulaInputService.updateSequenceRef(nodeIndex, refString);const sequenceNodes = this._formulaInputService.getSequenceNodes();