Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
8652aa9a
Z
zendata
项目概览
易企天创
/
zendata
9 个月 前同步成功
通知
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 搜索 >>
提交
8652aa9a
编写于
6月 23, 2022
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix prefix range issue
上级
55272195
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
119 addition
and
24 deletion
+119
-24
cmd/test/export/export-company.go
cmd/test/export/export-company.go
+54
-14
demo/data.yaml
demo/data.yaml
+11
-10
yaml/city/v2.yaml
yaml/city/v2.yaml
+42
-0
yaml/company/v2.yaml
yaml/company/v2.yaml
+12
-0
未找到文件。
cmd/test/export/export-company.go
浏览文件 @
8652aa9a
...
...
@@ -12,7 +12,7 @@ import (
func
main
()
{
filePath
:=
"data/company/v2.xlsx"
sheetName
:=
"company"
sheetName
1
:=
"company"
fileUtils
.
MkDirIfNeeded
(
filepath
.
Dir
(
filePath
))
...
...
@@ -21,33 +21,72 @@ func main() {
&
model
.
DataCompany
{},
)
pos
:=
make
([]
model
.
DataCompany
,
0
)
db
.
Order
(
"id ASC"
)
.
Find
(
&
pos
)
pos
1
:=
make
([]
model
.
DataCompany
,
0
)
db
.
Order
(
"id ASC"
)
.
Find
(
&
pos
1
)
f
:=
excelize
.
NewFile
()
index
:=
f
.
NewSheet
(
sheetName
)
f
.
SetActiveSheet
(
index
)
index
1
:=
f
.
NewSheet
(
sheetName1
)
f
.
SetActiveSheet
(
index
1
)
sheet1
:=
f
.
GetSheetName
(
0
)
f
.
DeleteSheet
(
sheet1
)
var
infos1
[]
model
.
TableInfo
db
.
Raw
(
"desc "
+
model
.
DataCompany
{}
.
TableName
())
.
Scan
(
&
infos1
)
excelColNameArr1
,
excelColNameHeader1
:=
comm
.
GetExcelColsByTableDef
(
infos1
)
fieldNames1
:=
comm
.
GetStructFields
(
model
.
DataCompany
{})
// gen headers
for
index
,
name
:=
range
excelColNameHeader1
{
excelColName
:=
excelColNameArr1
[
index
]
excelColId
:=
fmt
.
Sprintf
(
"%s%d"
,
excelColName
,
1
)
f
.
SetCellValue
(
sheetName1
,
excelColId
,
name
)
}
// gen rows
for
rowIndex
,
po
:=
range
pos1
{
for
fieldIndex
,
fieldName
:=
range
fieldNames1
{
val
:=
""
if
fieldName
==
"Id"
{
val
=
fmt
.
Sprintf
(
"%d"
,
reflect
.
ValueOf
(
po
)
.
FieldByName
(
fieldName
)
.
Uint
())
}
else
{
val
=
reflect
.
ValueOf
(
po
)
.
FieldByName
(
fieldName
)
.
String
()
}
excelColName
:=
excelColNameArr1
[
fieldIndex
]
excelColId
:=
fmt
.
Sprintf
(
"%s%d"
,
excelColName
,
rowIndex
+
2
)
f
.
SetCellValue
(
sheetName1
,
excelColId
,
val
)
}
}
sheetName2
:=
"company_abbreviation"
pos
:=
make
([]
model
.
DataCompanyAbbreviation
,
0
)
db
.
Order
(
"id ASC"
)
.
Find
(
&
pos
)
index2
:=
f
.
NewSheet
(
sheetName2
)
f
.
SetActiveSheet
(
index2
)
var
infos
[]
model
.
TableInfo
db
.
Raw
(
"desc "
+
model
.
DataCompany
{}
.
TableName
())
.
Scan
(
&
infos
)
db
.
Raw
(
"desc "
+
model
.
DataCompany
Abbreviation
{}
.
TableName
())
.
Scan
(
&
infos
)
excelColNameArr
,
excelColNameHeader
:=
comm
.
GetExcelColsByTableDef
(
infos
)
fieldNames
:=
comm
.
GetStructFields
(
model
.
DataCompany
{})
excelColNameArr
2
,
excelColNameHeader2
:=
comm
.
GetExcelColsByTableDef
(
infos
)
fieldNames
2
:=
comm
.
GetStructFields
(
model
.
DataCompanyAbbreviation
{})
// gen headers
for
index
,
name
:=
range
excelColNameHeader
{
excelColName
:=
excelColNameArr
[
index
]
for
index
,
name
:=
range
excelColNameHeader
2
{
excelColName
:=
excelColNameArr
2
[
index
]
excelColId
:=
fmt
.
Sprintf
(
"%s%d"
,
excelColName
,
1
)
f
.
SetCellValue
(
sheetName
,
excelColId
,
name
)
f
.
SetCellValue
(
sheetName
2
,
excelColId
,
name
)
}
// gen rows
for
rowIndex
,
po
:=
range
pos
{
for
fieldIndex
,
fieldName
:=
range
fieldNames
{
for
fieldIndex
,
fieldName
:=
range
fieldNames
2
{
val
:=
""
if
fieldName
==
"Id"
{
...
...
@@ -56,12 +95,13 @@ func main() {
val
=
reflect
.
ValueOf
(
po
)
.
FieldByName
(
fieldName
)
.
String
()
}
excelColName
:=
excelColNameArr
[
fieldIndex
]
excelColName
:=
excelColNameArr
2
[
fieldIndex
]
excelColId
:=
fmt
.
Sprintf
(
"%s%d"
,
excelColName
,
rowIndex
+
2
)
f
.
SetCellValue
(
sheetName
,
excelColId
,
val
)
f
.
SetCellValue
(
sheetName
2
,
excelColId
,
val
)
}
}
f
.
SetActiveSheet
(
index1
)
f
.
SaveAs
(
filePath
)
}
demo/data.yaml
浏览文件 @
8652aa9a
...
...
@@ -5,21 +5,22 @@ author: zentao
version
:
1.0
fields
:
# - field: f11
# range: a-z
# prefix: "1-9"
# postfix: "\t"
#
# - field: f22
# range: a-z
# postfix: ", "
-
field
:
f1
from
:
chronology.v2.yaml
use
:
chronology
postfix
:
"
,
"
-
field
:
f2
from
:
city.v2.yaml
use
:
name
postfix
:
"
\t
"
-
field
:
f3
from
:
color.v1.yaml
use
:
chinese
postfix
:
"
\t
"
\ No newline at end of file
postfix
:
"
\t
"
-
field
:
f4
from
:
company.v2.yaml
use
:
name
postfix
:
"
\t
"
yaml/city/v2.yaml
0 → 100644
浏览文件 @
8652aa9a
title
:
城市
desc
:
author
:
wwccss
version
:
1.0
field
:
city
instances
:
-
instance
:
name
fields
:
-
field
:
part1
from
:
city.v2.city
select
:
name
-
instance
:
code
fields
:
-
field
:
part1
from
:
city.v2.city
select
:
code
-
instance
:
zip_code
fields
:
-
field
:
part1
from
:
city.v2.city
select
:
name
-
instance
:
state
fields
:
-
field
:
part1
from
:
city.v2.city
select
:
zip_code
-
instance
:
state_short
fields
:
-
field
:
part1
from
:
city.v2.city
select
:
state_short
-
instance
:
state_short2
fields
:
-
field
:
part1
from
:
city.v2.city
select
:
state_short2
yaml/company/v2.yaml
0 → 100644
浏览文件 @
8652aa9a
title
:
公司
desc
:
author
:
wwccss
version
:
1.0
field
:
company
instances
:
-
instance
:
name
fields
:
-
field
:
part1
from
:
company.v2.company
select
:
content
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录