Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to specify field types? #9

Open
facundofarias opened this issue Oct 23, 2015 · 4 comments
Open

Is there a way to specify field types? #9

facundofarias opened this issue Oct 23, 2015 · 4 comments

Comments

@facundofarias
Copy link

Once we have the CSV file as XLS, all the data it's taken as text, and I would like to have as the datatype they are, such as: Number, Date, etc.

Is there a way to specify this? (Like an options hash or something)
Thanks!

@tapajos
Copy link

tapajos commented Oct 23, 2015

I didn't submit a PR adding this code yet but I have something that may be helpful for you.

module Excelinator
  def self.array_to_xls(array)
    book = Spreadsheet::Workbook.new
    sheet = book.create_worksheet
    array.each_with_index do |row_data, index|
      row = sheet.row(index)
      row_data.each_with_index do |cell_data, row_index|
        if cell_data.kind_of?(Date)
          row.set_format row_index, Spreadsheet::Format.new(:number_format => 'MM/DD/YYYY')
        end
        row.push(cell_data)
      end
    end
    content = ''
    ios = StringIO.new(content)
    book.write(ios)
    content
  end
end

@facundofarias
Copy link
Author

Hey, yes! It's seems to be the feature that I need.
How can I integrate this code with the Excelinator I am using? By cloning the repo? Would this feature be enabled in the future? Thanks a lot!

@tapajos
Copy link

tapajos commented Oct 23, 2015

I'm planning submit a PR adding something like that but it needs to be improved to work with other types.

To be honest, you don't need Excelinator for that, you can use https://github.com/zdavatz/spreadsheet directly (if you don't need anything else from Excelinator).

@chrismo
Copy link
Member

chrismo commented Jan 12, 2016

Yeah, Excelinator is just a little bit of glue code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants