Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
7f0f4d89
Z
zendata
项目概览
易企天创
/
zendata
11 个月 前同步成功
通知
17
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zendata
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7f0f4d89
编写于
11月 02, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
close task#8188
上级
12318e4f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
38 addition
and
13 deletion
+38
-13
demo/advanced.yaml
demo/advanced.yaml
+7
-4
src/action/generator.go
src/action/generator.go
+1
-1
src/gen/printer.go
src/gen/printer.go
+1
-1
src/gen/writer.go
src/gen/writer.go
+28
-7
src/model/definition.go
src/model/definition.go
+1
-0
未找到文件。
demo/advanced.yaml
浏览文件 @
7f0f4d89
...
...
@@ -6,10 +6,8 @@ version: 1.0
fields
:
-
field
:
field_step_negative
# 区间指定步长。
range
:
z-a:-2
# 9,7,5,4...
loop
:
1-3
loopfix
:
"
|"
-
field
:
field_step_negative
# 区间指定负数步长。
range
:
9-1:-2
# 9,7,5,4...
prefix
:
"
["
postfix
:
"
]
\t
"
...
...
@@ -25,6 +23,11 @@ fields:
prefix
:
"
["
postfix
:
"
]
\t
"
-
field
:
field_value
# 引用同文件其他字段进行数学运算。
value
:
"
$field_step_negative
*
2
-
1"
prefix
:
"
["
postfix
:
"
]
\t
"
-
field
:
field_nested_range
from
:
zentao.number.v1.yaml
# 引用用户自定义ranges,存于users目录下。
use
:
medium
...
...
src/action/generator.go
浏览文件 @
7f0f4d89
...
...
@@ -28,7 +28,7 @@ func Generate(defaultFile string, configFile string, fieldsToExportStr, format,
return
}
if
format
==
constant
.
FormatExcel
{
if
format
==
constant
.
FormatExcel
||
format
==
constant
.
FormatCsv
{
gen
.
Write
(
rows
,
format
,
table
,
colIsNumArr
,
fieldsToExport
)
}
else
{
gen
.
Print
(
rows
,
format
,
table
,
colIsNumArr
,
fieldsToExport
)
...
...
src/gen/
output
.go
→
src/gen/
printer
.go
浏览文件 @
7f0f4d89
...
...
@@ -37,7 +37,7 @@ func Print(rows [][]string, format string, table string, colIsNumArr []bool,
col
=
stringUtils
.
AddPad
(
col
,
field
)
}
if
j
>
0
&&
vari
.
Human
{
if
j
>
0
&&
vari
.
Human
{
// use a tab
lineForText
=
strings
.
TrimRight
(
lineForText
,
"
\t
"
)
col
=
strings
.
TrimLeft
(
col
,
"
\t
"
)
...
...
src/gen/write.go
→
src/gen/write
r
.go
浏览文件 @
7f0f4d89
package
gen
import
(
"
fmt
"
"
encoding/csv
"
"github.com/360EntSecGroup-Skylar/excelize/v2"
constant
"github.com/easysoft/zendata/src/utils/const"
logUtils
"github.com/easysoft/zendata/src/utils/log"
...
...
@@ -13,6 +13,9 @@ import (
const
(
sheetName
=
"Sheet1"
)
var
(
csvWriter
*
csv
.
Writer
)
func
Write
(
rows
[][]
string
,
format
string
,
table
string
,
colIsNumArr
[]
bool
,
fields
[]
string
)
(
lines
[]
interface
{})
{
...
...
@@ -23,23 +26,41 @@ func Write(rows [][]string, format string, table string, colIsNumArr []bool,
if
format
==
constant
.
FormatExcel
{
printExcelHeader
(
fields
,
f
)
}
else
if
format
==
constant
.
FormatCsv
{
csvWriter
=
csv
.
NewWriter
(
logUtils
.
FileWriter
)
}
for
i
,
row
:=
range
rows
{
for
j
,
col
:=
range
row
{
csvData
:=
make
([][]
string
,
0
)
for
i
,
cols
:=
range
rows
{
csvRow
:=
make
([]
string
,
0
)
for
j
,
col
:=
range
cols
{
col
=
replacePlaceholder
(
col
)
field
:=
vari
.
TopFieldMap
[
fields
[
j
]]
if
field
.
Length
>
runewidth
.
StringWidth
(
col
)
{
col
=
stringUtils
.
AddPad
(
col
,
field
)
}
colName
,
_
:=
excelize
.
CoordinatesToCellName
(
j
+
1
,
i
+
2
)
f
.
SetCellValue
(
sheetName
,
colName
,
col
)
if
format
==
constant
.
FormatExcel
{
colName
,
_
:=
excelize
.
CoordinatesToCellName
(
j
+
1
,
i
+
2
)
f
.
SetCellValue
(
sheetName
,
colName
,
col
)
}
else
if
format
==
constant
.
FormatCsv
{
csvRow
=
append
(
csvRow
,
col
)
}
}
csvData
=
append
(
csvData
,
csvRow
)
}
if
err
:=
f
.
SaveAs
(
logUtils
.
FilePath
);
err
!=
nil
{
fmt
.
Println
(
err
)
var
err
error
if
format
==
constant
.
FormatExcel
{
err
=
f
.
SaveAs
(
logUtils
.
FilePath
)
}
else
if
format
==
constant
.
FormatCsv
{
err
=
csvWriter
.
WriteAll
(
csvData
)
csvWriter
.
Flush
()
}
if
err
!=
nil
{
logUtils
.
PrintErrMsg
(
err
.
Error
())
}
return
...
...
src/model/definition.go
浏览文件 @
7f0f4d89
...
...
@@ -72,6 +72,7 @@ type FieldSimple struct {
Field
string
`yaml:"field"`
Note
string
`yaml:"note"`
Range
string
`yaml:"range"`
Value
string
`yaml:"value"`
Prefix
string
`yaml:"prefix"`
Postfix
string
`yaml:"postfix"`
Loop
string
`yaml:"loop"`
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录