From: Will James Date: 2011-05-26T03:53:48+09:00 Subject: Re: Matz never said Microsoft was the Devil Incarnate. (or did he?) > 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: 1.5812633999999999E-2 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/.