-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
74 lines (61 loc) · 1.42 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"log"
"strings"
"github.com/miaogaolin/excel-proc/config"
"github.com/miaogaolin/excel-proc/utils"
"github.com/spf13/cobra"
)
const version = "0.1.3"
var (
configFile string
outputFile string
rootCmd = &cobra.Command{
Use: "excel-proc",
Short: "excel-pro is a simple excel data pre-processing tool",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
log.Fatal("No data file path set")
}
err := Run(args[0])
if err != nil {
log.Fatal(err)
}
},
}
)
func init() {
rootCmd.Version = "v" + version
rootCmd.PersistentFlags().StringVar(&configFile, "config", "default.tpl", "Template configuration file")
rootCmd.PersistentFlags().StringVar(&outputFile, "output", "default.bean", "File for saving results")
}
func main() {
err := rootCmd.Execute()
if err != nil {
log.Fatal(err)
}
}
func Run(dataFile string) error {
config, err := config.ReadConfig(configFile)
if err != nil {
return err
}
data, err := GetData(dataFile)
if err != nil {
return err
}
var SourceOrderData [][]interface{}
for _, cols := range data {
var rowData []interface{}
for _, v := range cols {
if num, err := utils.GetMoneyNum(v); err == nil {
rowData = append(rowData, num)
} else {
v = strings.TrimSpace(v)
rowData = append(rowData, v)
}
}
SourceOrderData = append(SourceOrderData, rowData)
}
return Ouput(SourceOrderData, config, outputFile)
}