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
47ff0a8e
Commit
47ff0a8e
authored
May 22, 2023
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: remove auto merge cells feature
parent
eba1a437
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
38 deletions
+32
-38
export_form.rb
lib/tallty_import_export/export_form.rb
+32
-38
No files found.
lib/tallty_import_export/export_form.rb
View file @
47ff0a8e
...
...
@@ -5,11 +5,11 @@ module TalltyImportExport
end
class
<<
self
def
export_template_xlsx
form
def
export_template_xlsx
(
form
)
export_xlsx
([],
{
headers:
form_transfer_to_headers
(
form
),
header_only:
true
}
)
headers:
form_transfer_to_headers
(
form
),
header_only:
true
,
},
)
end
end
...
...
@@ -18,11 +18,11 @@ module TalltyImportExport
alignment
=
{
vertical: :center
,
horizontal: :center
}
border
=
{
color:
'969696'
,
style: :thin
}
title1
=
workbook
.
styles
.
add_style
(
alignment:
alignment
,
border:
border
,
sz:
12
,
b:
true
)
title2
=
workbook
.
styles
.
add_style
(
alignment:
alignment
,
border:
border
,
bg_color:
"2a5caa"
,
sz:
12
,
fg_color:
"fffffb"
)
title2
=
workbook
.
styles
.
add_style
(
alignment:
alignment
,
border:
border
,
bg_color:
'2a5caa'
,
sz:
12
,
fg_color:
'fffffb'
)
title3
=
workbook
.
styles
.
add_style
(
alignment:
alignment
.
merge
(
wrap_text:
true
),
border:
border
,
sz:
10
)
_sheet_name
=
(
respond_to?
(
:sheet_name
)
?
s
elf
.
s
heet_name
:
nil
)
||
options
[
:sheet_name
]
_sheet_name
=
(
respond_to?
(
:sheet_name
)
?
sheet_name
:
nil
)
||
options
[
:sheet_name
]
header_obj
=
export_headers_result
**
options
header_obj
=
export_headers_result
(
**
options
)
workbook
.
add_worksheet
(
name:
_sheet_name
)
do
|
sheet
|
index
=
0
...
...
@@ -41,13 +41,13 @@ module TalltyImportExport
# 合并相同 header
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
next
unless
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
return
if
options
[
:header_only
]
...
...
@@ -69,7 +69,6 @@ module TalltyImportExport
handle_data
(
payload
,
header
,
index
,
**
opts
)
end
# p '----------------------------------------------------------------'
# payload.lines.each { |x| p x.map { |x| x.try(:value) || '________' } }
...
...
@@ -78,33 +77,30 @@ module TalltyImportExport
line
.
each_with_index
do
|
value
,
col_index
|
value_living_alone_col_index_to_value_count
[
col_index
]
||=
0
if
(
TalltyImportExport
::
ExportPayload
::
Value
===
v
alue
)
if
value
.
is_a?
(
TalltyImportExport
::
ExportPayload
::
V
alue
)
row
<<
value
.
value
value_living_alone_col_index_to_value_count
[
col_index
]
+=
1
unless
value_seq_to_axios
[
value
.
seq
]
value_seq_to_axios
[
value
.
seq
]
=
[]
end
value_seq_to_axios
[
value
.
seq
]
<<
[
col_index
,
row_index
+
index
]
value_seq_to_axios
[
value
.
seq
]
=
[]
unless
value_seq_to_axios
[
value
.
seq
]
value_seq_to_axios
[
value
.
seq
]
<<
[
col_index
,
row_index
+
index
]
else
row
<<
nil
end
formats
.
push
(
header_obj
.
flatten_value
[
col_index
].
format
&
.
to_sym
||
(
row
.
last
.
is_a?
(
String
)
?
:
string
:
nil
)
header_obj
.
flatten_value
[
col_index
].
format
&
.
to_sym
||
(
row
.
last
.
is_a?
(
String
)
?
:
string
:
nil
)
,
)
end
sheet
.
add_row
(
row
,
style:
title3
,
height:
@row_height
,
types:
formats
)
formats
=
[]
end
# 合并仅有一个值的一列中所有格子
value_living_alone_col_index_to_value_count
.
each_pair
do
|
col_index
,
count
|
if
count
==
1
sheet
.
merge_cells
(
Axlsx
::
cell_r
(
col_index
,
index
)
+
':'
+
Axlsx
::
cell_r
(
col_index
,
index
+
payload
.
max_matrix_height
-
1
)
)
end
end
#
value_living_alone_col_index_to_value_count.each_pair do |col_index, count|
#
if count == 1
#
sheet.merge_cells(
#
Axlsx::cell_r(col_index, index) + ':' + Axlsx::cell_r(col_index, index + payload.max_matrix_height - 1)
#
)
#
end
#
end
index
+=
payload
.
max_matrix_height
end
...
...
@@ -112,23 +108,21 @@ module TalltyImportExport
# 合并相同值
value_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
next
unless
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
end
def
export_headers_result
**
options
@headers
=
options
.
symbolize_keys
[
:headers
]
@headers
=
super
(
**
options
)
@headers
=
TalltyImportExport
::
Attr
::
ExportHeader
.
new
({
items:
@headers
})
end
end
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