I have been using the Spreadsheet gem to create xls files and zip them for transfer using using ruby zip in my application.
excel_file = Spreadsheet::Workbook.new
.#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 the 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. And I am unable to read the excel file.
Also when the xls sheets is uploaded via gmail or hotmail, it is being tagged as virus.
Note:- This happens only for the xls or ods files which are greater than 140kB in size.
Both production and local environment generated files have this issue.
Is Spreadsheet gem the cause of this issue?
Update:-
The mime type for the file generated using Spreadsheet seems to be
application/CDFV2-corrupt; charset=binary
But the default mime type for an xls file should be
application/vnd.ms-office; charset=binary