I am building a web application that shows stock data trends and stock quotes. The data has been sent to me in an excel file and I now need to load it into the database. The excel file has daily stock data for each stock, with columns in this format:
date | bid | offer | price | volume
And each stock is in a separate work sheet in the file, as below, each block is a worksheet:
Stock1 | Stock2 | Stock3 | Stock4
What is the best way for me to load this data from the excel spreadsheet to my DailyQuotes table, the migration file for my DailyQuotes table is below:
class CreateDailyQuotes < ActiveRecord::Migration
def change
create_table :daily_quotes do |t|
t.date :date
t.decimal :bid
t.decimal :offer
t.decimal :price
t.integer :volume
t.integer :stock_id
t.timestamps
end
end
end
I have already created a Stocks table with the StockName and ID as columns.
The gem ‘spreadsheet’ maybe the best choice to parse old excel format ‘xls’. Check this guide
And if you want to deal with xlsx, maybe rubyXL is better.