@@ -237,38 +237,43 @@ func (f *File) adjustSingleRowFormulas(sheet, sheetN string, r *xlsxRow, num, of
237
237
}
238
238
239
239
// adjustCellRef provides a function to adjust cell reference.
240
- func (f * File ) adjustCellRef (ref string , dir adjustDirection , num , offset int ) (string , bool , error ) {
241
- if ! strings .Contains (ref , ":" ) {
242
- ref += ":" + ref
243
- }
244
- var delete bool
245
- coordinates , err := rangeRefToCoordinates (ref )
246
- if err != nil {
247
- return ref , delete , err
248
- }
249
- if dir == columns {
250
- if offset < 0 && coordinates [0 ] == coordinates [2 ] {
251
- delete = true
252
- }
253
- if coordinates [0 ] >= num {
254
- coordinates [0 ] += offset
255
- }
256
- if coordinates [2 ] >= num {
257
- coordinates [2 ] += offset
240
+ func (f * File ) adjustCellRef (cellRef string , dir adjustDirection , num , offset int ) (string , error ) {
241
+ var SQRef []string
242
+ for _ , ref := range strings .Split (cellRef , " " ) {
243
+ if ! strings .Contains (ref , ":" ) {
244
+ ref += ":" + ref
258
245
}
259
- } else {
260
- if offset < 0 && coordinates [ 1 ] == coordinates [ 3 ] {
261
- delete = true
246
+ coordinates , err := rangeRefToCoordinates ( ref )
247
+ if err != nil {
248
+ return "" , err
262
249
}
263
- if coordinates [1 ] >= num {
264
- coordinates [1 ] += offset
250
+ if dir == columns {
251
+ if offset < 0 && coordinates [0 ] == coordinates [2 ] {
252
+ continue
253
+ }
254
+ if coordinates [0 ] >= num {
255
+ coordinates [0 ] += offset
256
+ }
257
+ if coordinates [2 ] >= num {
258
+ coordinates [2 ] += offset
259
+ }
260
+ } else {
261
+ if offset < 0 && coordinates [1 ] == coordinates [3 ] {
262
+ continue
263
+ }
264
+ if coordinates [1 ] >= num {
265
+ coordinates [1 ] += offset
266
+ }
267
+ if coordinates [3 ] >= num {
268
+ coordinates [3 ] += offset
269
+ }
265
270
}
266
- if coordinates [ 3 ] >= num {
267
- coordinates [ 3 ] += offset
271
+ if ref , err = coordinatesToRangeRef ( coordinates ); err != nil {
272
+ return "" , err
268
273
}
274
+ SQRef = append (SQRef , ref )
269
275
}
270
- ref , err = coordinatesToRangeRef (coordinates )
271
- return ref , delete , err
276
+ return strings .Join (SQRef , " " ), nil
272
277
}
273
278
274
279
// adjustFormula provides a function to adjust formula reference and shared
@@ -284,7 +289,7 @@ func (f *File) adjustFormula(sheet, sheetN string, cell *xlsxC, dir adjustDirect
284
289
return nil
285
290
}
286
291
if cell .F .Ref != "" && sheet == sheetN {
287
- if cell .F .Ref , _ , err = f .adjustCellRef (cell .F .Ref , dir , num , offset ); err != nil {
292
+ if cell .F .Ref , err = f .adjustCellRef (cell .F .Ref , dir , num , offset ); err != nil {
288
293
return err
289
294
}
290
295
if si && cell .F .Si != nil {
@@ -932,11 +937,11 @@ func (f *File) adjustConditionalFormats(ws *xlsxWorksheet, sheet string, dir adj
932
937
if cf == nil {
933
938
continue
934
939
}
935
- ref , del , err := f .adjustCellRef (cf .SQRef , dir , num , offset )
940
+ ref , err := f .adjustCellRef (cf .SQRef , dir , num , offset )
936
941
if err != nil {
937
942
return err
938
943
}
939
- if del {
944
+ if ref == "" {
940
945
ws .ConditionalFormatting = append (ws .ConditionalFormatting [:i ],
941
946
ws .ConditionalFormatting [i + 1 :]... )
942
947
i --
@@ -967,11 +972,11 @@ func (f *File) adjustDataValidations(ws *xlsxWorksheet, sheet string, dir adjust
967
972
continue
968
973
}
969
974
if sheet == sheetN {
970
- ref , del , err := f .adjustCellRef (dv .Sqref , dir , num , offset )
975
+ ref , err := f .adjustCellRef (dv .Sqref , dir , num , offset )
971
976
if err != nil {
972
977
return err
973
978
}
974
- if del {
979
+ if ref == "" {
975
980
worksheet .DataValidations .DataValidation = append (worksheet .DataValidations .DataValidation [:i ],
976
981
worksheet .DataValidations .DataValidation [i + 1 :]... )
977
982
i --
0 commit comments