-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxls.go
92 lines (85 loc) · 2.12 KB
/
xls.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"os"
"path/filepath"
"strconv"
"github.com/bon-ami/eztools"
"github.com/unidoc/unioffice/spreadsheet"
)
func wrH(name string) *os.File {
eztools.ShowStrln("Processing sheet " + name)
file := "values-" + name
if err := os.Mkdir(file, os.ModeDir); err != nil {
eztools.LogErrPrint(err)
return nil
}
fp, err := os.Create(filepath.Join(file, "strings.xml"))
if err != nil {
eztools.LogErrPrint(err)
return nil
}
fp.WriteString("<?xml version='1.0' encoding='utf-8'?>\n")
fp.WriteString("<resources xmlns:android=\"http://schemas.android.com/apk/res/android\" xmlns:tools=\"http://schemas.android.com/tools\" xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\">\n")
return fp
}
func wrB(fp *os.File, nm, vl string) {
//eztools.ShowStrln("\t" + nm + "=" + vl)
if fp != nil {
fp.WriteString("<string name=\"" + nm + "\">" + vl + "</string>\n")
}
}
func wrT(fp *os.File) {
if fp != nil {
fp.WriteString("</resources>")
fp.Close()
}
}
func rd(file string) (err error) {
wb, err := spreadsheet.Open(file)
if err != nil {
eztools.LogErrPrint(err)
return
}
defer wb.Close()
for _, sh := range wb.Sheets() {
nm := sh.Name()
fp := wrH(nm)
if fp == nil {
break
}
for i, ro := range sh.Rows() {
if i == 0 {
continue
}
it, err := strconv.Atoi(*(ro.Cell("F").X().V))
if err != nil {
eztools.LogErrPrint(err)
continue
}
if it < 0 || it >= len(wb.SharedStrings.X().Si) {
eztools.LogPrint("invalid index " + *(ro.Cell("F").X().V))
continue
}
for _, vr := range wb.SharedStrings.X().Si[it].R {
if vr != nil {
wrB(fp, ro.Cell("B").GetString(), vr.T)
} else {
eztools.LogPrint("no value for " + nm + "," + ro.Cell("B").GetString())
}
}
/*str, err := wb.SharedStrings.GetString(it)
//str, err := ro.Cell("F").GetRawValue()
if err == nil {
if len(str) > 0 {
fmt.Printf("%s\t%x\n", str, str)
} else {
fmt.Println(*(ro.Cell("F").X().RAttr))
}
} else {
eztools.LogErrPrint(err)
}*/
}
wrT(fp)
}
return
}