本文介绍了Roo 电子表格上传 OLE2 签名无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是的,所以我检查了 Roo.伟大的宝石和所有,并有一个没有模型的非常基本的应用程序.和基本控制器、类和视图,我似乎无法上传电子表格,因为我收到 OLE2 签名无效
错误.我有以下基本设置
Right so I've checked out Roo. Great gem and all and have a really basic application that doesn't have no models. And basic controller, class and view and I can't seem to get a spreadsheet to upload as I am getting OLE2 signature is invalid
error. I have the following basic setup
控制器
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
电子表格标签服务
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 %>
推荐答案
代替 .xls
格式使用 .xlsx
格式.然后它会工作.
Instead of .xls
format use .xlsx
format.then it will work.
对我来说这是有效的.
这篇关于Roo 电子表格上传 OLE2 签名无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!