Commit d24a60ff by liyijie

fix: 解决each_method的逻辑错误

parent 6b0916d9
......@@ -65,7 +65,7 @@ module TalltyImportExport
end
end
def export_workbook workbook, records
def export_workbook workbook, association_records
# excel导出样式
alignment = { vertical: :center, horizontal: :center }
border = { color: '969696', style: :thin }
......@@ -89,10 +89,13 @@ module TalltyImportExport
merge_column_hash = {}
first_content_row_index = respond_to?(:first_header) ? 2 : 1
each_method = @each_method || :each
records.try_method(each_method).with_index do |record, index|
index = 0
association_records.each do |association_record|
row = []
headers.each_with_index do |header, col_index|
records = @each_method.present? ? association_record.try_method(@each_method) : [association_record]
records.each do |record|
index += 1
_data = handle_data(record, header, index)
if header[:merge].present? && last_row.present? && _data == last_row[col_index]
# 这里使用二维数组,每个数组里都是列内容相同的各行
......@@ -109,6 +112,7 @@ module TalltyImportExport
sheet.add_row row, style: title3, height: @row_height, types: headers.map{|header| header[:format]&.to_sym}
last_row = row
end
end
# 需要根据column进行多行的内容合并
if merge_column_hash.present?
merge_column_hash.each do |col_index, row_arr|
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment