Writing formulas to excel spreadsheet

x11 is not an operating system. FreeBSD is not even on that list. If
your gonna link analysis and statistic web at least link one that has
been around since before the bubble.

http://news.netcraft.com/archives/2011/01/05/most-reliable-hosting-company-sites-in-december-2010.html

As for referring to your peers as childish within your remark about M$
hate. Seriously if you don’t know what the problem is at this point
you really should reevaluate some of this cognitive dissonance so you
wont be spewing bullshit like over 90% computer in the whole world run
x,y,z OS.

On Tue, May 24, 2011 at 06:38:19AM +0900, Mike S. wrote:

Chad P. wrote in post #1000266:

but it is not vital to explain to some
Microsoft obsessed shitbird why you are using Ruby to interact with an
XLS file rather than doing it “by hand” in Excel.

The trouble with you Chad is you always manage to miss the point.

That’s funny, considering you have, apparently, completely missed the
point of the original query in favor of criticizing someone’s need for a
solution to the problem of programmatically generating spreadsheet
formulae in Ruby rather than just using Excel.

No-one on this thread has mentioned doing it by hand. The issue was
whether or not to use Windows OLE rather than a Linux environment, given
that the end-product is for Windows users, and that it is does what Will
wants - unlike his Linux solution.

I’m not sure you’re reading all that closely:

Why fanny around with some Micky Mouse spreadsheet gem when you
can have the Full Monty?

Even if he had it installed locally, I’m guessing that he would want
to generate the document in code since generating it by hand would be
cumbersome. In addition, the spreadsheet gem works on any platform
(last I checked).

Of course, I didn’t read back too far in the thread – because I didn’t
keep an archive of the entire thread before that point. It’s possible I
lost some reference to a subject that made it clear Daniel’s discussion
of “generating it by hand” was in error, but I think it’s at least as
possible you’re just full of it, given your attitude.

I’m not Microsoft obsessed. The simple fact is it is the Linga Franca
of the computing world. Linux is only on a tiny minority of desktops.
So it’s natural to question why someone would choose to go down a such
a route when Windows is what most other people would be using.

It’s not “natural” to criticize someone for writing software that allows
people to accomplish things on their OSes of choice. Try to avoid
trolling by criticizing people’s platform choices in circumstances like
this, and you won’t have people pointing out that you sound like you’re
obsessed with microsoft.

Will has said his colleagues just happen to be avid Linux fans so
that’s fair enough. That answers the question.

You didn’t have a question. You had non-constructive criticism. Try
reading what you type after you’re done typing it before sending it,
unless your actual goal is to be an abrasive asshole. The latter seems
likely, given the fact that I frankly don’t even know who you are, but
you clearly chose to treat me like some kind of mortal enemy.

I know on this channel I will get the anti-Microsoft lobby. Fortunately
I don’t get it at work.

If you didn’t come off as anti-anything-but-Microsoft with some of your
responses, you probably wouldn’t get “anti-Microsoft” responses. Of
course, my response was not “anti-Microsoft”: it simply treated your
response as unreasonably demanding that people buy software they don’t
want.

Professional programmers grudgingly accept that .NET has bugs and the
usual MS baggage but probably is a better bet than say Java for
mainstream e-business. Sadly people rarely have an opinion on Ruby.

I’ve fed the troll enough already. I’ll just stop there.

On Sat, May 21, 2011 at 3:28 AM, Will J. [email protected] wrote:

cumbersome.

Yep, that’s correct - I want the scripts to work across a variety of
platforms, with as little dependence on outside applications and
libraries as possible. This is partly because the scripts I’m writing
may be used by a few others; I don’t know about what software they will
or won’t have on their systems, and they will likely not be too willing
to resolve too many dependency issues. I do have office installed on one
of my systems, but don’t have access to that one right now, and will not
buy another copy just for this task.

