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
bde58662
Commit
bde58662
authored
May 05, 2022
by
Ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 实现 header 合并
parent
e638cb04
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
20 deletions
+73
-20
export_header.rb
lib/tallty_import_export/attr/export_header.rb
+40
-0
export_form.rb
lib/tallty_import_export/export_form.rb
+15
-2
export_spec.rb
spec/export_spec.rb
+18
-18
No files found.
lib/tallty_import_export/attr/export_header.rb
View file @
bde58662
...
...
@@ -50,11 +50,51 @@ module TalltyImportExport
attr_json
:items
,
ExportHeaderItem
.
to_type
,
array:
true
attr_reader
:header_seq_to_axios
def
flatten_value
items
.
map
do
|
item
|
item
.
calcute_flatten_value
(
0
,
[])
end
.
flatten
end
def
height
flatten_value
.
map
(
&
:depth
).
max
+
1
end
def
header_lines
result
=
[]
height
.
times
.
each
do
|
row_index
|
col_index
=
0
next_line
=
flatten_value
.
map
do
|
header
|
next_header
=
[
*
header
.
try
(
:parent_path
),
header
]
&
.
[
](
row_index
)
@header_seq_to_axios
||=
{}
if
next_header
@header_seq_to_axios
[
next_header
.
seq
]
||=
[]
@header_seq_to_axios
[
next_header
.
seq
].
push
([
col_index
,
row_index
])
end
# 处理最后一列
if
(
row_index
===
height
-
1
)
@header_seq_to_axios
[
header
.
seq
]
||=
[]
@header_seq_to_axios
[
header
.
seq
].
push
([
col_index
,
row_index
])
end
col_index
+=
1
# 下一级继续递归 或 保持自己以合并
next_header
||
header
end
result
.
push
(
next_line
)
end
result
end
end
end
end
lib/tallty_import_export/export_form.rb
View file @
bde58662
...
...
@@ -21,7 +21,6 @@ module TalltyImportExport
header_obj
=
export_headers_result
**
options
workbook
.
add_worksheet
(
name:
_sheet_name
)
do
|
sheet
|
if
respond_to?
(
:first_header
)
row_index
=
Axlsx
.
col_ref
(
header_obj
.
flatten_value
.
size
-
1
)
...
...
@@ -31,8 +30,22 @@ module TalltyImportExport
index
=
0
sheet
.
add_row
header_obj
.
flatten_value
.
map
{
|
header
|
header
.
name
},
style:
title2
,
height:
25
header_obj
.
header_lines
.
each
do
|
header_line
|
sheet
.
add_row
(
header_line
.
map
(
&
:name
),
style:
title2
,
height:
25
)
index
+=
1
end
# 合并相同 header
p
header_obj
.
header_seq_to_axios
.
values
header_obj
.
header_seq_to_axios
.
values
.
each
do
|
axios_ary
|
if
axios_ary
.
count
>
1
top_right
=
[
axios_ary
.
map
(
&
:first
).
min
,
axios_ary
.
map
(
&
:last
).
min
]
bottom_left
=
[
axios_ary
.
map
(
&
:first
).
max
,
axios_ary
.
map
(
&
:last
).
max
]
sheet
.
merge_cells
(
Axlsx
::
cell_r
(
top_right
.
first
,
top_right
.
last
)
+
':'
+
Axlsx
::
cell_r
(
bottom_left
.
first
,
bottom_left
.
last
)
)
end
end
value_seq_to_axios
=
{}
...
...
spec/export_spec.rb
View file @
bde58662
...
...
@@ -54,28 +54,28 @@ RSpec.describe TalltyImportExport::Importable do
}
@header_h
=
{
items:
[
{
key: :a
},
{
key: :b
},
{
key: :c
,
children:
[
{
key: :c1
},
{
key: :c2
},
{
key: :c3
},
{
key: :a
,
name: :a
},
{
key: :b
,
name: :b
},
{
key: :c
,
name: :c
,
children:
[
{
key: :c1
,
name: :c1
},
{
key: :c2
,
name: :c2
},
{
key: :c3
,
name: :c3
},
]
},
{
key: :d
,
children:
[
{
key: :d1
},
{
key: :d2
},
{
key: :d
,
name: :d
,
children:
[
{
key: :d1
,
name: :d1
},
{
key: :d2
,
name: :d2
},
]
},
{
key: :e
,
children:
[
{
key: :e1
},
{
key: :e2
},
{
key: :e3
,
children:
[
{
key: :e31
},
{
key: :e32
},
{
key: :e33
},
{
key: :e
,
name: :e
,
children:
[
{
key: :e1
,
name: :e1
},
{
key: :e2
,
name: :e2
},
{
key: :e3
,
name: :e3
,
children:
[
{
key: :e31
,
name: :e31
},
{
key: :e32
,
name: :e32
},
{
key: :e33
,
name: :e33
},
]},
{
key: :e4
},
{
key: :e4
,
name: :e4
},
]
},
{
key: :f
},
{
key: :f
,
name: :f
},
]
}
end
...
...
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