How to create a spreadsheet with formulas using Rails? - ruby

I need some gem/plugin to create an Excel spreadsheet with formulas to use in my Rails application. Any suggestions?

I've used Roo and it's quite good and easy to do spreadsheet processing (once you get all the gem dependencies installed). However, it doesn't support formulas natively. It won't eval the formula and return the result (this would be difficult I think -- use the excel engine?) but it will give you the text of the formula, for example:
=SUM(.A1,.B1)
It'd be pretty easy to handle this specific case but if you have many different formulas and functions then rolling your own evaluator is going to be difficult. Going and getting A1 and B1 to add them together is very doable with Roo. It's just a question of how complex your formulas are.

writeexcel does it wonderfully!

I think you should create blank Excel file with formulas and then fill it with Rails. Because you can't create formulas with Ruby.

There's a spreadsheet gem listed on RubyGems but having never used it I can't recommend it.

Related

I want to edit a wellformatted excel file with ruby

I have a wellformatted excel file with a lot of macros and styling in it that I want to keep.
Then i have this information I want to enter in the file.
And I want to do it with ruby.
I've tried roo and spreadsheet but they don't seem able to actually edit the file, just create a new one and loosing all the formattin in the process.
It feels it should be simple to just edit the cells I want and save the file again but obviously it's more complex that I originally though(or I'm completely blind)
Any help is appreciated.
I'm learning ruby at the moment so that's why I would prefer a solution in ruby.
If you know there are better suited laguages for this feel free to point me in the right direction and I'll check it out.
Thanks in advance
Speaking from experience, there is no Ruby gem that would handle Excel files with all bells, whistles, macros and styling. It is a pity, because Excel is squarely the finest of Microsoft products. In my experience, spreadsheet library can import legacy data from Excel, LibreOffice Calc etc. (I'm not sure about Gnumeric).
As for your problem of getting data from Ruby to Excel, I suggest that you first save Ruby output as a separate file (spreadsheet, CSV, text...) and then teach Excel to import it (eg. using macros).
Another possibility is to abandon Excel for data processing tasks (and possibly keep it for data presentation tasks). Excel is great for presentation and simple data processing, but very bad for complex algorithms.
I wrote gems yzz and y_nelson, which I intended as Ruby replacement for spreadsheets. Yzz provides Ted Nelson's ZZ structures in Ruby (ZZ structure is an improved version of spreadsheet data structure) and y_nelson mixes it with Petri nets (because Petri nets are an improved version of Excel cell functions). Mathematically speaking, a spreadsheed is a hybrid between some sort of multidimensional orthogonal grid of data cells plus a Petri net execution engine. With y_nelson, I hope to bring dearly missed Excel functionality into Ruby, while at the same time moving one step towards better abstraction.

How to store and find records based on location?

I'm thinking of building an application that helps you find local businesses (just an example). You might enter your zip code (or GPS if this is on a phone) and find the closest business within 10 miles, etc. My question is how can I achieve this type of logic? Is there a library or service that I will need to use? Or can this be done with math? I'm not familiar with how this sort of thing usually works, so let me know how I need to store the records so I can query them later. Note: I will be using Ruby and MongoDB.
It should be easy to find the math to solve that, providing lat/long coordinates.
Or you could use some full featured gem to do that for you like Geocoder, that supports Mongoid or MongoMapper.
Next time you need some feature that might be a commun world problem, first check if there is a gem for that at ruby-toolbox, for this case here are some other gems for geocoding
One more solution here...
http://geokit.rubyforge.org/
I think, this topic is already discussed here..

What is a good approach for extracting keywords from user-submitted text?

I'm building a site that allows users to make sense of a debate by graphically representing arguments for and against a particular issue. (Wrangl)
I'd like to categorise these debates so they are more easily found and connected. I don't want to irritate the person creating the debate by asking them to add tags and categories before they see any benefit, so I'm looking at a way of automatically extracting keywords.
What's a good approach for taking the debate's title and description (and possibly the content of the arguments themselves once there are some) to pull out, say, ten strong keywords that could be used as metadata to connect similar debates together, or even as the content of the "meta" keywords tag in the head of the HTML page where the debate is viewable. Eg. Datamapper vs ActiveRecord
The site is coded in Ruby with Sinatra, using DataMapper for data storage. I'm ideally looking for something which will work on Heroku (I don't have a way of writing files to disk dynamically), and I'd consider a web service, an API or ideally a Ruby gem.
Maybe you can use TextAnalyzer.
I understand that you're wanting to find an easy way of achieving this, I've recently dived into the world of NLP (Natural Language Processing) and Text-mining and its a daunting process of which most went far above my head.
Although i managed to code some functionality that resembles what you're looking for, though I did it in PHP. What i would suggest, that if you want it tailored to your project (Wrangl) then do it yourself.
Using the Porter stemming algorithm which I'm sure there will be Ruby code for.
Ruby Porter stemmer
You can try the salsaAPI to automatically extract keywords and categorize the debates!

how do i create charts from a cvs file using ruby

csv sample:
Date,128,440,1024,Mixed
6/30/2010,342,-0.26%,-0.91%,1.51%,-0.97%
6/24/2010,0.23%,0.50%,-1.34%,0.67%
i want to render this data in a multi-line graph
Well, you first need to parse the CSV. I suggest FasterCSV - the RDoc explains pretty much everything you need to know.
You'll need to have ImageMagick and RMagick installed, then you can use Gruff. Or if you've got an Internet connection on the machine you are running the script on, you can use Google Charts with this Ruby plugin. Or if you want to get back SVG, consider Scruffy.
The page about Gruff has a code sample showing how to create a multi-line graph. Basically, you need to collect together all the data you want in each line into an array. Looks basically like the primary thing you need to do is array mangling.

Pulling stats out of a text

I'd like to know what are the most recurrent in a given text or group of text (pulled from a database) in ruby.
Does anyone know what are the best practices?
You might start with statistical natural language processing. Also, you may be able to leverage one or more of the libraries mentioned on the AI Ruby Plugins page.

Resources