There are other use cases for what you want to do, which is why I’m
interested in any problems you come across and any ways you solve
them. For example: I distrust spreadsheets for making important
calculations (too easy to make errors in obscure cells without
noticing), but they are very useful for displaying data. So I make
some calculations using Ruby (or whatever), and then display the
results on a worksheet page, using formulas to generate some of the
displayed results for the same reasons you give in a later post “it’s
good to have the formulas in there, in part so that whoever is viewing
the formulas can follow the process of
how something is derived (without too much effort)”. An important part
of what I’m doing is that the worksheets will be usable in even quite
old versions of Excel, so I only want to use elementary features of
Excel.

Actually, the original version of this used Microsoft Excel
VisualBasic for Applications, with all the calculations being done in
VBA, and using VBA to generate the worksheet pages. But I’d rather use
Ruby for the calculations, so I’m currently rewriting it, hence my
interest in what you’re doing.

I’m assuming you’ve looked at things like this
Optimize VBA
which has a section on using VBA to force calculations: I haven’t
tried adapting the VBA code to run from Ruby accessing Excel, but it
should be possible?

As a very orthogonal suggestion: one thing that was worrying me about
my approach was what if I couldn’t manage to get Ruby to write
anything directly into Excel. (You haven’t got that problem.) But a
possible solution occurred to me: use Ruby (or whatever) to generate a
text file which has a list of cells and values or formulas (and
formatting) to be entered into (or used by) each cell. Then write a
VBA function to read such text files and generate the worksheet(s): a
little messy, but fairly easy to do, and I was much happier once I had
a backup plan if directly accessing Excel through Ruby didn’t work.

Colin B. wrote in post #1000942:

So I make
some calculations using Ruby (or whatever), and then display the
results on a worksheet page, using formulas to generate some of the
displayed results for the same reasons you give in a later post “it’s
good to have the formulas in there, in part so that whoever is viewing
the formulas can follow the process of
how something is derived (without too much effort)”.

You are using formulae. Will wanted to change the formulae. (Apologies,
Will, if I came across as criticising you - that wasn’t intended. I
fully
understand your problem constraints, which were not evident to start
with).

I’m curious to know why Will would change formulae. If parameters are
changing then he could factor those out as values passed in ( a bit like
your text file approach). If the data structures are changing
(eg variable range sizes) he could let Excel sort that out at run time.
Maybe you could tell us more, Will?

As regards to VBA, personally - for purity - I would aim to avoid it as
it shouldn’t add any functionality you couldn’t achieve by using a
combination of Ruby and Excel. To avoid being flamed yet again, I do
appreciate that this assumes you are running Ruby in the presence of
Windows and Excel. If you want to create an Excel sheet on a non-Windows
platform, your options are reduced.

On Wed, May 25, 2011 at 03:22:41AM +0900, Johnny M. wrote:

Do you do parties?
He’s probably too busy doing bridges.

Actually, the original version of this used Microsoft Excel
VisualBasic for Applications, with all the calculations being done in
VBA, and using VBA to generate the worksheet pages. But I’d rather use
Ruby for the calculations, so I’m currently rewriting it, hence my
interest in what you’re doing.

I’m assuming you’ve looked at things like this
Optimize VBA
which has a section on using VBA to force calculations: I haven’t
tried adapting the VBA code to run from Ruby accessing Excel, but it
should be possible?

As a very orthogonal suggestion: one thing that was worrying me about
my approach was what if I couldn’t manage to get Ruby to write
anything directly into Excel. (You haven’t got that problem.) But a
possible solution occurred to me: use Ruby (or whatever) to generate a
text file which has a list of cells and values or formulas (and
formatting) to be entered into (or used by) each cell. Then write a
VBA function to read such text files and generate the worksheet(s): a
little messy, but fairly easy to do, and I was much happier once I had
a backup plan if directly accessing Excel through Ruby didn’t work.

