nish
nish

Reputation: 7280

Writing integer values to spreadsheet

I am using the following code to convert a csv to spreadsheet:

require 'spreadsheet'
require 'csv'

book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet

CSV.open("product_2014-11-19_10-41-00.csv", 'r') do |csv|
    csv.each_with_index do |row, i|
        sheet1.row(i).replace(row)
    end
end
book.write("temp.xls")

But on doing so, the spreadsheet contains a leading quote for columns that hold integer values. Eg consider the row SGDEL,18,,,,140,0,Bib columns corresponding to 18, 140 and 0 become '18, '140, '0. Why is this so? How can I fix this?

Thanks

Upvotes: 1

Views: 34

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

There is an option for CSV#open:

#                    vvvvvvvvvvvv 
CSV.open("…", "…", { force_quotes: false }) do |csv|

Setting it to false should do the trick.

Upvotes: 2

Related Questions