1
JavaScript를 사용하여 계산 스크립트를 작성했으며 그 결과를 XLS 파일로 내보내려고합니다. 입력 텍스트 결과를 레일스의 XLS 파일로 내보내려면 어떻게해야합니까?
이
내 코드입니다 :****************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);
}
});
그리고 이것은 내보기입니다 : 내 결과를 내보낼
def index
@search = CustomerReport.search(params[:search])
@customer_reports = @search.paginate(:page => params[:page], :per_page =>10)
@results = CustomerReport.search(params[:search])
@soles=CustomerReport.search(params[:search]).find(:all ,:conditions=>"mount_type = '0'").sum(&:mount)
@dolares=CustomerReport.search(params[:search]).find(:all ,:conditions=>"mount_type = '1'").sum(&:mount)
respond_to do |format|
format.html
format.csv { render :csv => "reporte_csv",:partial =>"csv" }
format.xls { render :xls => "reporte_xls",:partial =>"xls" }
end
end
:
<div>
<table border="1" class="calculator">
<tr>
<th>COSTO DEL DOLAR</th>
<th>SUMA DE SOLES</th>
<th>SUMA DE SOLES A DOLARES</th>
<th>SUMA DE DOLARES</th>
</tr>
<tr class="conversion">
<td> <input id="cambio" name="cambio" class="val1" maxlength ="5"/></td>
<td>S/<input id="partial" name="partial" class="val2" readonly="readonly" value="<%= @soles %>"/></td>
<td>$ <span class="soles" value="<%= @multi.to_i %>"></span></td>
<td>$ <input name="dolares" class="val3" readonly="readonly" value="<%= @dolares.to_i %>"/></td>
</tr>
<tr>
<td colspan="4" align="center">MONTO TOTAL EN DOLARES: $ <span id="total"> 0.00 </span></td>
</tr>
</table>
</div>
<%= link_to image_tag("/images/excel.png",:size => "18x18"),{
:controller=>"customer_reports",:action=>"excel",:format=>"xls" ,:search => params[:search]} %>
가 여기 내 컨트롤러입니다. 이것을 할 다른 방법이 있습니까?
감사합니다. 좋은 답변이지만 어떻게 할 수 있습니까? 나는 자바 스크립트 결과를 내보낼 수 없다는 것을 알았지 만 어떻게 해결할 수 있습니까? 코드가 있습니까? 또는 가이드? –
일부 코드 또는 안내서? 이것은 단순한 단일 코드 라인이 아닙니다. Rails에서 양식의 출력을받는 방법을 모르십니까? 그렇다면 레일스가하는 일의 아주 기본적인 부분이다. 또는 XLS 파일을 만드는 방법을 모르십니까? 루비는 그렇게 할 수있는 많은 보석을 가지고 있습니다. Google이나 보석 저장소 중 하나를 사용하여 검색하면 도움이 될 것입니다. 그 보석을 사용하는 방법은 모두 다르기 때문에 자체 문서로 다루어 질 것입니다. –