# HG changeset patch # User Sascha L. Teichmann # Date 1622331899 -7200 # Node ID 313bf3f3a8b10f9067ae190d293e180265c42afd # Parent 348d91848278679c84b6d4e6f532220dc06db0a1 XLSX templater: Simplify copy action. If location is a single element array only that cell is copied. If destination is no defined the destination is the same as source. diff -r 348d91848278 -r 313bf3f3a8b1 pkg/xlsx/templater.go --- a/pkg/xlsx/templater.go Sun May 30 01:26:36 2021 +0200 +++ b/pkg/xlsx/templater.go Sun May 30 01:44:59 2021 +0200 @@ -162,9 +162,9 @@ } func (e *executor) copy(action *Action) error { - if len(action.Location) != 2 { - return fmt.Errorf("length location = %d (expect 2)", - len(action.Source)) + if n := len(action.Location); !(n == 1 || n == 2) { + return fmt.Errorf("length location = %d (expect 1 or 2)", + len(action.Location)) } vars := e.vars() @@ -193,10 +193,26 @@ return a, b } + var location []string + + if len(action.Location) == 1 { + location = []string{action.Location[0], action.Location[0]} + } else { + location = action.Location + } + + var destination string + + if action.Destination == "" { + destination = location[0] + } else { + destination = action.Destination + } + var ( - s1 = expand(action.Location[0]) - s2 = expand(action.Location[1]) - d1 = expand(action.Destination) + s1 = expand(location[0]) + s2 = expand(location[1]) + d1 = expand(destination) sx1, sy1 = split(s1) sx2, sy2 = split(s2) dx1, dy1 = split(d1)