Commit 47ff0a8e by liyijie

feat: remove auto merge cells feature

parent eba1a437
...@@ -5,11 +5,11 @@ module TalltyImportExport ...@@ -5,11 +5,11 @@ module TalltyImportExport
end end
class << self class << self
def export_template_xlsx form def export_template_xlsx(form)
export_xlsx([], { export_xlsx([], {
headers: form_transfer_to_headers(form), headers: form_transfer_to_headers(form),
header_only: true header_only: true,
}) },)
end end
end end
...@@ -18,11 +18,11 @@ module TalltyImportExport ...@@ -18,11 +18,11 @@ module TalltyImportExport
alignment = { vertical: :center, horizontal: :center } alignment = { vertical: :center, horizontal: :center }
border = { color: '969696', style: :thin } border = { color: '969696', style: :thin }
title1 = workbook.styles.add_style(alignment: alignment, border: border, sz: 12, b: true) title1 = workbook.styles.add_style(alignment: alignment, border: border, sz: 12, b: true)
title2 = workbook.styles.add_style(alignment: alignment, border: border, bg_color: "2a5caa", sz: 12, fg_color: "fffffb") title2 = workbook.styles.add_style(alignment: alignment, border: border, bg_color: '2a5caa', sz: 12, fg_color: 'fffffb')
title3 = workbook.styles.add_style(alignment: alignment.merge(wrap_text: true), border: border, sz: 10) title3 = workbook.styles.add_style(alignment: alignment.merge(wrap_text: true), border: border, sz: 10)
_sheet_name = (respond_to?(:sheet_name) ? self.sheet_name : nil) || options[:sheet_name] _sheet_name = (respond_to?(:sheet_name) ? sheet_name : nil) || options[:sheet_name]
header_obj = export_headers_result **options header_obj = export_headers_result(**options)
workbook.add_worksheet(name: _sheet_name) do |sheet| workbook.add_worksheet(name: _sheet_name) do |sheet|
index = 0 index = 0
...@@ -41,13 +41,13 @@ module TalltyImportExport ...@@ -41,13 +41,13 @@ module TalltyImportExport
# 合并相同 header # 合并相同 header
header_obj.header_seq_to_axios.values.each do |axios_ary| header_obj.header_seq_to_axios.values.each do |axios_ary|
if axios_ary.count > 1 next unless 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] top_right = [axios_ary.map(&:first).min, axios_ary.map(&:last).min]
sheet.merge_cells( bottom_left = [axios_ary.map(&:first).max, axios_ary.map(&:last).max]
Axlsx::cell_r(top_right.first, top_right.last) + ':' + Axlsx::cell_r(bottom_left.first, bottom_left.last) sheet.merge_cells(
) Axlsx.cell_r(top_right.first, top_right.last) + ':' + Axlsx.cell_r(bottom_left.first, bottom_left.last),
end )
end end
return if options[:header_only] return if options[:header_only]
...@@ -69,7 +69,6 @@ module TalltyImportExport ...@@ -69,7 +69,6 @@ module TalltyImportExport
handle_data(payload, header, index, **opts) handle_data(payload, header, index, **opts)
end end
# p '----------------------------------------------------------------' # p '----------------------------------------------------------------'
# payload.lines.each { |x| p x.map { |x| x.try(:value) || '________' } } # payload.lines.each { |x| p x.map { |x| x.try(:value) || '________' } }
...@@ -78,33 +77,30 @@ module TalltyImportExport ...@@ -78,33 +77,30 @@ module TalltyImportExport
line.each_with_index do |value, col_index| line.each_with_index do |value, col_index|
value_living_alone_col_index_to_value_count[col_index] ||= 0 value_living_alone_col_index_to_value_count[col_index] ||= 0
if (TalltyImportExport::ExportPayload::Value === value) if value.is_a?(TalltyImportExport::ExportPayload::Value)
row << value.value row << value.value
value_living_alone_col_index_to_value_count[col_index] += 1 value_living_alone_col_index_to_value_count[col_index] += 1
unless value_seq_to_axios[value.seq] value_seq_to_axios[value.seq] = [] unless value_seq_to_axios[value.seq]
value_seq_to_axios[value.seq] = [] value_seq_to_axios[value.seq] << [col_index, row_index + index]
end
value_seq_to_axios[value.seq] << [col_index , row_index + index]
else else
row << nil row << nil
end end
formats.push( formats.push(
header_obj.flatten_value[col_index].format&.to_sym || (row.last.is_a?(String) ? :string : nil) header_obj.flatten_value[col_index].format&.to_sym || (row.last.is_a?(String) ? :string : nil),
) )
end end
sheet.add_row(row, style: title3, height: @row_height, types: formats) sheet.add_row(row, style: title3, height: @row_height, types: formats)
formats = [] formats = []
end end
# 合并仅有一个值的一列中所有格子 # 合并仅有一个值的一列中所有格子
value_living_alone_col_index_to_value_count.each_pair do |col_index, count| # value_living_alone_col_index_to_value_count.each_pair do |col_index, count|
if count == 1 # if count == 1
sheet.merge_cells( # sheet.merge_cells(
Axlsx::cell_r(col_index, index) + ':' + Axlsx::cell_r(col_index, index + payload.max_matrix_height - 1) # Axlsx::cell_r(col_index, index) + ':' + Axlsx::cell_r(col_index, index + payload.max_matrix_height - 1)
) # )
end # end
end # end
index += payload.max_matrix_height index += payload.max_matrix_height
end end
...@@ -112,23 +108,21 @@ module TalltyImportExport ...@@ -112,23 +108,21 @@ module TalltyImportExport
# 合并相同值 # 合并相同值
value_seq_to_axios.values.each do |axios_ary| value_seq_to_axios.values.each do |axios_ary|
if axios_ary.count > 1 next unless 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] top_right = [axios_ary.map(&:first).min, axios_ary.map(&:last).min]
sheet.merge_cells( bottom_left = [axios_ary.map(&:first).max, axios_ary.map(&:last).max]
Axlsx::cell_r(top_right.first, top_right.last) + ':' + Axlsx::cell_r(bottom_left.first, bottom_left.last) 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 end
end end
def export_headers_result **options def export_headers_result **options
@headers = options.symbolize_keys[:headers] @headers = options.symbolize_keys[:headers]
@headers = super(**options) @headers = super(**options)
@headers = TalltyImportExport::Attr::ExportHeader.new({ items: @headers }) @headers = TalltyImportExport::Attr::ExportHeader.new({ items: @headers })
end end
end end
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