@@ -416,48 +416,30 @@ func (f *File) adjustFormulaOperand(sheet, sheetN string, keepRelative bool, tok
416
416
// adjustFormulaRef returns adjusted formula by giving adjusting direction and
417
417
// the base number of column or row, and offset.
418
418
func (f * File ) adjustFormulaRef (sheet , sheetN , formula string , keepRelative bool , dir adjustDirection , num , offset int ) (string , error ) {
419
- var (
420
- val string
421
- definedNames []string
422
- ps = efp .ExcelParser ()
423
- )
419
+ var definedNames []string
424
420
for _ , definedName := range f .GetDefinedName () {
425
421
if definedName .Scope == "Workbook" || definedName .Scope == sheet {
426
422
definedNames = append (definedNames , definedName .Name )
427
423
}
428
424
}
429
- for _ , token := range ps .Parse (formula ) {
425
+ ps := efp .ExcelParser ()
426
+ tokens := ps .Parse (formula )
427
+ for i , token := range tokens {
430
428
if token .TType == efp .TokenTypeUnknown {
431
- val = formula
432
- break
429
+ return formula , nil
433
430
}
434
431
if token .TType == efp .TokenTypeOperand && token .TSubType == efp .TokenSubTypeRange {
435
- if inStrSlice (definedNames , token .TValue , true ) != - 1 {
436
- val += token .TValue
437
- continue
438
- }
439
- if strings .ContainsAny (token .TValue , "[]" ) {
440
- val += token .TValue
432
+ if inStrSlice (definedNames , token .TValue , true ) != - 1 || strings .ContainsAny (token .TValue , "[]" ) {
441
433
continue
442
434
}
443
435
operand , err := f .adjustFormulaOperand (sheet , sheetN , keepRelative , token , dir , num , offset )
444
436
if err != nil {
445
- return val , err
437
+ return ps . Render () , err
446
438
}
447
- val += operand
448
- continue
439
+ tokens [i ].TValue = operand
449
440
}
450
- if paren := transformParenthesesToken (token ); paren != "" {
451
- val += transformParenthesesToken (token )
452
- continue
453
- }
454
- if token .TType == efp .TokenTypeOperand && token .TSubType == efp .TokenSubTypeText {
455
- val += string (efp .QuoteDouble ) + strings .ReplaceAll (token .TValue , "\" " , "\" \" " ) + string (efp .QuoteDouble )
456
- continue
457
- }
458
- val += token .TValue
459
441
}
460
- return val , nil
442
+ return ps . Render () , nil
461
443
}
462
444
463
445
// transformParenthesesToken returns formula part with parentheses by given
0 commit comments