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
b3803f03
Commit
b3803f03
authored
Dec 26, 2021
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 判断数据格式,自动转换excel格式
parent
840c8fbb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
2 deletions
+15
-2
export.rb
lib/tallty_import_export/export.rb
+15
-2
No files found.
lib/tallty_import_export/export.rb
View file @
b3803f03
...
@@ -94,12 +94,13 @@ module TalltyImportExport
...
@@ -94,12 +94,13 @@ module TalltyImportExport
index
=
0
index
=
0
association_records
.
each
do
|
association_record
|
association_records
.
each
do
|
association_record
|
row
=
[]
records
=
@each_method
.
present?
?
records
=
@each_method
.
present?
?
(
try_method
(
association_record
,
@each_method
)
||
[
nil
])
:
(
try_method
(
association_record
,
@each_method
)
||
[
nil
])
:
[
association_record
]
[
association_record
]
records
.
each
do
|
record
|
records
.
each
do
|
record
|
row
=
[]
formats
=
[]
index
+=
1
index
+=
1
headers
.
each_with_index
do
|
header
,
col_index
|
headers
.
each_with_index
do
|
header
,
col_index
|
_data
=
header
[
:source
]
?
_data
=
header
[
:source
]
?
...
@@ -117,8 +118,9 @@ module TalltyImportExport
...
@@ -117,8 +118,9 @@ module TalltyImportExport
end
end
end
end
row
.
push
(
_data
)
row
.
push
(
_data
)
formats
.
push
(
header
[
:format
]
&
.
to_sym
||
(
_data
.
is_a?
(
String
)
?
:
string
:
nil
))
end
end
sheet
.
add_row
row
,
style:
title3
,
height:
@row_height
,
types:
headers
.
map
{
|
header
|
header
[
:format
]
&
.
to_sym
}
sheet
.
add_row
row
,
style:
title3
,
height:
@row_height
,
types:
formats
}
last_row
=
row
last_row
=
row
end
end
end
end
...
@@ -194,6 +196,7 @@ module TalltyImportExport
...
@@ -194,6 +196,7 @@ module TalltyImportExport
try_method
(
record
,
header
[
:key
])
try_method
(
record
,
header
[
:key
])
end
end
data
=
handle_format
(
data
,
header
)
data
=
handle_format
(
data
,
header
)
data
=
handle_data_type
(
data
)
data
=
handle_select
(
data
,
header
)
data
=
handle_select
(
data
,
header
)
rescue
rescue
''
''
...
@@ -222,6 +225,16 @@ module TalltyImportExport
...
@@ -222,6 +225,16 @@ module TalltyImportExport
end
end
end
end
def
handle_data_type
data
if
data
.
is_a?
(
Time
)
data
.
in_time_zone
.
strftime
(
'%F %H:%M'
)
elsif
data
.
is_a?
(
Date
)
data
.
in_time_zone
.
strftime
(
'%F'
)
else
data
end
end
def
handle_select
data
,
header
def
handle_select
data
,
header
if
header
[
:select
].
present?
if
header
[
:select
].
present?
select_option
=
header
[
:select
].
find
{
|
option
|
option
[
:value
].
to_s
==
data
.
to_s
}
select_option
=
header
[
:select
].
find
{
|
option
|
option
[
:value
].
to_s
==
data
.
to_s
}
...
...
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