tallty_import_export 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 284928193ebed0e079f44ba98ee7a2f0d51c05f0c1ea5100dd68973940f56369
|
4
|
+
data.tar.gz: 75dbf1351c7a08ce445b508ea60aba31da811fcfc87e9355c5f8c710f66be47a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d335d50b6059608dcdb41cc3f44e16f75746d900d698ff1ea3960de8d2541b0fdfadf9b7fceeadef33f70906a3c4673f8247c6aa9406195826f0b45a9977d5e
|
7
|
+
data.tar.gz: e72f4ddf2a9bb43f00d031aa74c56723870b63ce0b548110d6c3112a0945dbd21f789759a88834fb1101f24c61e30ce179bd14dea19001c2e4bb81f5e7721c9e
|
@@ -29,13 +29,14 @@ module TalltyImportExport
|
|
29
29
|
|
30
30
|
# 导出excel的空模版
|
31
31
|
def export_template_xlsx(**options)
|
32
|
+
origin_options = options.dup
|
32
33
|
process_options(options)
|
33
34
|
|
34
35
|
Axlsx::Package.new do |pack|
|
35
36
|
pack.use_shared_strings = true
|
36
37
|
workbook = pack.workbook
|
37
38
|
|
38
|
-
export_workbook workbook, **
|
39
|
+
export_workbook workbook, **origin_options
|
39
40
|
|
40
41
|
file_path = File.join(Rails.root, 'public', 'import')
|
41
42
|
FileUtils.mkdir_p(file_path) unless Dir.exist?(file_path)
|
@@ -47,42 +48,11 @@ module TalltyImportExport
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def export_workbook(workbook, **options)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
title3 = workbook.styles.add_style(alignment: alignment.merge(wrap_text: true), border: border, sz: 10)
|
56
|
-
_sheet_name = (respond_to?(:sheet_name) ? sheet_name : nil) || options[:sheet_name]
|
57
|
-
|
58
|
-
header_obj = @headers
|
59
|
-
|
60
|
-
workbook.add_worksheet(name: _sheet_name) do |sheet|
|
61
|
-
index = 0
|
62
|
-
|
63
|
-
if respond_to?(:first_header)
|
64
|
-
row_index = Axlsx.col_ref(headers.size - 1)
|
65
|
-
sheet.merge_cells("A1:#{row_index}1")
|
66
|
-
sheet.add_row [first_header], style: title1, height: 30
|
67
|
-
index += 1
|
68
|
-
end
|
69
|
-
|
70
|
-
header_obj.header_lines.each do |header_line|
|
71
|
-
sheet.add_row(header_line.map(&:name), style: title2, height: 25)
|
72
|
-
index += 1
|
73
|
-
end
|
74
|
-
|
75
|
-
# 合并相同 header
|
76
|
-
header_obj.header_seq_to_axios.values.each do |axios_ary|
|
77
|
-
next unless axios_ary.count > 1
|
78
|
-
|
79
|
-
top_right = [axios_ary.map(&:first).min, axios_ary.map(&:last).min]
|
80
|
-
bottom_left = [axios_ary.map(&:first).max, axios_ary.map(&:last).max]
|
81
|
-
sheet.merge_cells(
|
82
|
-
Axlsx.cell_r(top_right.first, top_right.last) + ':' + Axlsx.cell_r(bottom_left.first, bottom_left.last),
|
83
|
-
)
|
84
|
-
end
|
85
|
-
end
|
51
|
+
export_instance = TalltyImportExport::Export.new(@klass)
|
52
|
+
opts = options.symbolize_keys.merge({ headers: @headers })
|
53
|
+
Rails.logger.info opts
|
54
|
+
export_instance.process_options(opts)
|
55
|
+
export_instance.export_workbook(workbook, [], **opts)
|
86
56
|
end
|
87
57
|
|
88
58
|
def exchange_to_ids(xlsx_file, associations, **options)
|
@@ -136,7 +106,7 @@ module TalltyImportExport
|
|
136
106
|
|
137
107
|
def process_options(options)
|
138
108
|
options = import_options.merge(options).with_indifferent_access
|
139
|
-
@headers = options.delete(:headers) || import_headers
|
109
|
+
@headers = options.delete(:headers) || import_headers(**options)
|
140
110
|
@primary_keys = options.delete(:primary_keys) || @headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact
|
141
111
|
@skip_keys = options.delete(:skip_keys) || @headers.map { |header| header[:skip] ? header[:key].to_sym : nil }.compact
|
142
112
|
@params = options
|
@@ -28,6 +28,10 @@ module TalltyImportExport
|
|
28
28
|
def exchange_to_ids xlsx_file, associations, **options
|
29
29
|
import_instance.exchange_to_ids(xlsx_file, associations, **options)
|
30
30
|
end
|
31
|
+
|
32
|
+
def export_template_xlsx **options
|
33
|
+
import_instance.export_template_xlsx(**options)
|
34
|
+
end
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tallty_import_export
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- liyijie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zip-zip
|