This commit is contained in:
邱博亞 2024-03-21 22:45:15 +08:00
parent 12ded1ffe1
commit 8459e2e191
2 changed files with 6 additions and 6 deletions

View File

@ -623,14 +623,14 @@ class Admin::Coloncancerpredict2sController < OrbitAdminController
@pagination = create_pagination(@page_num.to_i) @pagination = create_pagination(@page_num.to_i)
end end
def export_cancer_tool_record def export_cancer_tool_record
@cancer_records = Coloncancerpredictrecord2.where("title"=>@app_title).desc(:id) cancer_records = Coloncancerpredictrecord2.where("title"=>@app_title).desc(:id)
dir_path = 'tmp/cancer_tool/' dir_path = 'tmp/cancer_tool/'
#FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path) #FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path)
FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist
@filename = ("#{Time.now.year}_%02s_%02s_export_cancer_tool_record.xlsx"%[Time.now.month,Time.now.day]).gsub(" ","0") @filename = ("#{Time.now.year}_%02s_%02s_export_cancer_tool_record.xlsx"%[Time.now.month,Time.now.day]).gsub(" ","0")
Dir.chdir(dir_path) do Dir.chdir(dir_path) do
File.open(@filename, 'w') do |f| File.open(@filename, 'w') do |f|
f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'export_cancer_tool_record.xlsx',:locals=> {:@results=>@cancer_records} ) f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'export_cancer_tool_record.xlsx',:locals=> {:results=>cancer_records} )
end end
end end
tmp_filename_data = File.read(dir_path +@filename) tmp_filename_data = File.read(dir_path +@filename)

View File

@ -2,18 +2,18 @@
wb = xlsx_package.workbook wb = xlsx_package.workbook
wb.add_worksheet(name: "cancer_tool") do |sheet| wb.add_worksheet(name: "cancer_tool") do |sheet|
if !@results[0].nil? if !results[0].nil?
row = [] row = []
title = sheet.styles.add_style(:bg_color => "FFFF00",:border=>{ :style => :thin, :color => "666666" },:alignment=>{ :horizontal => :center,:vertical => :center ,:wrap_text => true}) title = sheet.styles.add_style(:bg_color => "FFFF00",:border=>{ :style => :thin, :color => "666666" },:alignment=>{ :horizontal => :center,:vertical => :center ,:wrap_text => true})
column = sheet.styles.add_style(:alignment=>{ :horizontal => :center,:vertical => :center ,:wrap_text => true},:border=>{ :style => :thin, :color => "666666" }) column = sheet.styles.add_style(:alignment=>{ :horizontal => :center,:vertical => :center ,:wrap_text => true},:border=>{ :style => :thin, :color => "666666" })
row << ((I18n.locale=="en") ? 'submit time' : '提交時間') row << ((I18n.locale=="en") ? 'submit time' : '提交時間')
@fields = @results.first.names.keys @fields = results.first.names.keys
@fields.each do |field_name| @fields.each do |field_name|
row << @results.first.names[field_name][I18n.locale.to_s].split('<br/>')[0] row << results.first.names[field_name][I18n.locale.to_s].split('<br/>')[0]
end end
#export data start #export data start
export_data_rows = [] export_data_rows = []
@results.each do |result| results.each do |result|
temp_row = [] temp_row = []
temp_row << result.created_at.to_s temp_row << result.created_at.to_s
result.result.each do |key,value| result.result.each do |key,value|