forked from davyxu/tabtoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportor.go
122 lines (82 loc) · 2.22 KB
/
exportor.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package v2
import (
"path/filepath"
"strings"
"github.com/davyxu/tabtoy/v2/i18n"
"github.com/davyxu/tabtoy/v2/model"
"github.com/davyxu/tabtoy/v2/printer"
)
func Run(g *printer.Globals) bool {
if !g.PreExport() {
return false
}
cachedFile := cacheFile(g)
fileObjList := make([]*File, 0)
log.Infof("==========%s==========", i18n.String(i18n.Run_CollectTypeInfo))
// 合并类型
for _, in := range g.InputFileList {
inputFile := in.(string)
var mainMergeFile *File
mergeFileList := strings.Split(inputFile, "+")
for index, fileName := range mergeFileList {
file, _ := cachedFile[fileName]
if file == nil {
return false
}
var mergeTarget string
if len(mergeFileList) > 1 {
mergeTarget = "--> " + filepath.Base(mergeFileList[0])
}
log.Infoln(filepath.Base(fileName), mergeTarget)
file.GlobalFD = g.FileDescriptor
// 电子表格数据导出到Table对象
if !file.ExportLocalType(mainMergeFile) {
return false
}
// 主文件才写入全局信息
if index == 0 {
// 整合类型信息和数据
if !g.AddTypes(file.LocalFD) {
return false
}
// 只写入主文件的文件列表
if file.Header != nil {
fileObjList = append(fileObjList, file)
}
mainMergeFile = file
} else {
// 添加自文件
mainMergeFile.mergeList = append(mainMergeFile.mergeList, file)
}
}
}
log.Infof("==========%s==========", i18n.String(i18n.Run_ExportSheetData))
for _, file := range fileObjList {
log.Infoln(filepath.Base(file.FileName))
dataModel := model.NewDataModel()
tab := model.NewTable()
tab.LocalFD = file.LocalFD
// 主表
if !file.ExportData(dataModel, nil) {
return false
}
// 子表提供数据
for _, mergeFile := range file.mergeList {
log.Infoln(filepath.Base(mergeFile.FileName), "--->", filepath.Base(file.FileName))
// 电子表格数据导出到Table对象
if !mergeFile.ExportData(dataModel, file.Header) {
return false
}
}
// 合并所有值到node节点
if !mergeValues(dataModel, tab, file) {
return false
}
// 整合类型信息和数据
if !g.AddContent(tab) {
return false
}
}
// 根据各种导出类型, 调用各导出器导出
return g.Print()
}