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.

fix(formula): deserializeRangeWithSheet add rangeType (#1166)

Dushusirc6fcb1e1ea74
diff --git a/packages/core/src/sheets/__tests__/reference.spec.ts b/packages/core/src/sheets/__tests__/reference.spec.ts
index a70b1827f2..d1716402e3 100644
--- a/packages/core/src/sheets/__tests__/reference.spec.ts
+++ b/packages/core/src/sheets/__tests__/reference.spec.ts
@@ -110,6 +110,19 @@ describe('Test Reference', () => {
unitId: 'workbook1',
})
).toEqual('[workbook1]sheet1!A:K');
+ expect(
+ serializeRangeToRefString({
+ range: {
+ startColumn: NaN,
+ endColumn: NaN,
+ startRow: 15,
+ endRow: 15,
+ rangeType: RANGE_TYPE.ROW,
+ },
+ sheetName: 'sheet1',
+ unitId: 'workbook1',
+ })
+ ).toEqual('[workbook1]sheet1!16:16');
});
it('deserializeRangeWithSheet', () => {
@@ -121,6 +134,7 @@ describe('Test Reference', () => {
startAbsoluteRefType: 0,
startColumn: 0,
startRow: 4,
+ rangeType: RANGE_TYPE.NORMAL,
},
sheetName: 'sheet1',
unitId: 'workbook1',
@@ -134,6 +148,7 @@ describe('Test Reference', () => {
startAbsoluteRefType: 0,
startColumn: 0,
startRow: 4,
+ rangeType: RANGE_TYPE.NORMAL,
},
sheetName: 'sheet1',
unitId: 'workbook2',
@@ -147,6 +162,7 @@ describe('Test Reference', () => {
startAbsoluteRefType: AbsoluteRefType.NONE,
startColumn: 0,
startRow: NaN,
+ rangeType: RANGE_TYPE.COLUMN,
},
sheetName: 'sheet1',
unitId: 'workbook2',
@@ -160,6 +176,7 @@ describe('Test Reference', () => {
startAbsoluteRefType: AbsoluteRefType.NONE,
startColumn: NaN,
startRow: 9,
+ rangeType: RANGE_TYPE.ROW,
},
sheetName: 'sheet1',
unitId: 'workbook2',
@@ -173,6 +190,7 @@ describe('Test Reference', () => {
startAbsoluteRefType: AbsoluteRefType.NONE,
startColumn: NaN,
startRow: 9,
+ rangeType: RANGE_TYPE.ROW,
},
sheetName: '',
unitId: '',
@@ -186,6 +204,7 @@ describe('Test Reference', () => {
startAbsoluteRefType: AbsoluteRefType.NONE,
startColumn: NaN,
startRow: 9,
+ rangeType: RANGE_TYPE.ROW,
},
sheetName: 'sheet-1',
unitId: 'workbook2',
diff --git a/packages/core/src/sheets/reference.ts b/packages/core/src/sheets/reference.ts
index 3138b74251..d8b621804e 100644
--- a/packages/core/src/sheets/reference.ts
+++ b/packages/core/src/sheets/reference.ts
@@ -263,6 +263,13 @@ export function deserializeRangeWithSheet(refString: string): IGridRangeName {
const endRow = endGrid.row;
const endColumn = endGrid.column;
+ let rangeType = RANGE_TYPE.NORMAL;
+ if (isNaN(startRow) && isNaN(endRow)) {
+ rangeType = RANGE_TYPE.COLUMN;
+ } else if (isNaN(startColumn) && isNaN(endColumn)) {
+ rangeType = RANGE_TYPE.ROW;
+ }
+
return {
unitId,
sheetName,
@@ -275,6 +282,8 @@ export function deserializeRangeWithSheet(refString: string): IGridRangeName {
startAbsoluteRefType: startGrid.absoluteRefType,
endAbsoluteRefType: endGrid.absoluteRefType,
+
+ rangeType,
},
};
}