Best way to deal in reading very old xls files - ruby-on-rails

I'm coming across transferring and old app to a new one, some of the reports are generated by some very old desktop app running on old xls files, the new app is build with rails 3.x but the only problem I have is that it keeps on getting an OLE Signature error, I tried parsing the files manually via excel to xlsx and all the rails xls gems start reading them. What would be the best way to handle old xls files?
Are there actually gems that read very old xls files, I've already tested roo, spreadsheet, rubyXL (i can't get simple-spreadsheet to work due to version conflicts with roo-xls and spreadsheet requirements)
Gem that would allow me to simply re-parse the file as an xlsx file and let the latest gems read them from there on.

Take a look at this gem https://github.com/roo-rb/roo-xls.
Taken from README.
This library extends Roo to add support for handling class Excel files, including:
.xls files
.xml files in the SpreadsheetML format (circa 2003)

Related

How do I edit .xslm file in ruby/rails without losing VBA macros?

I have some .xslm files in my project which I have to edit. My application is written in Rails. I know macro enabled files can not be edited with rubyXL or roo gem, somehow I have to edit them using Ruby/Rails gems or any tool which can be incorporated within Rails app. The application is hosted on AWS, does aws have any tool to do the same ? Plus the requirement is the macros be retained.
It turns out it is not possible to edit macro enabled excel sheets (.xlsm) files in Rails. Even though you tweaked the file somehow, MS Office will treat it as a corrupt file.

How to make .cab in ruby with ruby-libmspack gem

I am working on POC to create .cab file (MS compress format) in ruby on rails application. I found this ruby-libmspack that provide bindings to create .cab files. But the gem seriously lacks examples. I did lot of research on google but didnt find any sample code to compress files into .cab archive.
Did anyone knows how to create cab archive using ruby-libmspack gem? Is there any other way to create .cab archive in ruby on rails application?
Not Sure About Ruby-libmspack, but lcab can create CAB files on Linux.

Parse doc and xls files in ruby

In my rails application, I need to upload some doc/xls files and parse its structure and get information. How can I get data from *.doc or *.xls in maybe xml format or anything else that I can read and parse?
You can parse different types of spreadsheets using the Roo gem. It supports:
OpenOffice
Excel
Google spreadsheets
Excelx
LibreOffice
CSV
From my experience it has some issues with parsing .xls files, however parsing .xlsx files is good.
As for .doc files, you may try using msworddoc-extractor gem or try one of the solutions proposed here.
Update: working with *.docx files - docx and docx-html
Have you seen the Nokogiri gem? http://nokogiri.org/
Very useful for xml parsing
The spreadsheet gem is nice for excel and csv files.
https://github.com/zdavatz/spreadsheet

Rubyzip and zipruby for zip/unzip not creating much difference in the compressed zipfile size

i have been using rubyzip for zip/unzip for files/folder ranging from 20MB TO 1GB.i noticed that after zipping a folder of 20MB,the created zipfile is almost of the same size somewhat 20MB.So is rubyzip just zip the file or actually compresses it because the compressed file must be less than 40%-50% of the actual file size.i even tried using system(zip, archive, Dir["#{path}/**/**"]) but i guess i am unable to get the correct syntax to call it.So my questions are
why rubyzip is unable to create an actual zip file which must be less in size too.
for a zipfile of more than 500MB,how van i send it to the client using send_file because its going to cost performance issue for a file of that size.what if i place that zip of 500MB or above in public folder and let the server serve it which might improve the performance,am i correct?
are there any other option instead of using rubyzip/zipruby(which requires libraries too).
I am using ruby 1.9 and rails 2.3.
my code:-
require 'zip/zip'
require 'fileutils'
require 'zip/zipfilesystem'
def self.compress_test(path)
path="#{RAILS_ROOT/answers/}"
path.sub!(%r[/$],'')
archive = File.join(path,File.basename(path))+'.zip'
FileUtils.rm archive, :force=>true
Zip::ZipFile.open(archive, 'w') do |zipfile|
Dir["#{path}/**/**"].reject{|f|f==archive}.each do |file|
begin
zipfile.add(file.sub(path+'/',''),file)
rescue Zip::ZipEntryExistsError
end
end
end
end
why rubyzip is unable to create an actual zip file which must be less in size too.
This varies a lot depending on what files you are trying to compress. Text and xls files will compress reasonably well. Media files in formats like JPEG, PNG, MPEG etc are already compressed internally, and often get compression ratios of 99%. They will usually be bigger that other files in the same folder, so the result of compressing a folder with some images, text and spreadsheets will not seem much smaller. Compressing a .zip file can even make the end result larger than you started.
for a zipfile of more than 500MB,how van i send it to the client using
send_file because its going to cost performance issue for a file of
that size.what if i place that zip of 500MB or above in public folder
and let the server serve it which might improve the performance,am i
correct?
Yes, saving a large file to disk, and letting the web server send it may be more efficient. The easiest thing to do would be to save the file to a folder where it can be served from, and provide a link. You could also make that from a different server (e.g. a lighttpd instance dedicated to serving out the large files) to avoid loading your application server.
There are some setups that allow you to pass control back from a Ruby process to e.g. Apache ( xsendfile is one I know of ), but setting that up would be a different question, it depends what web server you have, and whether you have security concerns.
are there any other option instead of using rubyzip/zipruby(which
requires libraries too).
Probably yes, but it is not likely you will find solutions to your two other questions by changing which gem you are using, because rubyzip is doing a reasonable job here - it is not failing.

Rails: export to .xlsx (Office 2007) spreadsheet

Took over an existing Rails 2.3.x app. Need to export some data to xlsx format(Excel 2007).
Unfortunately I cant use plain XLS format as it has a limit of 256 columns per sheet. The data the app exports goes beyond that limit.
Are there any existing gems/plug-ins that can generate XLSX files?
I have google-ed for answers, but nothing worked so far.
I have tried installing simple_xlsx_writer gem, and did the usual gem.config "simple_xlsx_writer" but it kept complaining that it couldn't find the required gem. (e.g. "Missing these required gems: simple_xlsx_writer "). Which is weird as I have it installed.
Looked at roo gem, but it only has the ability read xlsx files. So not good.
Open to any other suggestions so as long as the data can be opening in Excel.
Thanks in advance.
Have you seen the AXLSX Gem? You may have to require you database adapter manually and build the export by still possible. This can an entire workbook sheets, charts, etc. The only caveat I found is that charts cannot be their own sheet.
https://github.com/randym/axlsx

Resources