我第一次使用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')
提前致谢。
答案 0 :(得分: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')
这会回答你的问题吗?