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
...
@@ -5,11 +5,11 @@ module TalltyImportExport
end
end
class
<<
self
class
<<
self
def
export_template_xlsx
form
def
export_template_xlsx
(
form
)
export_xlsx
([],
{
export_xlsx
([],
{
headers:
form_transfer_to_headers
(
form
),
headers:
form_transfer_to_headers
(
form
),
header_only:
true
header_only:
true
,
}
)
},
)
end
end
end
end
...
@@ -18,11 +18,11 @@ module TalltyImportExport
...
@@ -18,11 +18,11 @@ module TalltyImportExport
alignment
=
{
vertical: :center
,
horizontal: :center
}
alignment
=
{
vertical: :center
,
horizontal: :center
}
border
=
{
color:
'969696'
,
style: :thin
}
border
=
{
color:
'969696'
,
style: :thin
}
title1
=
workbook
.
styles
.
add_style
(
alignment:
alignment
,
border:
border
,
sz:
12
,
b:
true
)
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
)
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
|
workbook
.
add_worksheet
(
name:
_sheet_name
)
do
|
sheet
|
index
=
0
index
=
0
...
@@ -41,13 +41,13 @@ module TalltyImportExport
...
@@ -41,13 +41,13 @@ module TalltyImportExport
# 合并相同 header
# 合并相同 header
header_obj
.
header_seq_to_axios
.
values
.
each
do
|
axios_ary
|
header_obj
.
header_seq_to_axios
.
values
.
each
do
|
axios_ary
|
if
axios_ary
.
count
>
1
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
]
top_right
=
[
axios_ary
.
map
(
&
:first
).
min
,
axios_ary
.
map
(
&
:last
).
min
]
sheet
.
merge_cells
(
bottom_left
=
[
axios_ary
.
map
(
&
:first
).
max
,
axios_ary
.
map
(
&
:last
).
max
]
Axlsx
::
cell_r
(
top_right
.
first
,
top_right
.
last
)
+
':'
+
Axlsx
::
cell_r
(
bottom_left
.
first
,
bottom_left
.
last
)
sheet
.
merge_cells
(
)
Axlsx
.
cell_r
(
top_right
.
first
,
top_right
.
last
)
+
':'
+
Axlsx
.
cell_r
(
bottom_left
.
first
,
bottom_left
.
last
),
end
)
end
end
return
if
options
[
:header_only
]
return
if
options
[
:header_only
]
...
@@ -69,7 +69,6 @@ module TalltyImportExport
...
@@ -69,7 +69,6 @@ module TalltyImportExport
handle_data
(
payload
,
header
,
index
,
**
opts
)
handle_data
(
payload
,
header
,
index
,
**
opts
)
end
end
# p '----------------------------------------------------------------'
# p '----------------------------------------------------------------'
# payload.lines.each { |x| p x.map { |x| x.try(:value) || '________' } }
# payload.lines.each { |x| p x.map { |x| x.try(:value) || '________' } }
...
@@ -78,33 +77,30 @@ module TalltyImportExport
...
@@ -78,33 +77,30 @@ module TalltyImportExport
line
.
each_with_index
do
|
value
,
col_index
|
line
.
each_with_index
do
|
value
,
col_index
|
value_living_alone_col_index_to_value_count
[
col_index
]
||=
0
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
row
<<
value
.
value
value_living_alone_col_index_to_value_count
[
col_index
]
+=
1
value_living_alone_col_index_to_value_count
[
col_index
]
+=
1
unless
value_seq_to_axios
[
value
.
seq
]
value_seq_to_axios
[
value
.
seq
]
=
[]
unless
value_seq_to_axios
[
value
.
seq
]
value_seq_to_axios
[
value
.
seq
]
=
[]
value_seq_to_axios
[
value
.
seq
]
<<
[
col_index
,
row_index
+
index
]
end
value_seq_to_axios
[
value
.
seq
]
<<
[
col_index
,
row_index
+
index
]
else
else
row
<<
nil
row
<<
nil
end
end
formats
.
push
(
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
end
sheet
.
add_row
(
row
,
style:
title3
,
height:
@row_height
,
types:
formats
)
sheet
.
add_row
(
row
,
style:
title3
,
height:
@row_height
,
types:
formats
)
formats
=
[]
formats
=
[]
end
end
# 合并仅有一个值的一列中所有格子
# 合并仅有一个值的一列中所有格子
value_living_alone_col_index_to_value_count
.
each_pair
do
|
col_index
,
count
|
#
value_living_alone_col_index_to_value_count.each_pair do |col_index, count|
if
count
==
1
#
if count == 1
sheet
.
merge_cells
(
#
sheet.merge_cells(
Axlsx
::
cell_r
(
col_index
,
index
)
+
':'
+
Axlsx
::
cell_r
(
col_index
,
index
+
payload
.
max_matrix_height
-
1
)
#
Axlsx::cell_r(col_index, index) + ':' + Axlsx::cell_r(col_index, index + payload.max_matrix_height - 1)
)
#
)
end
#
end
end
#
end
index
+=
payload
.
max_matrix_height
index
+=
payload
.
max_matrix_height
end
end
...
@@ -112,23 +108,21 @@ module TalltyImportExport
...
@@ -112,23 +108,21 @@ module TalltyImportExport
# 合并相同值
# 合并相同值
value_seq_to_axios
.
values
.
each
do
|
axios_ary
|
value_seq_to_axios
.
values
.
each
do
|
axios_ary
|
if
axios_ary
.
count
>
1
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
]
top_right
=
[
axios_ary
.
map
(
&
:first
).
min
,
axios_ary
.
map
(
&
:last
).
min
]
sheet
.
merge_cells
(
bottom_left
=
[
axios_ary
.
map
(
&
:first
).
max
,
axios_ary
.
map
(
&
:last
).
max
]
Axlsx
::
cell_r
(
top_right
.
first
,
top_right
.
last
)
+
':'
+
Axlsx
::
cell_r
(
bottom_left
.
first
,
bottom_left
.
last
)
sheet
.
merge_cells
(
)
Axlsx
.
cell_r
(
top_right
.
first
,
top_right
.
last
)
+
':'
+
Axlsx
.
cell_r
(
bottom_left
.
first
,
bottom_left
.
last
),
end
)
end
end
end
end
end
end
def
export_headers_result
**
options
def
export_headers_result
**
options
@headers
=
options
.
symbolize_keys
[
:headers
]
@headers
=
options
.
symbolize_keys
[
:headers
]
@headers
=
super
(
**
options
)
@headers
=
super
(
**
options
)
@headers
=
TalltyImportExport
::
Attr
::
ExportHeader
.
new
({
items:
@headers
})
@headers
=
TalltyImportExport
::
Attr
::
ExportHeader
.
new
({
items:
@headers
})
end
end
end
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