Files created with Spreadsheet gem tagged as virus

4

I have been using the Spreadsheet gem to create xls files and zip them for download using rubyzip gem in my application.

Below is the code snippet of my lib class that generates xls files

     excel_file = Spreadsheet::Workbook.new 
     sheet1 = excel_file.create_worksheet :name => 'Attendance'
     .#code
     .#code for xls
     .#code
     excel_file.write("/home/Code/attn/files/excel/TEST-#{@name}-#{t}.xls")

And I zip the file like this in my controller

     files = Dir.glob("#{Rails.root}/files/excel/*.xls")
     @original_file = File.basename(files.first)
     @original_path = "#{Rails.root}/files/excel"

     Zip:: File.open(@filename, Zip::File::CREATE) do |z|
    z.add(@original_file,@original_path+'/'+@original_file)
    z.get_output_stream("Other details.txt") { |os| os.write "This is a system generated excel sheet" }
  end
send_file @filename, :type => 'application/zip', :filename => "Attendance-#{city}-#{t}.zip", :stream=> false, :x_sendfile=>true

This approach works very well when I download the zip file with by Ubuntu desktop and read the xls file with LibreOffice. The zip is extracted properly without any issues and the xls sheet is read without any warnings for corruption.

But when I download the same zip file with Windows 7 and unzip with File explorer, the xls file when opened with MS Excel the "Error 0x80070057: The parameters are incorrect" error pops up.

Also when the xls sheets is uploaded via gmail or hotmail, it is being tagged as virus.

Note:- This happens only for the xls files which are greater than 140kB in size created by Spreadsheet gem

Both production and local environment generated files have this issue.

Environment:-

Production

Ubuntu 14.04 server
rvm 1.26.11
Ruby 2.2.2

Development

Ubuntu 14.04
rvm 1.26.11
Ruby 2.1.6

Gems version used:-

Production

rubyzip (1.1.7)
spreadsheet (1.0.7)
rubygems-bundler (1.4.4)
ruby-ole (1.2.11.8)

Development

rubyzip (1.1.7)
spreadsheet (1.0.7)
rubygems-update (2.4.8)
ruby-ole (1.2.11.8)

The mime type for the xls file generated is

application/CDFV2-corrupt; charset=binary

ruby-on-rails
ruby
excel
rubygems
asked on Stack Overflow Dec 22, 2015 by Yugendran • edited Dec 23, 2015 by Yugendran

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0