From cdc64f6c0f8ea1195a52ec566a365cd87639dd50 Mon Sep 17 00:00:00 2001 From: mr Date: Fri, 21 May 2010 14:45:10 +0200 Subject: xls export encoding, xls exp headlines removed, fix export error on empty smilesstring --- application.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/application.rb b/application.rb index c7ad2a4..04e40e5 100644 --- a/application.rb +++ b/application.rb @@ -1,5 +1,5 @@ require 'rubygems' -gem 'opentox-ruby-api-wrapper', '= 1.5.0' +gem 'opentox-ruby-api-wrapper', '= 1.5.1' require 'opentox-ruby-api-wrapper' #require 'sinatra/respond_to' #Sinatra::Application.register Sinatra::RespondTo @@ -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 -- cgit v1.2.3