Import Excel into Rails app

前端 未结 4 1676
情歌与酒
情歌与酒 2021-01-30 14:08

I am creating a small rails app for personal use and would like to be able to upload excel files to later be validated and added to the database. I had this working previously w

相关标签:
4条回答
  • 2021-01-30 14:21
    • https://rubygems.org/gems/spreadsheet
    • https://github.com/zdavatz/spreadsheet/blob/master/GUIDE.md

    "The Spreadsheet Library is designed to read and write Spreadsheet Documents. As of version 0.6.0, only Microsoft Excel compatible spreadsheets are supported. Spreadsheet is a combination/complete rewrite of the Spreadsheet::Excel Library by Daniel J. Berger and the ParseExcel Library by Hannes Wyss. Spreadsheet can read, write and modify Spreadsheet Documents."

    EDIT
    To get the uploaded file you have two options:
    1. (recommended) Use something a file upload plugin like paperclip and it will handle the bits and bolts.
    2. use the IO object params[:dump][:excel_file] as per: http://guides.rails.info/form_helpers.html#what-gets-uploaded

    0 讨论(0)
  • 2021-01-30 14:23

    There's an excellent RailsCast on how to do this with the roo gem: http://railscasts.com/episodes/396-importing-csv-and-excel

    0 讨论(0)
  • 2021-01-30 14:32

    Hey I use the spreadsheet gem and wrote a simple app to understand how it all fits together. It currently runs on Rails 3.1 and Carrierwave, hope this helps:

    https://github.com/jalagrange/excel_test_app

    0 讨论(0)
  • 2021-01-30 14:42

    we use roo which support Open Office,Excel,Google,Excel.xlsx

    0 讨论(0)
提交回复
热议问题