5

そう、私はRooをチェックアウトしました。素晴らしい宝石とすべてのモデルを持っていない本当に基本的なアプリケーションを持っています。そして、基本的なコントローラ、クラス、およびビューと私はOLE2 signature is invalidエラーを取得しているようにスプレッドシートをアップロードするように見えることができません。私は、次の基本的なセットアップを持ってRooスプレッドシートのOLE2署名のアップロードが無効です

コントローラ

class SpreadsheetServiceController < ApplicationController 

    def new 
    end 

    def create  
    parser = SpreadsheetTagService.new(params[:spreadsheet][:file]) 

    respond_to do |format| 
     format.all {render :json => 'Done'} 
    end 
    end 
end 

SpreadsheetTagService

class SpreadsheetTagService 
    include Roo 

    def initialize(uploaded_file) 
    @tmp_destination = "#{Rails.root}/tmp/tag-import.xls" 
    @file_path = save_file_to_tmp(uploaded_file) 
    @file = File.new(@file_path) 
    read_file(@file) 
    end 

    private 
    def save_file_to_tmp(uploaded_file) 
     FileUtils.mv(uploaded_file.tempfile.path, @tmp_destination) 
     @tmp_destination 
    end 

    def read_file(file) 
     @spreadsheet = open_spreadsheet(file) 
     @spreadsheet.each_with_pagename do |name,sheet|  
     Rails.logger.debug(sheet) 
     end  
    end 

    def open_spreadsheet(file) 
     case File.extname(file.path) 
     when ".csv" then Csv.new(file.path, nil, :ignore) 
     when ".xls" then Excel.new(file.path, nil, :ignore) 
     when ".xlsx" then Excelx.new(file.path, nil, :ignore) 
     else raise "Unknown file type: #{file.original_filename}" 
     end 
    end 

end 

ビュー

<%= form_tag spreadsheetupload_url, multipart: true do %> 
    <%= file_field_tag :file %> 
    <%= submit_tag "Import" %> 
<% end %> 

答えて

3

この記事では、非常に有用であった:

http://atomicules.co.uk/2009/07/17/roo-and-ole2-signature-is-invalid.html

フルテキスト:

If you get an "Ole::Storage::FormatError: OLE2 signature is invalid" error when reading an Excel spreadsheet using Roo it can probably be solved by resaving the spreadsheet (unfortunately using Excel) and making sure it is saving it as "Microsoft Office Excel Workbook (*.xls)", etc and not something odd.

I had two spreadsheets that had the .xls extension, but seems they were masquerading; when doing a Save As on them one was actually in a "Text (tab delimited)" format and the other in a "Web Page" HTML format. These were system generated files, so I guess that explains their odd form.

+2

リンクが壊れる可能性があるため、スタックオーバーフローではリンクのみの回答は推奨されません。 –

+0

リンクは、XLSとしてファイルを再保存することを提案しています。私のために働いた。名前を付けて保存...プロンプトで、Excelは私のファイルが実際にXMLであることを示唆していました。 –

4

代わり.xls形式の使用.xlsxのそれが動作しますformat.then。

私にとってはうまくいきます。

関連する問題