1

I have tried different gems in ruby and also searched a lot but Ruby doesnt seem to have a solution to write to existing excel file.

my excel file 'services.xls' has 3 columns

  1. 1st column name is 'inputxlm'
  2. 2nd column name is 'methodtoexecute'
  3. 3rd column name is 'output'

i have internal logic which takes the inputxlm, process it using the method and generates output

How do i write back the output to output column in 'services.xls' ?

Note : I dont want to use win32ole as my organization has some limitation on it

testerBDD
  • 255
  • 3
  • 18
  • Hey, I used to work with xls long time ago. and I remember `roo ` was pretty helpful to work with existing excel files. Have you tried it out? https://github.com/roo-rb/roo – amrdruid Sep 03 '18 at 16:47
  • roo is readonly cannot be used to write back to excel – testerBDD Sep 03 '18 at 16:51
  • Did you try xlsx writer? https://github.com/seamusabshere/xlsx_writer/ – amrdruid Sep 04 '18 at 08:34
  • @amrdruid does it support writing to existing excel, did searched but didnt find a solution – testerBDD Sep 04 '18 at 11:09
  • In the past i had problems to generate xls from ruby. When your excel is easy (and your 3 columns look so), then I would read the data (via sequel/ACE.OLEDB, maybe you must install AccessDatabaseEngine_x64.exe ) and recreate an excel with axlsx (but then it is a xlsx). If this is a possible solution, give me a feedback. – knut Sep 04 '18 at 14:24
  • I think the `spreadsheet` gem might be your only hope (note it does not account for cell styling at all). The main problem with `xls` is that it was a windows proprietary binary format making it far more difficult to build the document itself. Now that (as of office 2007) windows has the `xlsx` format which is a reasonable adoption of the Open Document Format (essential a zip of XML files) this portability (cross platform) and ease of generation has essentially orphaned the `xls` format and for good reason. – engineersmnky Sep 04 '18 at 15:20

1 Answers1

1

This article is a great source to find out which library suits you best: https://spin.atomicobject.com/2017/03/22/parsing-excel-files-ruby/

My company uses axlsx combined with axlsx_rails to render xls files with Rails rendering machine and axlsx_styler for styling.

Note that in a simple use case like the one you describe, you night not need an excel file like xls, a mere CSV would suffice, and for that, Ruby has CSV

Matthieu Libeer
  • 2,286
  • 1
  • 12
  • 16
  • How do you create xls-files with axlsx? (no xlsx, really a xls) . If you found a solution, can you post it on https://stackoverflow.com/questions/24146095/generating-xls-file-using-axlsx ? Thanks. – knut Sep 04 '18 at 21:19