大家用什么做导出啊?
ruby吧
全部回复
仅看楼主
level 7
a245830777 楼主
在网上看到3中 1.act_as_xlsx 2.csv 3.axlsx
听说act家族很强大,但是在网上找了些demo,demo都是比较老的 ,最早的是3年前,不知道是因为版本原因还是怎么回事,程序运行到.to_xlsx就报错
2014年07月31日 01点07分 1
level 7
a245830777 楼主
贴出错误了:ActiveRecord::RecordNotFound at /dashboard/admins/export.xlsx
Couldn*t find all Admins with *id*: (all, {}) (found 0 results, but was looking for 2)
2014年07月31日 01点07分 2
level 7
a245830777 楼主
binding.pry发现
[1] pry(#<Dashboard::AdminsController>)> @admins.to_xlsx
Admin Load (1.0ms) SELECT `admins`.* FROM `admins` WHERE `admins`.`id` IN (*all*, *--- {}\n*) ORDER BY `admins`.`created_at` DESC LIMIT 10 OFFSET 0
ActiveRecord::RecordNotFound: Couldn*t find all Admins with *id*: (all, {}) (found 0 results, but was looking for 2)
from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.1/lib/active_record/relation/finder_methods.rb:320:in `raise_record_not_found_exception!
在执行这个查询方法时报错了。。
2014年07月31日 02点07分 3
level 7
a245830777 楼主
然后找到了to_xlsx的源码:
def to_xlsx(options = {})
if self.xlsx_columns.nil?
self.xlsx_columns = self.column_names.map { |c| c = c.to_sym }
end
row_style = options.delete(:style)
header_style = options.delete(:header_style) || row_style
types = [options.delete(:types) || []].flatten
i18n = options.delete(:i18n) || self.xlsx_i18n
columns = options.delete(:columns) || self.xlsx_columns
p = options.delete(:package) || Package.new
row_style = p.workbook.styles.add_style(row_style) unless row_style.nil?
header_style = p.workbook.styles.add_style(header_style) unless header_style.nil?
i18n = self.xlsx_i18n == true ? *activerecord.attributes* : i18n
sheet_name = options.delete(:name) || (i18n ? I18n.t("
#{i18n}.#
{table_name.underscore}") : table_name.humanize)
data = options.delete(:data) || [*find(:all, options)]
data.compact!
data.flatten!
return p if data.empty?
p.workbook.add_worksheet(:name=>sheet_name) do |sheet|
col_labels = if i18n
columns.map { |c| I18n.t("
#{i18n}.#
{self.name.underscore}.#{c}") }
else
columns.map { |c| c.to_s.humanize }
end
sheet.add_row col_labels, :style=>header_style
data.each do |r|
row_data = columns.map do |c|
if c.to_s =~ /\./
v = r; c.to_s.split(*.*).each { |method| v = v.send(method) }; v
else
r.send(c)
end
end
sheet.add_row row_data, :style=>row_style, :types=>types
end
end
p
end
end
end
2014年07月31日 02点07分 4
level 7
a245830777 楼主
也就是说执行到data = options.delete(:data) || [*find(:all, options)]的时候出错,请问我应该如何解决?
2014年07月31日 02点07分 6
1