无法将图表添加到Excel工作簿

时间:2016-03-21 16:13:30

标签: ruby excel charts rubygems

我正在使用IF EXISTS (SELECT 1 FROM Users WHERE Reference='USR00000007') SELECT * FROM Users WHERE Reference='USR00000007' ELSE SELECT * FROM Staff WHERE Reference='USR00000007'; gem。

以下是我的代码段:

writeexcel

我收到以下错误:

  

nil的未定义方法`new':NilClass(NoMethodError)

完整错误:

workbook = WriteExcel.new("graphTest.xls")

worksheet = workbook.add_worksheet(sheetname = "Test")

chart = workbook.add_chart(
  :type => "Chart::column",
  :name => "Chart",
  :embedded => 1
  )

如果我直接从找到here的gem文档中获取示例,为什么会收到此错误消息?

1 个答案:

答案 0 :(得分:0)

The," Gotcha,"在您的代码段中找到columnChart::column的大写:

chart = workbook.add_chart(
  :type => "Chart::Column", #capitalized
  :name => "Chart",
  :embedded => 1
  )

而不是

chart = workbook.add_chart(
  :type => "Chart::column", #all lowercase
  :name => "Chart",
  :embedded => 1
  )