> 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
>   http://www.cpearson.com/excel/optimize.htm
> 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:
    <Cell ss:Index="14"
     ss:Formula="=(RC[-11]+R[57]C[-11]+R[114]C[-11]+R[171]C[-11]+R[228]C[-11])/5"><Data
      ss:Type="Number">1.5812633999999999E-2</Data></Cell>
    <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 fool around with 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.

-- 
Posted via http://www.ruby-forum.com/.