Reading and write on the same excel file with ruby - ruby

I'm looking for a way to reading and writing on same excel file in ruby. I saw a this topic but the suggestions doesn't work for me.
I tried to use Roo gem, but this not allow to write. I tried to use the Spreadsheet gem too, but this doesn't read Xlsx files.
Is there a way to reading and write on same excel file in ruby?

try rubyXL
Ruby lib for reading/writing/modifying .xlsx and .xlsm files

Related

Ruby - Write Data to Existing .xlsx Document

I have an existing xlsx file that I am trying to write data to programatically. Is there any modern solution to this for ruby? Also looked into the Google Sheets API but it's only Java and .Net.
I've searched quite a bit, and so far have checked out the following gems with no luck:
https://github.com/roo-rb/roo
https://github.com/randym/axlsx
https://github.com/weshatheleopard/rubyXL
https://github.com/cxn03651/write_xlsx
In the meantime it seems my best solution is to write to CSV, then import the CSV into the xlsx file. But it's tough to do that programmatically in the future.
Any help would be appreciated, thanks.

How to read from and write to the same EXCEL file using Ruby?

I want to read from and write to the same EXCEL file (file.xls) using Ruby. I tried to use Roo gem which doesn't allow to write to the file. Now I am using Spreadsheet gem, but I can't update existing data in the same excel file.
Is it possible to read from and write to the same EXCEL file without change in macros using Ruby?
Here's a similar post that received an answer: I want to edit a wellformatted excel file with ruby
Basically, you may want to check out win32ole: http://davidsulc.com/blog/2011/03/27/using-ruby-and-win32ole-to-manipulate-excel/
I was unable to make Roo read and write from the same file. This could be due to the fact that Roo creates a temporary file before it writes. Writing to a new file is cleaner, easier and supported. I have the data that I want to read from in my project under db/data/import, then I write to db/data/export and everything got way easier once I went with this approach.

How to create a Ruby executable using ocra or rubyscript2exe gems but including needed Excel files?

I have a dozen of selenium webdriver scripts written in Ruby and I have used both rubyscript2exe and ocra gems in an attempt to end up with a 'bundled' executable but to no avail. Problem is, my scripts are grabbing test data from Excel files; and this is causing havoc when trying to create the executable.
It works fine on the machine which has the original excel file but when taken home away from its native path it 'll just refuse to run. Do I need to declare my paths in my code in a relative way and not explicitly? Is there a command in Ruby like 'require' but for an Excel file for example?
I will be grateful if anyone knows a way to make a ruby executable (or even an installer/application builder) which will somehow include the Excel files running in parallel with the script.
* Resolved *
Admins you can close this one if you want.
It was pretty simple but couldn't figure it out on the first place. If you want to included additional non ruby files in your final executable you can use the line below..:
ocra yourscript.rb test.xls docs\documentantion.doc excel\additional.xls
Once you package an exe using Ocra the files are locked inside it, and if they're intended to be immutable you may as well store the data in the script and write it out directly from there. If you absolutely can't do it without an excel file you'd might also consider creating one via the script.
If you're using an external excel file which is distributed with the exe, then you'd be best off referencing the excel file's path relative to the script (Dir.pwd). Also, wouldn't it be more efficient to gather the data from a delimited text file rather than excel?

Ruby GEM for File and Directory manipulation

i'm looking for gem(s) which will provide me tools for File and Directory manipulation.
Basicly i would like to get possibility to:
search file in provided directory
search pattern inside file (different extensions)
insert into file at precise place content
I know how to do it using Ruby, but it would be nice to get such gem :)
Thanks
Anwser is NO, there isn't one.

convert Excel to csv either using shell script or jython . if so how

I am looking for a procedure where i can convert the excel to csv either if there some shell script , if so please guide me or if possbile how can i do in jython.
The main reason is that the excel is being received from other source and the header is always changing , which is unnecessary and we need to have some automatic way to remove that . If is it possible to do that easily using jython or shell script and remove only the first line of the excel
Thanks in advance.
To convert between various file formats I use: PyODConverter. There is Python and Java version.
It uses OpenOffice working as a service and can convert between various document formats including MS Office, PDF and text.
There is also pure Python library: xlrd Library for developers to extract data from Microsoft Excel (tm) spreadsheet files

Resources