0

我第一次使用 axlsx,不确定它的功能是什么。我正在尝试将我的 watir 结果写入 Excel 表。我发现 axlsx 很有趣,所以我正在尝试使用它。我被困在一个点上,无法前进。我希望我能从这里得到帮助,

我的情况是我的 excel 表中的每一列都需要一个标题,从第二行开始,我的结果每次都在新行中追加,到目前为止我已经尝试了下面的代码,

     p = Axlsx::Package.new
     p.workbook.add_worksheet(:name => "firefox") do |sheet|
       sheet.add_row ["url", "projectname", "scenarioname","value","execution time"],:b=>true
       sheet.add_row ["#{$url}","#{dirname}","#{scenario_name}","Pass","#{Time.now}"]
     end
     p.serialize('../../Results'+day+'.xlsx')

提前致谢。

4

1 回答 1

0

我不知道你的流程是什么,所以这是粗略的代码。如果您需要遍历记录,请在内部循环add_worksheet

p = Axlsx::Package.new
p.workbook.add_worksheet(:name => "firefox") do |sheet|
  sheet.add_row ["url", "projectname", "scenarioname","value","execution time"],:b=>true
  run_process = true
  while run_process
    # do something, set run_process = false when done
    sheet.add_row ["#{$url}","#{dirname}","#{scenario_name}","Pass","#{Time.now}"]
  end
end
p.serialize('../../Results'+day+'.xlsx')

或者,在外面访问工作表:

p = Axlsx::Package.new
sheet = p.workbook.add_worksheet(:name => "firefox") do |sheet|
  sheet.add_row ["url", "projectname", "scenarioname","value","execution time"],:b=>true
end
while (run process that returns true)
  sheet.add_row ["#{$url}","#{dirname}","#{scenario_name}","Pass","#{Time.now}"]
end
p.serialize('../../Results'+day+'.xlsx')

这能回答你的问题吗?

于 2014-08-06T14:34:48.470 回答