tallty_import_export 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c79d5ce9feb1942a7a972b5b781d77a8227bd6cde6d572c9b9c35cc49fa7fca
4
- data.tar.gz: 18b10723fc3ff9d1b3e2085cfcff144dae8a91b5658a8b7e8ab7d4d38d900b69
3
+ metadata.gz: 284928193ebed0e079f44ba98ee7a2f0d51c05f0c1ea5100dd68973940f56369
4
+ data.tar.gz: 75dbf1351c7a08ce445b508ea60aba31da811fcfc87e9355c5f8c710f66be47a
5
5
  SHA512:
6
- metadata.gz: 2072530b6532f423f7076a630b32770bebbacc2555004fe9073312b5c9665801bc2d120d15f96ff4542f0522fc2fd871b3e237b316f0c4a6d383607c496ea516
7
- data.tar.gz: 2f8ac80073fa1fa429b62316e05f6586245a1e410a5d6ddb181cd2fb9c49c98decb67f74d7e3e2dcd22b8dffeb30274a075c004c6d4a38775b543683ac4c2925
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, **options
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
- # excel导出样式
51
- alignment = { vertical: :center, horizontal: :center }
52
- border = { color: '969696', style: :thin }
53
- title1 = workbook.styles.add_style(alignment: alignment, border: border, sz: 12, b: true)
54
- title2 = workbook.styles.add_style(alignment: alignment, border: border, bg_color: '2a5caa', sz: 12, fg_color: 'fffffb')
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
@@ -1,3 +1,3 @@
1
1
  module TalltyImportExport
2
- VERSION = '1.1.2'
2
+ VERSION = '1.1.3'
3
3
  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.2
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-07 00:00:00.000000000 Z
11
+ date: 2022-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zip-zip