Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I export input text results to an XLS file in Rails?
    text
    copied!<p>I wrote a calculation script using JavaScript and I want to export that result to an XLS file.</p> <p>This is my code:</p> <pre><code>****************THIS IS MY SCRIPT******** **********PROJECT/PUBLIC/JAVASCRIPT/calculator.js $(document).ready(function () { $(".conversion input").keyup(multInputs); function multInputs() { var mult = 0; // for each row: $("tr.conversion").each(function () { // get the values from this row: var $val1 = $('.val1', this).val(); var $val2 = $('.val2', this).val(); var $val3 = $('.val3', this).val(); var $subtotal = ($val1 * 1) * ($val2 * 1) $('.soles',this).text($subtotal); mult = ($subtotal*1) +($val3 * 1); }); $("#total").text(mult); } }); </code></pre> <p>And this is my view:</p> <pre><code> &lt;div&gt; &lt;table border="1" class="calculator"&gt; &lt;tr&gt; &lt;th&gt;COSTO DEL DOLAR&lt;/th&gt; &lt;th&gt;SUMA DE SOLES&lt;/th&gt; &lt;th&gt;SUMA DE SOLES A DOLARES&lt;/th&gt; &lt;th&gt;SUMA DE DOLARES&lt;/th&gt; &lt;/tr&gt; &lt;tr class="conversion"&gt; &lt;td&gt; &lt;input id="cambio" name="cambio" class="val1" maxlength ="5"/&gt;&lt;/td&gt; &lt;td&gt;S/&lt;input id="partial" name="partial" class="val2" readonly="readonly" value="&lt;%= @soles %&gt;"/&gt;&lt;/td&gt; &lt;td&gt;$ &lt;span class="soles" value="&lt;%= @multi.to_i %&gt;"&gt;&lt;/span&gt;&lt;/td&gt; &lt;td&gt;$ &lt;input name="dolares" class="val3" readonly="readonly" value="&lt;%= @dolares.to_i %&gt;"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="4" align="center"&gt;MONTO TOTAL EN DOLARES: $ &lt;span id="total"&gt; 0.00 &lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;%= link_to image_tag("/images/excel.png",:size =&gt; "18x18"),{ :controller=&gt;"customer_reports",:action=&gt;"excel",:format=&gt;"xls" ,:search =&gt; params[:search]} %&gt; </code></pre> <p>Here is my controller:</p> <pre><code>def index @search = CustomerReport.search(params[:search]) @customer_reports = @search.paginate( :page =&gt; params[:page], :per_page =&gt;10) @results = CustomerReport.search(params[:search]) @soles=CustomerReport.search(params[:search]).find(:all ,:conditions=&gt;"mount_type = '0'").sum(&amp;:mount) @dolares=CustomerReport.search(params[:search]).find(:all ,:conditions=&gt;"mount_type = '1'").sum(&amp;:mount) respond_to do |format| format.html format.csv { render :csv =&gt; "reporte_csv",:partial =&gt;"csv" } format.xls { render :xls =&gt; "reporte_xls",:partial =&gt;"xls" } end end </code></pre> <p>I want to export my results. Is there other way to do this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload