Skip to content

Commit

Permalink
set examples
Browse files Browse the repository at this point in the history
  • Loading branch information
xuling1979 committed Jan 6, 2025
1 parent 5f81887 commit 2a33967
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions app/models/datum/ext/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Datum
module Ext::Export
extend ActiveSupport::Concern
LIST_KEY = '数据源'
EXAMPLE = '示例'

included do
attribute :code, :string
Expand Down Expand Up @@ -31,7 +32,8 @@ def worksheet
def export
set_headers
set_rows
set_validation_sheet
set_example
set_validation_names
set_validation
set_relevant_validation
set_note
Expand Down Expand Up @@ -123,13 +125,13 @@ def set_note
end
end

def set_validation_sheet
def set_validation_names
format = workbook.add_format(
fg_color: '#cccccc',
valign: 'vcenter',
align: 'center'
)
sheets = template.validations.where.not(sheet: LIST_KEY).select(:sheet).distinct.pluck(:sheet)
sheets = template.validations.where.not(sheet: [LIST_KEY, EXAMPLE]).select(:sheet).distinct.pluck(:sheet)
sheets.each do |sheet_name|
sheet = workbook.add_worksheet(sheet_name)
template.validations.where(sheet: sheet_name).each_with_index do |v, index|
Expand All @@ -156,9 +158,20 @@ def set_validation
end
end

def set_example
sheets = template.validations.where(sheet: EXAMPLE).select(:sheet).distinct.pluck(:sheet)
sheets.each do |sheet_name|
sheet = workbook.add_worksheet(sheet_name)
template.validations.where(sheet: sheet_name).each_with_index do |v, index|
sheet.write(0, index, v.header, format)
sheet.write_col(1, index, v.fields)
end
end
end

#
def set_relevant_validation
sheets = template.validations.where.not(sheet: LIST_KEY).select(:sheet).distinct.pluck(:sheet)
sheets = template.validations.where.not(sheet: [LIST_KEY, EXAMPLE]).select(:sheet).distinct.pluck(:sheet)
sheets.each do |sheet_name|
index = template.headers.index(sheet_name)
col_str = ColName.instance.col_str(index)
Expand Down

0 comments on commit 2a33967

Please sign in to comment.