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
178a7866
Commit
178a7866
authored
3 years ago
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
import do not assign headers in initialize
parent
db15a199
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6 additions
and
5 deletions
+6
-5
common.rb
lib/tallty_import_export/common.rb
+1
-1
export.rb
lib/tallty_import_export/export.rb
+1
-0
import.rb
lib/tallty_import_export/import.rb
+3
-3
version.rb
lib/tallty_import_export/version.rb
+1
-1
No files found.
lib/tallty_import_export/common.rb
View file @
178a7866
...
...
@@ -6,7 +6,7 @@ module TalltyImportExport
end
module
ClassMethods
def
model_headers
def
model_headers
**
args
columns
.
map
do
|
column
|
{
key:
column
.
name
,
...
...
This diff is collapsed.
Click to expand it.
lib/tallty_import_export/export.rb
View file @
178a7866
...
...
@@ -26,6 +26,7 @@ module TalltyImportExport
# chain: 导出时对象属性通过链式调用
# index: 数组方式,需要嵌套拿到里面的
# merge: true/false,默认false,某一列,如果上下行的内容相同,则直接合并单元格
# json: model_payload,代表存储在某一个列中
def
export_xlsx
records
,
**
options
records
=
with_scope
records
...
...
This diff is collapsed.
Click to expand it.
lib/tallty_import_export/import.rb
View file @
178a7866
module
TalltyImportExport
class
Import
require
'roo'
attr_reader
:klass
,
:context
,
:
headers
,
:
primary_keys
,
:associations
attr_reader
:klass
,
:context
,
:primary_keys
,
:associations
def
initialize
klass
@klass
=
klass
@headers
=
import_headers_result
.
map
{
|
header
|
header
.
with_indifferent_access
}
@context
=
Context
.
new
({})
end
...
...
@@ -15,6 +14,7 @@ module TalltyImportExport
# format: excel是否需要特定的格式,目前主要是类似于身份证号,可以用string
# convert: 导入时候,把excel的内容转换成导入时候代码逻辑需要的内容
# primary_key: 是否是主键
# json: model_payload,代表存储在某一个列中
# xlsx_file 为 file path or file object or TalltyImportExport::Excel.new
def
import_xlsx
xlsx_file
,
associations
,
**
options
...
...
@@ -101,7 +101,7 @@ module TalltyImportExport
end
def
import_headers
**
args
@headers
||
klass
.
try
(
:
import_
headers
)
||
klass
.
try
(
:model_headers
)
||
(
raise
ArgumentError
.
new
(
'missing import_headers'
))
@headers
||
klass
.
try
(
:headers
)
||
klass
.
try
(
:model_headers
)
||
(
raise
ArgumentError
.
new
(
'missing import_headers'
))
end
# 只保留 key, name, json, 合并到 import_header
...
...
This diff is collapsed.
Click to expand it.
lib/tallty_import_export/version.rb
View file @
178a7866
module
TalltyImportExport
VERSION
=
"1.0.
4
"
VERSION
=
"1.0.
5
"
end
This diff is collapsed.
Click to expand it.
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