Thanks for the good tips and suggestions, Colin. I’ve never really
looked at VB, and like yourself, would rather stick with ruby, but will
take a look at the method to which you pointed in the link. I guess that
if the VB script forces an after-the-fact evaluation, one dirty solution
would be to have the ruby script (after it has done its part) call the
VB script just to force calculations, but not knowing anything about VB,
I’m not sure about what sort of new issues this would introduce, aside
from having to have some sort of vb interpreter.

I’ve compared the excel xml for evaluated vs. non-evaluated cells, and
it appears that the spreadsheet gem writes whatever strings you tell it
to write (and the cell is tagged accordingly), whereas excel formulas
have a particular format, such as:
1.5812633999999999E-2
<Cell
which may take a while to implement if one were to, for example, dig
into the underlying module and try to add formula functionality. I don’t
think I can attempt this particular approach, because it risks
dedicating too much time to the tools used to solve the primary problem,
and cuts into the time allocated to the problem.

I’m glad to hear you’re working on a ruby solution to this issue, and
hope you let us know when you’ve got it ready. It’s kind of funny - as I
said earlier, I’ve never used ruby prior to this task, but I’m starting
to get into it to the point that I may end up using it quite a bit. But
I guess at this point, this particular issue has become one of
intellectual curiousity more than necessity.

I’m curious to know why Will would change formulae. If parameters are
changing then he could factor those out as values passed in ( a bit like
your text file approach). If the data structures are changing
(eg variable range sizes) he could let Excel sort that out at run time.
Maybe you could tell us more, Will?

No prob - the task at hand doesn’t involve changing formulas, but
dynamically generating them. Specifically, I’m reading in large,
cumbersome text files of output from another program, putting the data
into excel (in a more human-readable format), and dynamically generating
formulas in accordance with the nature of the input, and in an ideal
scenario, those formulas would have been evaluated automatically.

On Thu, May 26, 2011 at 03:53:48AM +0900, Will J. wrote:

Thanks for the good tips and suggestions, Colin. I’ve never really
looked at VB, and like yourself, would rather stick with ruby, but will
take a look at the method to which you pointed in the link. I guess that
if the VB script forces an after-the-fact evaluation, one dirty solution
would be to have the ruby script (after it has done its part) call the
VB script just to force calculations, but not knowing anything about VB,
I’m not sure about what sort of new issues this would introduce, aside
from having to have some sort of vb interpreter.

Note that the reference was to VBA, which is not strictly the same as
VB. Knowing the difference between Visual Basic (or Visual Basic .NET)
and Visual Basic for Applications might help you navigate through search
results to find relevant information.

Both of them are different from VBScript, in case it matters.

Chad P. wrote in post #1001016:

Note that the reference was to VBA, which is not strictly the same as
VB. Knowing the difference between Visual Basic (or Visual Basic .NET)
and Visual Basic for Applications might help you navigate through search
results to find relevant information.

Both of them are different from VBScript, in case it matters.

Thanks, Chad!

Will J. wrote in post #999695:

Hi, everyone. I’ve just started using ruby a couple of days ago, and
I’ve been using it to read data from text files and write to excel
spreadsheets. I also need to be able to write formulas to spreadsheets,
but when I open the excel file, the formula is in there without having
been evaluated - for example, the cell will appear as “=A1+A58+A114”
instead of whatever the value of that sum happens to be. If I click on
the cell and hit “enter,” the formula will evaluate, but it does not do
so automatically.

Is there any way to get ruby to force excel to evaluate? Thanks!

I created this gem libexcel | RubyGems.org | your community gem host

Our spreadsheet is about 3.3mb and about 10 worksheets.

Here is the lib that we use to generate our excel files using my gem.
https://github.com/osuclse/scarlet/blob/master/lib/survey_excel_report.rb

If you are using rails then the controller then this controller will
help you setup the correct encoding for downloading
https://github.com/osuclse/scarlet/blob/master/app/controllers/survey_controller.rb#L142

Honestly this isn’t the best way to do things, but it worked for us.

I actually came here looking for a solution to using spreadsheet for
formula because I wanna get rid of the dependency on libxml.