Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
d1a562ca
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 搜索 >>
提交
d1a562ca
编写于
9月 10, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
combine all excel data to single table
上级
f61ec3e4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
93 addition
and
47 deletion
+93
-47
test/article/common.go
test/article/common.go
+63
-0
test/article/convert_test.go
test/article/convert_test.go
+4
-47
test/article/generate_test.go
test/article/generate_test.go
+26
-0
tmp/cache/.words.db
tmp/cache/.words.db
+0
-0
未找到文件。
test/article/common.go
0 → 100644
浏览文件 @
d1a562ca
package
main
import
(
"github.com/Chain-Zhang/pinyin"
commonUtils
"github.com/easysoft/zendata/src/utils/common"
fileUtils
"github.com/easysoft/zendata/src/utils/file"
_
"github.com/mattn/go-sqlite3"
"io/ioutil"
"path"
"path/filepath"
"strings"
)
func
getFilesInDir
(
folder
,
ext
string
,
files
*
[]
string
)
{
folder
,
_
=
filepath
.
Abs
(
folder
)
if
!
fileUtils
.
IsDir
(
folder
)
{
if
path
.
Ext
(
folder
)
==
ext
{
*
files
=
append
(
*
files
,
folder
)
}
return
}
dir
,
err
:=
ioutil
.
ReadDir
(
folder
)
if
err
!=
nil
{
return
}
for
_
,
fi
:=
range
dir
{
name
:=
fi
.
Name
()
if
commonUtils
.
IngoreFile
(
name
)
{
continue
}
filePath
:=
fileUtils
.
AddSepIfNeeded
(
folder
)
+
name
if
fi
.
IsDir
()
{
getFilesInDir
(
filePath
,
ext
,
files
)
}
else
if
strings
.
Index
(
name
,
"~"
)
!=
0
&&
path
.
Ext
(
filePath
)
==
".xlsx"
{
*
files
=
append
(
*
files
,
filePath
)
}
}
}
func
getFileName
(
filePath
string
)
string
{
fileName
:=
path
.
Base
(
filePath
)
fileName
=
strings
.
TrimSuffix
(
fileName
,
path
.
Ext
(
filePath
))
return
fileName
}
func
changeFileExt
(
filePath
,
ext
string
)
string
{
ret
:=
strings
.
TrimSuffix
(
filePath
,
path
.
Ext
(
filePath
))
ret
+=
ext
return
ret
}
func
getPinyin
(
word
string
)
string
{
p
,
_
:=
pinyin
.
New
(
word
)
.
Split
(
""
)
.
Mode
(
pinyin
.
WithoutTone
)
.
Convert
()
return
p
}
\ No newline at end of file
test/article/convert_test.go
浏览文件 @
d1a562ca
...
...
@@ -4,16 +4,10 @@ import (
"database/sql"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize/v2"
"github.com/Chain-Zhang/pinyin"
commonUtils
"github.com/easysoft/zendata/src/utils/common"
constant
"github.com/easysoft/zendata/src/utils/const"
fileUtils
"github.com/easysoft/zendata/src/utils/file"
i118Utils
"github.com/easysoft/zendata/src/utils/i118"
logUtils
"github.com/easysoft/zendata/src/utils/log"
_
"github.com/mattn/go-sqlite3"
"io/ioutil"
"path"
"path/filepath"
"strconv"
"strings"
"testing"
...
...
@@ -21,7 +15,7 @@ import (
func
TestImportSqlite
(
t
*
testing
.
T
)
{
files
:=
make
([]
string
,
0
)
get
ExcelFilesInDir
(
"xdoc/words-9.3
"
,
&
files
)
get
FilesInDir
(
"xdoc/words-9.3"
,
"xlsx
"
,
&
files
)
tableName
:=
"words"
seq
:=
1
...
...
@@ -69,8 +63,7 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[]
return
}
fileName
:=
path
.
Base
(
filePath
)
fileName
=
strings
.
TrimSuffix
(
fileName
,
path
.
Ext
(
filePath
))
fileName
:=
getFileName
(
filePath
)
fileName
=
strings
.
TrimSuffix
(
fileName
,
"词库"
)
colPrefix
:=
getPinyin
(
fileName
)
...
...
@@ -95,7 +88,8 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[]
colName
:=
getPinyin
(
val
)
if
colIndex
==
0
&&
colName
!=
"ci"
{
colName
=
"ci"
}
else
{
}
if
colName
!=
"ci"
{
colName
=
colPrefix
+
":"
+
colName
}
...
...
@@ -145,41 +139,4 @@ func importExcel(filePath, tableName string, seq *int, ddlFields, insertSqls *[]
)
*
insertSqls
=
append
(
*
insertSqls
,
insertSql
)
}
}
func
getExcelFilesInDir
(
folder
string
,
files
*
[]
string
)
{
folder
,
_
=
filepath
.
Abs
(
folder
)
if
!
fileUtils
.
IsDir
(
folder
)
{
if
path
.
Ext
(
folder
)
==
".xlsx"
{
*
files
=
append
(
*
files
,
folder
)
}
return
}
dir
,
err
:=
ioutil
.
ReadDir
(
folder
)
if
err
!=
nil
{
return
}
for
_
,
fi
:=
range
dir
{
name
:=
fi
.
Name
()
if
commonUtils
.
IngoreFile
(
name
)
{
continue
}
filePath
:=
fileUtils
.
AddSepIfNeeded
(
folder
)
+
name
if
fi
.
IsDir
()
{
getExcelFilesInDir
(
filePath
,
files
)
}
else
if
strings
.
Index
(
name
,
"~"
)
!=
0
&&
path
.
Ext
(
filePath
)
==
".xlsx"
{
*
files
=
append
(
*
files
,
filePath
)
}
}
}
func
getPinyin
(
word
string
)
string
{
p
,
_
:=
pinyin
.
New
(
word
)
.
Split
(
""
)
.
Mode
(
pinyin
.
WithoutTone
)
.
Convert
()
return
p
}
\ No newline at end of file
test/article/generate_test.go
0 → 100644
浏览文件 @
d1a562ca
package
main
import
(
fileUtils
"github.com/easysoft/zendata/src/utils/file"
_
"github.com/mattn/go-sqlite3"
"testing"
)
func
TestGenerate
(
t
*
testing
.
T
)
{
files
:=
make
([]
string
,
0
)
getFilesInDir
(
"xdoc/words-9.3"
,
".txt"
,
&
files
)
for
_
,
filePath
:=
range
files
{
article
:=
fileUtils
.
ReadFile
(
filePath
)
content
:=
convertToYaml
(
article
)
newPath
:=
changeFileExt
(
filePath
,
".yaml"
)
fileUtils
.
WriteFile
(
newPath
,
content
)
}
}
func
convertToYaml
(
article
string
)
(
content
string
)
{
return
}
\ No newline at end of file
tmp/cache/.words.db
浏览文件 @
d1a562ca
无法预览此类型文件
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录