Import Excel into Rails app

前端 未结 4 1675
情歌与酒
情歌与酒 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

提交回复
热议问题