Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tallty_import_export
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
tallty_import_export
Commits
7fdf2df7
Commit
7fdf2df7
authored
Nov 21, 2020
by
Ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善备注,修复导入
parent
c9271cea
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
14 deletions
+15
-14
excel.rb
lib/tallty_import_export/excel.rb
+1
-0
import.rb
lib/tallty_import_export/import.rb
+1
-1
importable_spec.rb
spec/importable_spec.rb
+13
-13
No files found.
lib/tallty_import_export/excel.rb
View file @
7fdf2df7
...
@@ -56,6 +56,7 @@ module TalltyImportExport
...
@@ -56,6 +56,7 @@ module TalltyImportExport
mapping
=
excel_hash
.
invert
mapping
=
excel_hash
.
invert
each
do
|
row
|
each
do
|
row
|
line_info
=
row
.
reduce
({})
do
|
out
,
(
k
,
v
)
|
line_info
=
row
.
reduce
({})
do
|
out
,
(
k
,
v
)
|
next
out
unless
mapping
[
k
]
out
[
mapping
[
k
]]
=
v
out
[
mapping
[
k
]]
=
v
out
out
end
end
...
...
lib/tallty_import_export/import.rb
View file @
7fdf2df7
...
@@ -19,7 +19,7 @@ module TalltyImportExport
...
@@ -19,7 +19,7 @@ module TalltyImportExport
def
import_xlsx
xlsx_file
,
associations
,
**
options
def
import_xlsx
xlsx_file
,
associations
,
**
options
# 先处理获取出来Excel每行的数据, line_info
# 先处理获取出来Excel每行的数据, line_info
options
=
options
.
with_indifferent_access
options
=
options
.
with_indifferent_access
self
.
headers
=
options
.
delete
(
:headers
)
||
{}
self
.
headers
=
options
.
delete
(
:headers
)
||
[]
@primary_keys
=
options
.
delete
(
:primary_keys
)
||
headers
.
map
{
|
header
|
header
[
:primary_key
]
?
header
[:
key
].
to_sym
:
nil
}.
compact
@primary_keys
=
options
.
delete
(
:primary_keys
)
||
headers
.
map
{
|
header
|
header
[
:primary_key
]
?
header
[:
key
].
to_sym
:
nil
}.
compact
excel_hash
=
headers
.
reduce
({})
do
|
h
,
header
|
excel_hash
=
headers
.
reduce
({})
do
|
h
,
header
|
...
...
spec/importable_spec.rb
View file @
7fdf2df7
...
@@ -11,7 +11,7 @@ RSpec.describe TalltyImportExport::Importable do
...
@@ -11,7 +11,7 @@ RSpec.describe TalltyImportExport::Importable do
{
key:
'sub_code'
,
name:
'副学号'
,
convert: :skip
},
{
key:
'sub_code'
,
name:
'副学号'
,
convert: :skip
},
{
key:
'meta1'
,
name:
'meta字段1'
,
json: :meta
},
{
key:
'meta1'
,
name:
'meta字段1'
,
json: :meta
},
{
key:
'meta2'
,
name:
'meta字段2'
,
json: :meta
},
{
key:
'meta2'
,
name:
'meta字段2'
,
json: :meta
},
{
key:
'sum'
,
name:
'累计值'
,
convert: :handle_sum
},
{
key:
'sum'
,
name:
'累计值'
,
convert: :handle_sum
},
# 表格里 name 为 累加值
]
]
end
end
end
end
...
@@ -33,12 +33,12 @@ RSpec.describe TalltyImportExport::Importable do
...
@@ -33,12 +33,12 @@ RSpec.describe TalltyImportExport::Importable do
end
end
it
'import file directly'
do
it
'import file directly'
do
# 名称 学号 副学号 meta字段1 meta字段2
# 名称 学号 副学号 meta字段1 meta字段2
累加值
# 1 20070101 1 meta1 metaA
# 1 20070101 1 meta1 metaA
1
# 2 20070102 2 meta2 metaB
# 2 20070102 2 meta2 metaB
2
# 3 20070103 3 meta3 metaC
# 3 20070103 3 meta3 metaC
3
# 4 20070104 4 meta4 metaD
# 4 20070104 4 meta4 metaD
4
# 5 20070105 5 meta5 metaE
# 5 20070105 5 meta5 metaE
5
@result
=
[]
@result
=
[]
Test
.
import_xlsx
(
'./spec/test1.xlsx'
,
@result
,
Test
.
import_xlsx
(
'./spec/test1.xlsx'
,
@result
,
headers:
[
headers:
[
...
@@ -61,12 +61,12 @@ RSpec.describe TalltyImportExport::Importable do
...
@@ -61,12 +61,12 @@ RSpec.describe TalltyImportExport::Importable do
end
end
it
'import excel object'
do
it
'import excel object'
do
# 名称 学号 副学号 meta字段1 meta字段2
# 名称 学号 副学号 meta字段1 meta字段2
累加值
# 1 20070101 1 meta1 metaA
# 1 20070101 1 meta1 metaA
1
# 2 20070102 2 meta2 metaB
# 2 20070102 2 meta2 metaB
2
# 3 20070103 3 meta3 metaC
# 3 20070103 3 meta3 metaC
3
# 4 20070104 4 meta4 metaD
# 4 20070104 4 meta4 metaD
4
# 5 20070105 5 meta5 metaE
# 5 20070105 5 meta5 metaE
5
@result
=
[]
@result
=
[]
@excel
=
TalltyImportExport
::
Excel
.
new
@excel
=
TalltyImportExport
::
Excel
.
new
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment