tallty_import_export 1.0.26 → 1.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tallty_import_export/export.rb +28 -17
- data/lib/tallty_import_export/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d689c40b8f11354501a465563d14f5ab1060137fb2221180db05c8a18fe2b0d
|
4
|
+
data.tar.gz: 9cbd15c9a1eae1a0e036dd4557fb5197e3f595067b035dd01119167becee6d3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a11b8561c856588abf871fe6cac330e3a9412e468c6ff2d3480be75b8976b22a7037a655c51df7c884a367d9efa7c8b362c1c46ca3a1e5824f8777ccf0bb1204
|
7
|
+
data.tar.gz: d178c5d5ae84107a04862e7b5b929ba8546776b1400ed79bde6c518f656d6ac7c573bfaaad3d60b499ec18d1cf9df3a09962d0669c251acbc24f905939ab884e
|
@@ -15,7 +15,7 @@ module TalltyImportExport
|
|
15
15
|
# { key: 'user_code', name: '考核人工号' },
|
16
16
|
# { key: 'user_department_name', name: '考核人部门' },
|
17
17
|
# { key: 'state', name: '考核状态', method: :state_zh },
|
18
|
-
# { key: 'score', name: '考核分' },
|
18
|
+
# { key: 'score', name: '考核分', source: true },
|
19
19
|
# ]
|
20
20
|
# export_headers_result / headers
|
21
21
|
# key: 属性的英文名,可以支持user.name这样的方式
|
@@ -28,6 +28,7 @@ module TalltyImportExport
|
|
28
28
|
# merge: true/false,默认false,某一列,如果上下行的内容相同,则直接合并单元格
|
29
29
|
# json: model_payload,代表存储在某一个列中
|
30
30
|
# select: [{ label: '已报备', value: 'submitted'}, ...],需要转换的枚举类型
|
31
|
+
# source: true,如果source为true,代表从association_record 进行属性查询
|
31
32
|
|
32
33
|
def export_xlsx records, **options
|
33
34
|
records = with_scope records
|
@@ -65,7 +66,7 @@ module TalltyImportExport
|
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
|
-
def export_workbook workbook,
|
69
|
+
def export_workbook workbook, association_records
|
69
70
|
# excel导出样式
|
70
71
|
alignment = { vertical: :center, horizontal: :center }
|
71
72
|
border = { color: '969696', style: :thin }
|
@@ -89,25 +90,35 @@ module TalltyImportExport
|
|
89
90
|
merge_column_hash = {}
|
90
91
|
first_content_row_index = respond_to?(:first_header) ? 2 : 1
|
91
92
|
|
92
|
-
|
93
|
-
|
93
|
+
index = 0
|
94
|
+
association_records.each do |association_record|
|
94
95
|
row = []
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
96
|
+
records = @each_method.present? ?
|
97
|
+
(try_method(association_record, @each_method) || [nil]) :
|
98
|
+
[association_record]
|
99
|
+
|
100
|
+
records.each do |record|
|
101
|
+
headers.each_with_index do |header, col_index|
|
102
|
+
index += 1
|
103
|
+
_data = header[:source] ?
|
104
|
+
handle_data(association_record, header, index) :
|
105
|
+
handle_data(record, header, index)
|
106
|
+
|
107
|
+
if header[:merge].present? && last_row.present? && _data == last_row[col_index]
|
108
|
+
# 这里使用二维数组,每个数组里都是列内容相同的各行
|
109
|
+
merge_column_hash[col_index] ||= []
|
110
|
+
if merge_column_hash[col_index].last&.last == index + first_content_row_index - 1
|
111
|
+
# 说明内容和上面的是延续的,继续加入之前的数组
|
112
|
+
merge_column_hash[col_index].last << index + first_content_row_index
|
113
|
+
else
|
114
|
+
merge_column_hash[col_index] << [index + first_content_row_index - 1, index + first_content_row_index]
|
115
|
+
end
|
105
116
|
end
|
117
|
+
row.push(_data)
|
106
118
|
end
|
107
|
-
row.
|
119
|
+
sheet.add_row row, style: title3, height: @row_height, types: headers.map{|header| header[:format]&.to_sym}
|
120
|
+
last_row = row
|
108
121
|
end
|
109
|
-
sheet.add_row row, style: title3, height: @row_height, types: headers.map{|header| header[:format]&.to_sym}
|
110
|
-
last_row = row
|
111
122
|
end
|
112
123
|
# 需要根据column进行多行的内容合并
|
113
124
|
if merge_column_hash.present?
|