I'm trying to upload and parse an .XLS file. I've tried with roo-xls and Spreadsheet, but with both, I'm getting this error:
Ole::Storage::FormatError in UploadController#upload
OLE2 signature is invalid
I found a few resources about this error, and the only answer ever given is to re-save the document as .XLS, because although the original is labeled as .XLS, it actually isn't.
Unfortunately this isn't really an option, because I have users uploading files, so it's important that it work without requiring a re-save.
For the record, I tried re-saving the file and now it works, but I'm at a loss as to why it works, because the file's format before and after the re-save looks to be the exact same. This is what was listed under "type of file" in Excel, before and after:
Microsoft Excel 97-2003 Worksheet (.xls)"
And this is what is listed under "Type" in Libreoffice, before and after:
Microsoft Excel Worksheet (application/vnd.ms-excel)
What's going on?
Also, here's my simple upload code:
form
<%= form_tag(upload_path, multipart: true) do %>
<%= file_field_tag :file %>
<% end %>
controller
file = params[:file].path
#Roo Attempt
doc = Roo::Excel.new(file)
#Spreadsheet Attempt
require 'spreadsheet'
Spreadsheet.client_encoding = 'UTF-8'
doc = Spreadsheet.open(file).worksheets