On Thu, Feb 16, 2012 at 4:12 PM, Chris Adams <span dir="ltr"><<a href="mailto:mail@chrisadams.me.uk">mail@chrisadams.me.uk</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi all,<br>
<br>
I'm curious about how one might go about generating a downloadable<br>
spreadsheet for Excel or Openoffice, where formulae inside it are<br>
generated server side, depending on what a user has requested<br>
beforehand in a Rails 3 app.<br>
<br></blockquote><div><br>I don't know about Excel, but if you're willing to educate the recipient a little, Openoffice (and Libreoffice) will accept formulae in CSV files if you untick "Quoted fields as text" in the import dialog. I realise this doesn't answer the question as posed, but for a limited/internal audience it might do the trick<br>
<br>If you have a table with formulae on each row that depend on other columns in that row, you'll either have to track the row numbers yourself or use relative references - e.g.<br><br>require 'csv'<br># rows is some data<br>
CSV.open(ARGV[0],"w") do |csv|<br> csv << rows[0].keys<br> rows.each do |r|<br> r[:owing]='=INDIRECT("R[0]C[-2]",0)-INDIRECT("R[0]C[-1]",0)'<br> r[:value]='=(INDIRECT("R[0]C[-5]",0)+INDIRECT("R[0]C[-4]",0))*INDIRECT("R[0]C[-1]",0)'<br>
csv << r.values<br> end<br>end<br><br><br>-dan<br><br></div></div>-- <br><a href="mailto:dan@telent.net" target="_blank">dan@telent.net</a> <br><a href="http://ww.telent.net" target="_blank">http://ww.telent.net</a><br>
<br>