diff options
Diffstat (limited to 'application.rb')
-rw-r--r-- | application.rb | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/application.rb b/application.rb index 31dc0df..0f557bf 100644 --- a/application.rb +++ b/application.rb @@ -84,20 +84,21 @@ get '/:id' do dataset.yaml when /ms-excel/ require 'spreadsheet' - response['Content-Type'] = 'application/vnd.ms-excel' + response['Content-Type'] = 'application/vnd.ms-excel' + Spreadsheet.client_encoding = 'UTF-8' book = Spreadsheet::Workbook.new tmp = Tempfile.new('opentox-feature-xls') sheet = book.create_worksheet :name => 'Training Data' - sheet.update_row(0, "Chemical Structure","Activity") sheet.column(0).width = 100 - headline = Spreadsheet::Format.new :weight => :bold, :size => 12 - 2.times{|x| sheet.row(0).set_format(x , headline)} - i = 1 + i = 0 YAML.load(dataset.yaml).data.each do |line| - smilestring = RestClient.get(line[0], :accept => 'chemical/x-daylight-smiles').to_s - line[1][0] ? val = line[1][0].first[1] ? "1" : "0" : val = "" - sheet.update_row(i, smilestring , val) - i+=1 + begin + smilestring = RestClient.get(line[0], :accept => 'chemical/x-daylight-smiles').to_s + line[1][0] ? val = line[1][0].first[1] ? "1" : "0" : val = "" + sheet.update_row(i, smilestring , val) + i+=1 + rescue + end end begin book.write tmp.path |