Commit e638cb04 by Ivan Lan

feat: 完成内容导出 还缺少 header 处理

parent fa85d2c6
......@@ -91,17 +91,15 @@ module TalltyImportExport
end
# 合并相同值
# value_seq_to_axios.values.each do |axios_ary|
# if axios_ary.count > 1
# top_right = [axios_ary.map(&:first).min, axios_ary.map(&:last).min]
# bottom_left = [axios_ary.map(&:first).max, axios_ary.map(&:last).max]
# sheet.merge_cells(
# Axlsx::cell_r(top_right.first, top_right.last) + ':' + Axlsx::cell_r(bottom_left.first, bottom_left.last)
# )
# end
# end
value_seq_to_axios.values.each do |axios_ary|
if axios_ary.count > 1
top_right = [axios_ary.map(&:first).min, axios_ary.map(&:last).min]
bottom_left = [axios_ary.map(&:first).max, axios_ary.map(&:last).max]
sheet.merge_cells(
Axlsx::cell_r(top_right.first, top_right.last) + ':' + Axlsx::cell_r(bottom_left.first, bottom_left.last)
)
end
end
end
end
......
......@@ -16,6 +16,7 @@ class TalltyImportExport::ExportPayload
@value_handler = value_handler
@context = {
header_seq_to_value_seq_to_value: {},
parent_cell_seq_to_children_cell_value_array: {},
flatten_headers: @flatten_headers,
}
end
......
......@@ -2,7 +2,6 @@ class TalltyImportExport::ExportPayload::Cell
attr_accessor :cell_cluster, :value, :header, :parent_path
# cell_cluster 是表格纵向 集合
# cell_the_same_line 是表格横向 集合
def initialize header, value, context, parent_path=[], &value_handler
@value = value
@header = header
......@@ -12,15 +11,17 @@ class TalltyImportExport::ExportPayload::Cell
@context = context
value.seq_chain.each do |s|
unless (@context[:header_seq_to_value_seq_to_value][header.seq])
@context[:header_seq_to_value_seq_to_value][header.seq] = {}
end
# s = seq
@context[:header_seq_to_value_seq_to_value][header.seq] ||= {}
@context[:header_seq_to_value_seq_to_value][header.seq][s] = value # NOTE: value 对象
end
# parent
@parent_path = parent_path
@context[:parent_cell_seq_to_children_cell_value_array][parent_cell_seq] ||= []
@context[:parent_cell_seq_to_children_cell_value_array][parent_cell_seq].push(@value)
@cell_cluster = []
end
......@@ -28,6 +29,10 @@ class TalltyImportExport::ExportPayload::Cell
@seq ||= SecureRandom.uuid
end
def parent_cell_seq
@parent_path.last&.seq
end
def depth
@parent_path.count
end
......@@ -41,7 +46,6 @@ class TalltyImportExport::ExportPayload::Cell
new_cells = @header.children.map do |child_header|
if (child_header.children.present?)
val = @value.value[child_header.key.to_sym]
order = 0
val.map do |val|
cell = TalltyImportExport::ExportPayload::Cell.new(
child_header,
......@@ -50,7 +54,6 @@ class TalltyImportExport::ExportPayload::Cell
[*self.parent_path, self],
&@value_handler
)
order += 1
cell
end
else
......@@ -81,7 +84,10 @@ class TalltyImportExport::ExportPayload::Cell
map do |header|
target_value = nil
@value.seq_chain.uniq.reverse.each do |seq|
# 兄弟细胞上先查找,以解决同级兄弟细胞父一样,而导致的值覆盖
brother_cell_value_seqs = (@context[:parent_cell_seq_to_children_cell_value_array][parent_cell_seq] || []).map(&:seq)
[*brother_cell_value_seqs, *@value.seq_chain.uniq.reverse].each do |seq|
next if target_value
# seq = @value.seq
if @context[:header_seq_to_value_seq_to_value][header.seq]&.[](seq)
......
......@@ -44,7 +44,7 @@ class TalltyImportExport::ExportPayload::CellColumn
@flatten_cells = divised_cell_clusters.flatten
depth_to_cells_mapping = @flatten_cells.group_by { |cell| [cell.depth, cell.header.seq] }
depth_to_cells_mapping = @flatten_cells.group_by { |cell| [cell.header.seq] }
@tallest_cell_cluster = depth_to_cells_mapping.values.max { |a, b| a.count <=> b.count }
......
......@@ -82,7 +82,7 @@ RSpec.describe TalltyImportExport::Importable do
it 'export' do
# TalltyImportExport::ExportForm.new.export_workbook nil, [@payload], { headers: @header_h[:items] }
TalltyImportExport::ExportForm.new.export_xlsx [@payload], { headers: @header_h[:items] }
TalltyImportExport::ExportForm.new.export_xlsx [@payload, @payload], { headers: @header_h[:items] }
end
end
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