Files created with Spreadsheet gem tagged as virus


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 = 
     sheet1 = excel_file.create_worksheet :name => 'Attendance'
     .#code for 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::, Zip::File::CREATE) do |z|
    z.get_output_stream("Other details.txt") { |os| os.write "This is a system generated excel sheet" }
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.



Ubuntu 14.04 server
rvm 1.26.11
Ruby 2.2.2


Ubuntu 14.04
rvm 1.26.11
Ruby 2.1.6

Gems version used:-


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


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

The mime type for the xls file generated is

application/CDFV2-corrupt; charset=binary

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