-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
58 lines (52 loc) · 1.17 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
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/gnucoop/formconv/formats"
)
func main() {
if len(os.Args) <= 1 {
fmt.Fprintln(os.Stderr, `No input files provided.
formconv converts xlsform files to ajf. Usage:
formconv form1.xlsx form2.xls`)
return
}
for _, fileName := range os.Args[1:] {
err := decXlsEncAjf(fileName)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
}
func decXlsEncAjf(xlsName string) error {
f, err := os.Open(xlsName)
if err != nil {
return err
}
defer f.Close()
stat, err := f.Stat()
if err != nil {
return err
}
wb, err := formats.NewWorkBook(f, filepath.Ext(xlsName), stat.Size())
if err != nil {
return fmt.Errorf("Error opening workbook: %s", err)
}
xls, err := formats.DecXlsform(wb)
if err != nil {
return fmt.Errorf("Error decoding file %s: %s", xlsName, err)
}
ajf, err := formats.Convert(xls)
if err != nil {
return fmt.Errorf("%s, %s", xlsName, err)
}
ext := filepath.Ext(xlsName)
name := xlsName[0 : len(xlsName)-len(ext)]
ajfName := name + ".json"
err = formats.EncJsonToFile(ajfName, ajf)
if err != nil {
return fmt.Errorf("Error encoding file %s: %s", ajfName, err)
}
return nil
}