Mercurial > gemma
annotate pkg/xlsx/templater.go @ 5571:41d7bbc9eac1
Next dev version...
author | Sascha Wilde <wilde@sha-bang.de> |
---|---|
date | Thu, 10 Mar 2022 17:25:44 +0100 |
parents | 5f47eeea988d |
children | 163f38c69a07 |
rev | line source |
---|---|
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2021 by via donau |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package xlsx |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "bufio" |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "context" |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "database/sql" |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "errors" |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "fmt" |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "io" |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "os" |
5349
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
24 "strconv" |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 "strings" |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
5478
699048c86848
Updated 3rd-party libs of the gemma server to the latest bug fix release.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5364
diff
changeset
|
27 "github.com/xuri/excelize/v2" |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 "gopkg.in/yaml.v2" |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 "github.com/PaesslerAG/gval" |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5478
diff
changeset
|
31 |
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5478
diff
changeset
|
32 "gemma.intevation.de/gemma/pkg/log" |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 ) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 type Action struct { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 Type string `yaml:"type"` |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 Actions []*Action `yaml:"actions"` |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 Location []string `yaml:"location"` |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 Source string `yaml:"source"` |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 Destination string `yaml:"destination"` |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 Statement string `yaml:"statement"` |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 Vars []string `yaml:"vars"` |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 Name string `yaml:"name"` |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 Expr string `yaml:"expr"` |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 type frame struct { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 res *sqlResult |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 index int |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
5364
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
52 type sheetAxis struct { |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
53 sheet string |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
54 axis string |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
55 } |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
56 |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
57 type cellValue struct { |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
58 value string |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
59 err error |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
60 } |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
61 |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 type executor struct { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 ctx context.Context |
5333
6c0f40676984
Run xlsx templating in a read-only transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5325
diff
changeset
|
64 tx *sql.Tx |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 template *excelize.File |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 keep map[string]bool |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 expressions map[string]gval.Evaluable |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 sourceSheet string |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 destinationSheet string |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 frames []frame |
5364
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
71 // Fetching formulas out of cells is very expensive so we cache them. |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
72 formulaCache map[sheetAxis]cellValue |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
75 type area struct { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
76 x1 int |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
77 y1 int |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
78 x2 int |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
79 y2 int |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
80 mc excelize.MergeCell |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
81 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
82 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
83 func mergeCellToArea(mc excelize.MergeCell) (area, error) { |
5346
72469b713705
XLSX templater: Cosmetics
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5344
diff
changeset
|
84 x1, y1, err := excelize.CellNameToCoordinates(mc.GetStartAxis()) |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
85 if err != nil { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
86 return area{}, err |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
87 } |
5346
72469b713705
XLSX templater: Cosmetics
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5344
diff
changeset
|
88 x2, y2, err := excelize.CellNameToCoordinates(mc.GetEndAxis()) |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
89 if err != nil { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
90 return area{}, err |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
91 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
92 return area{ |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
93 x1: x1, |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
94 y1: y1, |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
95 x2: x2, |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
96 y2: y2, |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
97 mc: mc, |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
98 }, nil |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
99 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
100 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
101 func (a *area) contains(x, y int) bool { |
5346
72469b713705
XLSX templater: Cosmetics
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5344
diff
changeset
|
102 return a.x1 <= x && x <= a.x2 && a.y1 <= y && y <= a.y2 |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
103 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
104 |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 func ActionFromFile(filename string) (*Action, error) { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 f, err := os.Open(filename) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 return nil, err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 defer f.Close() |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 return ActionFromReader(f) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 func ActionFromReader(r io.Reader) (*Action, error) { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 action := new(Action) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 err := yaml.NewDecoder(bufio.NewReader(r)).Decode(action) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 return action, err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 func (a *Action) Execute( |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 ctx context.Context, |
5333
6c0f40676984
Run xlsx templating in a read-only transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5325
diff
changeset
|
122 tx *sql.Tx, |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 template *excelize.File, |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 ) error { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 |
5364
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
126 //if f, err := os.Create("cpu.prof"); err == nil { |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
127 // pprof.StartCPUProfile(f) |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
128 // defer pprof.StopCPUProfile() |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
129 //} |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
130 |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 e := executor{ |
5364
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
132 ctx: ctx, |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
133 tx: tx, |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
134 template: template, |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
135 keep: map[string]bool{}, |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
136 expressions: map[string]gval.Evaluable{}, |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
137 formulaCache: map[sheetAxis]cellValue{}, |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 oldSheets := template.GetSheetList() |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 if err := e.dispatch(a); err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 for _, sheet := range oldSheets { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 if !e.keep[sheet] { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 template.DeleteSheet(sheet) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 return nil |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 |
5364
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
154 var reused int |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
155 |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
156 func (e *executor) getCellFormula(sheet, axis string) (string, error) { |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
157 var ( |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
158 k = sheetAxis{sheet: sheet, axis: axis} |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
159 v cellValue |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
160 ok bool |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
161 ) |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
162 if v, ok = e.formulaCache[k]; !ok { |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
163 v.value, v.err = e.template.GetCellFormula(sheet, axis) |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
164 e.formulaCache[k] = v |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
165 } |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
166 return v.value, v.err |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
167 } |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
168 |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
169 func (e *executor) setCellFormula(sheet, axis, formula string) { |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
170 e.formulaCache[sheetAxis{sheet: sheet, axis: axis}] = cellValue{value: formula} |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
171 e.template.SetCellFormula(sheet, axis, formula) |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
172 } |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
173 |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 func (e *executor) dispatch(action *Action) error { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 if len(action.Vars) > 0 { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 e.pushVars(action.Vars) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 defer e.popFrame() |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 switch action.Type { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 case "sheet": |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 return e.sheet(action) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 case "copy": |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 return e.copy(action) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 case "select": |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 return e.sel(action) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 case "assign": |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 return e.assign(action) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 case "": |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 return e.actions(action) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 return fmt.Errorf("unknown type '%s'", action.Type) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 func (e *executor) pushVars(vars []string) { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 e.frames = append(e.frames, frame{ |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 res: &sqlResult{ |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 columns: vars, |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 rows: [][]interface{}{make([]interface{}, len(vars))}, |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 }, |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 }) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 func (e *executor) popFrame() { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 n := len(e.frames) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 e.frames[n-1].res = nil |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 e.frames = e.frames[:n-1] |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 func (e *executor) assign(action *Action) error { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 if action.Name == "" { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 return errors.New("missing name in assign") |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 if action.Expr == "" { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 return errors.New("missing expr in assign") |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 for i := len(e.frames) - 1; i >= 0; i-- { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 fr := &e.frames[i] |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 if idx := fr.res.find(action.Name); idx >= 0 { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 f, err := e.expr(action.Expr) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 value, err := f(e.ctx, e.vars()) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 fr.res.rows[fr.index][idx] = value |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 break |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 return e.actions(action) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
235 func order(a, b int) (int, int) { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
236 if a < b { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
237 return a, b |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
238 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
239 return b, a |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
240 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
241 |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 func (e *executor) copy(action *Action) error { |
5325
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
243 if n := len(action.Location); !(n == 1 || n == 2) { |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
244 return fmt.Errorf("length location = %d (expect 1 or 2)", |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
245 len(action.Location)) |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 vars := e.vars() |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 var err error |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 expand := func(s string) string { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 if err == nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 s, err = e.expand(s, vars) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 return s |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
257 split := func(s string) (int, int) { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 var x, y int |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 if err == nil { |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
260 x, y, err = excelize.CellNameToCoordinates(s) |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 return x, y |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
264 |
5325
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
265 var location []string |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
266 if len(action.Location) == 1 { |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
267 location = []string{action.Location[0], action.Location[0]} |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
268 } else { |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
269 location = action.Location |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
270 } |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
271 |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
272 var destination string |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
273 if action.Destination == "" { |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
274 destination = location[0] |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
275 } else { |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
276 destination = action.Destination |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
277 } |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
278 |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 var ( |
5325
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
280 s1 = expand(location[0]) |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
281 s2 = expand(location[1]) |
313bf3f3a8b1
XLSX templater: Simplify copy action.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5321
diff
changeset
|
282 d1 = expand(destination) |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
283 sx1, sy1 = split(s1) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
284 sx2, sy2 = split(s2) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
285 dx1, dy1 = split(d1) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
286 ) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
287 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
288 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
289 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
290 sx1, sx2 = order(sx1, sx2) |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
291 sy1, sy2 = order(sy1, sy2) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
292 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
293 var areas []area |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
294 |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5478
diff
changeset
|
295 //log.Debugln("merged cells") |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
296 if mcs, err := e.template.GetMergeCells(e.sourceSheet); err == nil { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
297 areas = make([]area, 0, len(mcs)) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
298 for _, mc := range mcs { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
299 if a, err := mergeCellToArea(mc); err == nil { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
300 areas = append(areas, a) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
301 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
302 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
303 } |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
304 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
305 for y, i := sy1, 0; y <= sy2; y, i = y+1, i+1 { |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
306 nextX: |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
307 for x, j := sx1, 0; x <= sx2; x, j = x+1, j+1 { |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
308 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
309 // check if cell is part of a merged cell |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
310 for k := range areas { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
311 area := &areas[k] |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
312 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
313 if area.contains(x, y) { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
314 ofsX := x - area.x1 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
315 ofsY := y - area.y1 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
316 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
317 sx := dx1 + j - ofsX |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
318 sy := dy1 + i - ofsY |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
319 ex := sx + (area.x2 - area.x1) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
320 ey := sy + (area.y2 - area.y1) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
321 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
322 // Copy over attributes |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
323 for l := 0; l <= area.x2-area.x1; l++ { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
324 for m := 0; m <= area.y2-area.y1; m++ { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
325 src, err1 := excelize.CoordinatesToCellName(area.x1+l, area.y1+m) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
326 dst, err2 := excelize.CoordinatesToCellName(sx+l, sy+m) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
327 if err1 != nil || err2 != nil { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
328 continue |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
329 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
330 if s, err := e.template.GetCellStyle(e.sourceSheet, src); err == nil { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
331 e.template.SetCellStyle(e.destinationSheet, dst, dst, s) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
332 } |
5364
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
333 if s, err := e.getCellFormula(e.sourceSheet, src); err == nil { |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
334 e.setCellFormula(e.destinationSheet, dst, s) |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
335 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
336 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
337 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
338 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
339 dst, err := excelize.CoordinatesToCellName(sx, sy) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
340 if err != nil { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
341 continue nextX |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
342 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
343 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
344 // Copy over expanded text |
5354
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
345 if v, err := e.typedExpand(area.mc.GetCellValue(), vars); err == nil { |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
346 e.template.SetCellValue(e.destinationSheet, dst, v) |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
347 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
348 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
349 // Finally merge the cells |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
350 if end, err := excelize.CoordinatesToCellName(ex, ey); err == nil { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
351 e.template.MergeCell(e.destinationSheet, dst, end) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
352 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
353 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
354 continue nextX |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
355 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
356 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
357 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
358 // Regular cell |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
359 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
360 src, err := excelize.CoordinatesToCellName(x, y) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
361 if err != nil { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
362 continue |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
363 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
364 dst, err := excelize.CoordinatesToCellName(dx1+j, dy1+i) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
365 if err != nil { |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
366 continue |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
367 } |
5343
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
368 |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
369 cn, err := excelize.ColumnNumberToName(x) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
370 if err != nil { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
371 continue |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
372 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
373 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
374 cw, err := e.template.GetColWidth(e.sourceSheet, cn) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
375 if err != nil { |
5343
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
376 continue |
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
377 } |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
378 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
379 rh, err := e.template.GetRowHeight(e.sourceSheet, y) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
380 if err != nil { |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
381 continue |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
382 } |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
383 |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
384 dc, err := excelize.ColumnNumberToName(dx1 + j) |
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
385 if err != nil { |
5343
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
386 continue |
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
387 } |
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
388 |
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
389 if e.template.SetColWidth(e.destinationSheet, dc, dc, cw) != nil { |
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
390 continue |
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
391 } |
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
392 |
5344
7df6062a1371
XLSX: Implemented correct handling of merged cells.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5343
diff
changeset
|
393 if e.template.SetRowHeight(e.destinationSheet, dy1+i, rh) != nil { |
5343
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
394 continue |
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
395 } |
bb6761abd81d
XLSX template: Copy column and row height explicitly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5333
diff
changeset
|
396 |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
397 if s, err := e.template.GetCellStyle(e.sourceSheet, src); err == nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
398 e.template.SetCellStyle(e.destinationSheet, dst, dst, s) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
399 } |
5364
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
400 if s, err := e.getCellFormula(e.sourceSheet, src); err == nil { |
1adbd6a5f849
XLSX templater: Cache cell formulas for performance.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5363
diff
changeset
|
401 e.setCellFormula(e.destinationSheet, dst, s) |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
402 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
403 if s, err := e.template.GetCellValue(e.sourceSheet, src); err == nil { |
5362
f733bb327b9b
XLSX template: Fixed copy & paste errors from the toy tool.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5361
diff
changeset
|
404 if v, err := e.typedExpand(s, vars); err == nil { |
5354
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
405 e.template.SetCellValue(e.destinationSheet, dst, v) |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
406 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
407 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
408 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
409 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
410 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
411 return nil |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
412 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
413 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
414 func (e *executor) sel(action *Action) error { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
415 vars := e.vars() |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
416 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
417 eval := func(x string) (interface{}, error) { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
418 f, err := e.expr(x) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
419 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
420 return nil, err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
421 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
422 return f(e.ctx, vars) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
423 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
424 |
5333
6c0f40676984
Run xlsx templating in a read-only transaction.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5325
diff
changeset
|
425 res, err := query(e.ctx, e.tx, action.Statement, eval) |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
426 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
427 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
428 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
429 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
430 e.frames = append(e.frames, frame{res: res}) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
431 defer e.popFrame() |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
432 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
433 for i := range res.rows { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
434 e.frames[len(e.frames)-1].index = i |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
435 if err := e.actions(action); err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
436 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
437 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
438 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
439 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
440 return nil |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
441 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
442 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
443 func (e *executor) actions(action *Action) error { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
444 for _, a := range action.Actions { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
445 if err := e.dispatch(a); err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
446 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
447 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
448 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
449 return nil |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
450 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
451 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
452 func (e *executor) sheet(action *Action) error { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
453 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
454 vars := e.vars() |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
455 source, err := e.expand(action.Source, vars) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
456 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
457 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
458 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
459 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
460 srcIdx := e.template.GetSheetIndex(source) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
461 if srcIdx == -1 { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
462 return fmt.Errorf("sheet '%s' not found", source) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
463 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
464 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
465 destination := action.Destination |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
466 if destination == "" { // same as source |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
467 e.keep[source] = true |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
468 destination = source |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
469 } else { // new sheet |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
470 destination, err = e.expand(destination, vars) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
471 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
472 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
473 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
474 dstIdx := e.template.NewSheet(destination) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
475 if len(action.Actions) == 0 { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
476 // Only copy if there are no explicit instructions. |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
477 if err := e.template.CopySheet(srcIdx, dstIdx); err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
478 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
479 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
480 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
481 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
482 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
483 if len(action.Actions) > 0 { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
484 pSrc, pDst := e.sourceSheet, e.destinationSheet |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
485 defer func() { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
486 e.sourceSheet, e.destinationSheet = pSrc, pDst |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
487 }() |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
488 e.sourceSheet, e.destinationSheet = source, destination |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
489 return e.actions(action) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
490 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
491 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
492 // Simple filling |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
493 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
494 // "{{" only as a quick filter |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
495 result, err := e.template.SearchSheet(destination, "{{", true) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
496 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
497 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
498 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
499 for _, axis := range result { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
500 value, err := e.template.GetCellValue(destination, axis) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
501 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
502 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
503 } |
5362
f733bb327b9b
XLSX template: Fixed copy & paste errors from the toy tool.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5361
diff
changeset
|
504 nvalue, err := e.typedExpand(value, vars) |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
505 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
506 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
507 } |
5362
f733bb327b9b
XLSX template: Fixed copy & paste errors from the toy tool.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5361
diff
changeset
|
508 if err := e.template.SetCellValue(destination, axis, nvalue); err != nil { |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
509 return err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
510 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
511 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
512 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
513 return nil |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
514 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
515 |
5349
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
516 func columnToNum(col interface{}) interface{} { |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
517 var name string |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
518 switch v := col.(type) { |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
519 case string: |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
520 name = v |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
521 default: |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
522 name = fmt.Sprintf("%v", col) |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
523 } |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
524 num, err := excelize.ColumnNameToNumber(name) |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
525 if err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5478
diff
changeset
|
526 log.Errorf("invalid column name '%v'\n", col) |
5349
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
527 return 1 |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
528 } |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
529 return num |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
530 } |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
531 |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
532 func asInt(i interface{}) (int, error) { |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
533 switch v := i.(type) { |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
534 case int: |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
535 return v, nil |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
536 case int8: |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
537 return int(v), nil |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
538 case int16: |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
539 return int(v), nil |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
540 case int32: |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
541 return int(v), nil |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
542 case int64: |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
543 return int(v), nil |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
544 case float32: |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
545 return int(v), nil |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
546 case float64: |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
547 return int(v), nil |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
548 case string: |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
549 return strconv.Atoi(v) |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
550 default: |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
551 return 0, fmt.Errorf("invalid int '%v'", i) |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
552 } |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
553 } |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
554 |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
555 func coord2cell(ix, iy interface{}) interface{} { |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
556 x, err := asInt(ix) |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
557 if err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5478
diff
changeset
|
558 log.Errorf("invalid x value: %v\n", err) |
5349
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
559 return "A1" |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
560 } |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
561 y, err := asInt(iy) |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
562 if err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5478
diff
changeset
|
563 log.Errorf("invalid y value: %v\n", err) |
5349
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
564 return "A1" |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
565 } |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
566 |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
567 cell, err := excelize.CoordinatesToCellName(x, y) |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
568 if err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5478
diff
changeset
|
569 log.Errorf("invalid cell coord (%d, %d)\n", x, y) |
5349
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
570 return "A1" |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
571 } |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
572 return cell |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
573 } |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
574 |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
575 var templateLang = gval.Full( |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
576 gval.Function("column2num", columnToNum), |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
577 gval.Function("coord2cell", coord2cell), |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
578 ) |
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
579 |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
580 func (e *executor) expr(x string) (gval.Evaluable, error) { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
581 if f := e.expressions[x]; f != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
582 return f, nil |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
583 } |
5349
a352a695b69c
XLSX templater: Added column to coord conversions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5346
diff
changeset
|
584 f, err := templateLang.NewEvaluable(x) |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
585 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
586 return nil, err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
587 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
588 e.expressions[x] = f |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
589 return f, nil |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
590 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
591 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
592 func (e *executor) vars() map[string]interface{} { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
593 vars := map[string]interface{}{} |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
594 if len(e.frames) > 0 { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
595 vars["row_number"] = e.frames[len(e.frames)-1].index |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
596 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
597 for i := len(e.frames) - 1; i >= 0; i-- { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
598 fr := &e.frames[i] |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
599 for j, n := range fr.res.columns { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
600 if _, found := vars[n]; !found { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
601 vars[n] = fr.res.rows[fr.index][j] |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
602 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
603 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
604 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
605 return vars |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
606 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
607 |
5363
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
608 func (e *executor) expand( |
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
609 str string, |
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
610 vars map[string]interface{}, |
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
611 ) (string, error) { |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
612 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
613 var err error |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
614 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
615 replace := func(s string) string { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
616 if err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
617 return "" |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
618 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
619 var eval gval.Evaluable |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
620 if eval, err = e.expr(strings.TrimSpace(s)); err != nil { |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
621 return "" |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
622 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
623 s, err = eval.EvalString(e.ctx, vars) |
5362
f733bb327b9b
XLSX template: Fixed copy & paste errors from the toy tool.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5361
diff
changeset
|
624 if err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5478
diff
changeset
|
625 log.Errorf("'%s' '%s' %v\n", str, s, err) |
5362
f733bb327b9b
XLSX template: Fixed copy & paste errors from the toy tool.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5361
diff
changeset
|
626 } |
5321
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
627 return s |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
628 } |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
629 |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
630 str = handlebars(str, replace) |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
631 return str, err |
0919946f624b
Added a report controller.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
632 } |
5354
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
633 |
5363
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
634 func (e *executor) typedExpand( |
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
635 str string, |
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
636 vars map[string]interface{}, |
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
637 ) (interface{}, error) { |
5354
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
638 |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
639 var ( |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
640 err error |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
641 repCount int |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
642 last interface{} |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
643 ) |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
644 |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
645 replace := func(s string) string { |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
646 if err != nil { |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
647 return "" |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
648 } |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
649 var eval gval.Evaluable |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
650 if eval, err = e.expr(strings.TrimSpace(s)); err != nil { |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
651 return "" |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
652 } |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
653 repCount++ |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
654 last, err = eval(e.ctx, vars) |
5363
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
655 if err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5478
diff
changeset
|
656 log.Errorf("'%s' '%s' %v\n", str, s, err) |
5363
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
657 } |
5354
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
658 return fmt.Sprintf("%v", last) |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
659 } |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
660 |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
661 nstr := handlebars(str, replace) |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
662 |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
663 if err != nil { |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
664 return nil, err |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
665 } |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
666 |
5363
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
667 if repCount == 1 && |
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
668 strings.HasPrefix(str, "{{") && |
04b3fb35910c
XLSX templater: More logging in case of expression eval errors.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5362
diff
changeset
|
669 strings.HasSuffix(str, "}}") { |
5354
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
670 return last, nil |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
671 } |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
672 return nstr, nil |
6a94ab82eaaa
XLSX templater: Added type support for cell expansion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5349
diff
changeset
|
673 } |