我正在尝试在 ruby on rails 中创建一个 excel 表。所以我使用了插件Rexcel。当我运行应用程序时,我收到以下错误。
未初始化的常量 Rexcel::Workbook::Builder
我添加了以下代码,然后出现此错误
workbook = Rexcel::Workbook.new
worksheet = workbook.add_worksheet("Customers")
worksheet.add_line("name","test")
headers['Content-Type'] = "application/vnd.ms-excel"
headers['Content-Disposition'] = 'attachment; filename="excel-export.xlsx"'
headers['Cache-Control'] = 'max-age=0'
headers['pragma']="public"
workbook.build
如何解决这个问题?
最佳答案
我建议使用电子表格而不是 Rexcel,因为它肯定更成熟,而且我在 Rails 3 中使用它没有任何问题。
Here is the documentation.
整个过程将是:
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet :name => 'Customers'
sheet.row(0).concat %w{Name Country Acknowlegement}
book.write '/path/to/output/excel-file.xls'
关于ruby-on-rails - 在rails中生成excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4152366/