Skip to content

Commit

Permalink
fix(definedName): set current sheet name
Browse files Browse the repository at this point in the history
  • Loading branch information
Dushusir committed Dec 6, 2024
1 parent 5baf0d0 commit a6ea39c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,13 @@ describe('lexer nodeMaker test', () => {
const result = lexerTreeBuilder.convertRefersToAbsolute('=SUM(A1:B10) + LAMBDA(x, y, x*y*x)(A1:B10, A10) + MAX(A1:B10,SUM(A2))', AbsoluteRefType.ALL, AbsoluteRefType.ALL);
expect(result).toStrictEqual('=SUM($A$1:$B$10) + LAMBDA(x, y, x*y*x)($A$1:$B$10,$A$10) + MAX($A$1:$B$10,SUM($A$2))');
});

it('manually set current sheet name', () => {
let result = lexerTreeBuilder.convertRefersToAbsolute('=A1:B2', AbsoluteRefType.ALL, AbsoluteRefType.ALL, 'Sheet1');
expect(result).toStrictEqual('=Sheet1!$A$1:$B$2');
result = lexerTreeBuilder.convertRefersToAbsolute('=A1:B2,C1:D2,F3:G5', AbsoluteRefType.ALL, AbsoluteRefType.ALL, 'Sheet1');
expect(result).toStrictEqual('=Sheet1!$A$1:$B$2,Sheet1!$C$1:$D$2,Sheet1!$F$3:$G$5');
});
});

describe('moveFormulaRefOffset', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export class LexerTreeBuilder extends Disposable {
return newSequenceNodes;
}

convertRefersToAbsolute(formulaString: string, startAbsoluteRefType: AbsoluteRefType, endAbsoluteRefType: AbsoluteRefType) {
convertRefersToAbsolute(formulaString: string, startAbsoluteRefType: AbsoluteRefType, endAbsoluteRefType: AbsoluteRefType, currentSheetName: string = '') {
const nodes = this.sequenceNodesBuilder(formulaString);
if (nodes == null) {
return formulaString;
Expand Down Expand Up @@ -298,7 +298,7 @@ export class LexerTreeBuilder extends Disposable {
const newToken = serializeRangeToRefString({
range: newRange,
unitId,
sheetName,
sheetName: sheetName || currentSheetName,
});

const minusCount = newToken.length - token.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ export const DefinedNameInput = (props: IDefinedNameInputProps) => {
return;
}

const currentSheetName = workbook.getActiveSheet().getName();
confirm && confirm({
id: id || '',
name: nameValue,
formulaOrRefString: lexerTreeBuilder.convertRefersToAbsolute(formulaOrRefStringValue, AbsoluteRefType.ALL, AbsoluteRefType.ALL),
formulaOrRefString: lexerTreeBuilder.convertRefersToAbsolute(formulaOrRefStringValue, AbsoluteRefType.ALL, AbsoluteRefType.ALL, currentSheetName),
comment: commentValue,
localSheetId: localSheetIdValue,
});
Expand Down

0 comments on commit a6ea39c

Please sign in to comment.