changeset 5325:313bf3f3a8b1 extented-report

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.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 30 May 2021 01:44:59 +0200
parents 348d91848278
children c008e13fa1d1
files pkg/xlsx/templater.go
diffstat 1 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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)