有没有办法或示例在rails 2.3.5上导出xls而不使用gems和复杂的东西?
我试图通过我选择的ejectuve_id导出xls条件 我有这个代码
*********It s in my controller********
@search_ejecutive = params[:search_ejecutive].to_i
@search_status = params[:status_id].to_i
@list_ejecutives_comision = Ejecutive.find(:all)
ejecutive_ids = []
obj_user.ejecutives.each do |ejecutive|
@list_ejecutives_comision << Ejecutive.find(ejecutive.id)
end
@list_policies_search = Policy.deleted_is(0)
if params[:search_ejecutive].to_i!=0
@list_policies_search = @list_policies_search.ejecutive_id_is(@search_ejecutive)
end
ejecutive_ids = []
obj_user.ejecutives.each do |ejecutive|
ejecutive_ids << ejecutive.id
end
if !ejecutive_ids.blank?
@list_policies_search = @list_policies_search.ejecutive_id_in(ejecutive_ids)
end
@list_policies_search = @list_policies_search.deleted_is(0)
@list_policies = @list_policies_search.paginate(:page => params[:page], :per_page => 10)
在这里,我显示了我尝试的链接
<% form_remote_tag :url=>{:action=>"generate_print_ejecutive_comercial"},:before=>"load_close('loading_search')",:success=>"load_off('loading_search')" do -%>
<label>Ejecutivo:</label>
<%= select_tag 'search_ejecutive',"<option value=\"\">Seleccione</option>"+options_for_select(@list_ejecutives_comision.collect {|t| [t.name.to_s+" "+t.lastname1.to_s,t.id]})%>
<input name="Buscar" value="Buscar" type="submit" /><span id="loading_search"></span>
<% end %>
<%= link_to("xls","http://localhost:3000/policy_management/policy/generate_print_ejecutive/generate_print_ejecutive.xls")%>
<%= link_to "xls", :controller=>"policy_management/policy",:action=>"generate_print_ejecutive",:format=>"xls" ,:search => params[:search_ejecutive],:page => params[:page] %>
<%= link_to 'Imprimir', :controller=>"policy_management/policy",:action=>"generate_print_ejecutive", :format=>"pdf" %>
<div id="table">
<%= render :partial=>"table2" %>
我的:部分table2是@list_policies的结果 我的老师不想要不透露我的秘密,告诉我诀窍是
@list_policies
我尝试手动导出,我试过这个
@list_policies.find(:all,:conditions=>"ejecutive id = 1")
有人可以帮我这个,我的教导告诉我,我需要输出:search_ejecutive params
我将非常感谢所有帮助
答案 0 :(得分:0)
有一种方法可以用xml表示xls的最新格式,你可以阅读更多关于它的here。
因此,您的控制器可以回复.xls
个请求,然后您可以像这样查看generate_print_executive.xls.erb
:
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet ss:Name="Sheet1">
<Table>
<% @list_policies.each do |policy| %>
<Row>
<Cell>
<Data ss:Type="String"><%= policy.column_data %></Data>
</Cell>
</Row>
<% end %>
</Table>
</Worksheet>
</Workbook>
请注意,这只是一个关于如何在不使用任何gem的情况下生成.xls
的虚拟示例,我无法理解您在帖子中需要的内容,我主要回答帖子的标题: p