Commit 47ff0a8e by liyijie

feat: remove auto merge cells feature

parent eba1a437
......@@ -5,11 +5,11 @@ module TalltyImportExport
end
class << self
def export_template_xlsx form
def export_template_xlsx(form)
export_xlsx([], {
headers: form_transfer_to_headers(form),
header_only: true
})
header_only: true,
},)
end
end
......@@ -18,11 +18,11 @@ module TalltyImportExport
alignment = { vertical: :center, horizontal: :center }
border = { color: '969696', style: :thin }
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)
_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|
index = 0
......@@ -41,14 +41,14 @@ module TalltyImportExport
# 合并相同 header
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]
sheet.merge_cells(
Axlsx::cell_r(top_right.first, top_right.last) + ':' + Axlsx::cell_r(bottom_left.first, bottom_left.last)
Axlsx.cell_r(top_right.first, top_right.last) + ':' + Axlsx.cell_r(bottom_left.first, bottom_left.last),
)
end
end
return if options[:header_only]
......@@ -69,7 +69,6 @@ module TalltyImportExport
handle_data(payload, header, index, **opts)
end
# p '----------------------------------------------------------------'
# payload.lines.each { |x| p x.map { |x| x.try(:value) || '________' } }
......@@ -78,33 +77,30 @@ module TalltyImportExport
line.each_with_index do |value, col_index|
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
value_living_alone_col_index_to_value_count[col_index] += 1
unless value_seq_to_axios[value.seq]
value_seq_to_axios[value.seq] = []
end
value_seq_to_axios[value.seq] << [col_index , row_index + index]
value_seq_to_axios[value.seq] = [] unless value_seq_to_axios[value.seq]
value_seq_to_axios[value.seq] << [col_index, row_index + index]
else
row << nil
end
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
sheet.add_row(row, style: title3, height: @row_height, types: formats)
formats = []
end
# 合并仅有一个值的一列中所有格子
value_living_alone_col_index_to_value_count.each_pair do |col_index, count|
if count == 1
sheet.merge_cells(
Axlsx::cell_r(col_index, index) + ':' + Axlsx::cell_r(col_index, index + payload.max_matrix_height - 1)
)
end
end
# value_living_alone_col_index_to_value_count.each_pair do |col_index, count|
# if count == 1
# sheet.merge_cells(
# Axlsx::cell_r(col_index, index) + ':' + Axlsx::cell_r(col_index, index + payload.max_matrix_height - 1)
# )
# end
# end
index += payload.max_matrix_height
end
......@@ -112,23 +108,21 @@ module TalltyImportExport
# 合并相同值
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]
sheet.merge_cells(
Axlsx::cell_r(top_right.first, top_right.last) + ':' + Axlsx::cell_r(bottom_left.first, bottom_left.last)
Axlsx.cell_r(top_right.first, top_right.last) + ':' + Axlsx.cell_r(bottom_left.first, bottom_left.last),
)
end
end
end
end
def export_headers_result **options
@headers = options.symbolize_keys[:headers]
@headers = super(**options)
@headers = TalltyImportExport::Attr::ExportHeader.new({ items: @headers })
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