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
d5d2daaa
Commit
d5d2daaa
authored
Nov 07, 2022
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 增加导出 导入时候 excel的模版
parent
7517e09b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
9 deletions
+71
-9
Gemfile.lock
Gemfile.lock
+13
-9
import.rb
lib/tallty_import_export/import.rb
+58
-0
No files found.
Gemfile.lock
View file @
d5d2daaa
PATH
PATH
remote: .
remote: .
specs:
specs:
tallty_import_export (1.
0.35
)
tallty_import_export (1.
1.1
)
activesupport
activesupport
attr_json
attr_json
caxlsx
caxlsx
...
@@ -27,27 +27,31 @@ GEM
...
@@ -27,27 +27,31 @@ GEM
tzinfo (~> 2.0)
tzinfo (~> 2.0)
attr_json (1.4.0)
attr_json (1.4.0)
activerecord (>= 5.0.0, < 7.1)
activerecord (>= 5.0.0, < 7.1)
caxlsx (3.
2
.0)
caxlsx (3.
3
.0)
htmlentities (~> 4.3, >= 4.3.4)
htmlentities (~> 4.3, >= 4.3.4)
marcel (~> 1.0)
marcel (~> 1.0)
nokogiri (~> 1.10, >= 1.10.4)
nokogiri (~> 1.10, >= 1.10.4)
rubyzip (>= 1.3.0, < 3)
rubyzip (>= 1.3.0, < 3)
concurrent-ruby (1.1.10)
concurrent-ruby (1.1.10)
connection_pool (2.3.0)
diff-lcs (1.4.4)
diff-lcs (1.4.4)
htmlentities (4.3.4)
htmlentities (4.3.4)
i18n (1.1
0
.0)
i18n (1.1
2
.0)
concurrent-ruby (~> 1.0)
concurrent-ruby (~> 1.0)
marcel (1.0.2)
marcel (1.0.2)
mini_portile2 (2.8.0)
mini_portile2 (2.8.0)
minitest (5.1
5.0
)
minitest (5.1
6.3
)
nokogiri (1.13.
4
)
nokogiri (1.13.
9
)
mini_portile2 (~> 2.8.0)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
racc (~> 1.4)
racc (1.6.0)
racc (1.6.0)
rake (12.3.3)
rake (12.3.3)
redis (4.6.0)
redis (5.0.5)
redis-objects (1.5.1)
redis-client (>= 0.9.0)
redis (~> 4.2)
redis-client (0.10.0)
connection_pool
redis-objects (1.7.0)
redis
roo (2.9.0)
roo (2.9.0)
nokogiri (~> 1)
nokogiri (~> 1)
rubyzip (>= 1.3.0, < 3.0.0)
rubyzip (>= 1.3.0, < 3.0.0)
...
@@ -77,7 +81,7 @@ GEM
...
@@ -77,7 +81,7 @@ GEM
activesupport (>= 5.0)
activesupport (>= 5.0)
tallty_form (1.0.0)
tallty_form (1.0.0)
tallty_duck_record
tallty_duck_record
tzinfo (2.0.
4
)
tzinfo (2.0.
5
)
concurrent-ruby (~> 1.0)
concurrent-ruby (~> 1.0)
zip-zip (0.3)
zip-zip (0.3)
rubyzip (>= 1.0.0)
rubyzip (>= 1.0.0)
...
...
lib/tallty_import_export/import.rb
View file @
d5d2daaa
...
@@ -27,6 +27,64 @@ module TalltyImportExport
...
@@ -27,6 +27,64 @@ module TalltyImportExport
end
end
end
end
# 导出excel的空模版
def
export_template_xlsx
(
**
options
)
process_options
(
options
)
Axlsx
::
Package
.
new
do
|
pack
|
pack
.
use_shared_strings
=
true
workbook
=
pack
.
workbook
export_workbook
workbook
,
**
options
file_path
=
File
.
join
(
Rails
.
root
,
'public'
,
'import'
)
FileUtils
.
mkdir_p
(
file_path
)
unless
Dir
.
exist?
(
file_path
)
file_name
=
"
#{
Time
.
now
.
strftime
(
'%Y%m%d%H%M%S'
)
}#{
@filename
}
.xlsx"
file_path_with_name
=
File
.
join
(
file_path
,
file_name
)
pack
.
serialize
(
file_path_with_name
)
return
file_path_with_name
end
end
def
export_workbook
(
workbook
,
**
options
)
# excel导出样式
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'
)
title3
=
workbook
.
styles
.
add_style
(
alignment:
alignment
.
merge
(
wrap_text:
true
),
border:
border
,
sz:
10
)
_sheet_name
=
(
respond_to?
(
:sheet_name
)
?
sheet_name
:
nil
)
||
options
[
:sheet_name
]
header_obj
=
@headers
workbook
.
add_worksheet
(
name:
_sheet_name
)
do
|
sheet
|
index
=
0
if
respond_to?
(
:first_header
)
row_index
=
Axlsx
.
col_ref
(
headers
.
size
-
1
)
sheet
.
merge_cells
(
"A1:
#{
row_index
}
1"
)
sheet
.
add_row
[
first_header
],
style:
title1
,
height:
30
index
+=
1
end
header_obj
.
header_lines
.
each
do
|
header_line
|
sheet
.
add_row
(
header_line
.
map
(
&
:name
),
style:
title2
,
height:
25
)
index
+=
1
end
# 合并相同 header
header_obj
.
header_seq_to_axios
.
values
.
each
do
|
axios_ary
|
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
exchange_to_ids
(
xlsx_file
,
associations
,
**
options
)
def
exchange_to_ids
(
xlsx_file
,
associations
,
**
options
)
errors
=
[]
errors
=
[]
ids
=
[]
ids
=
[]
...
...
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