简体   繁体   中英

Ruby on Rails - Roo gem | Issue opening active record attachment

Status:

  • I have a simple new Ruby On Rails App
  • I need to import some data from MS Excel in.xlsx format
  • I programmed an uploading to ActiveRecord as attachment via an attribute called 'excel'
  • I found a gem called Roo which should do the opening of the attachment
  • ...via: Roo::Excelx.open() command
  • Then executes the accessing part of the file

Issue: Roo::Excel.open() doesnt work for:

  1. Roo::Excel.open(excel)
  2. Roo::Excel.open(excel.attachment)

What is the correct command to execute to open the ActiveRecord::Attachment ?

how about do this?

ModelName.excel.open do |file|
 xlsx = Roo::Spreadsheet.open(file)
end

Actually I got an answer outside of Stackoverflow which was this:

Roo::Spreadsheet.open(ActiveStorage::Blob.service.path_for(excel.key), extension: 'xlsx')

I loaded one row from the Excel so must change code but opening it seemed to have worked: :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM