# -*-coding:utf-8 -*-
#author:kanlijun
require 'win32ole'
require 'fileutils'
class ResultAnalyse
@@i=0
@@f=0
def initialize path
excel =WIN32OLE.new('excel.application')
@workbook =excel.WorkBooks.open(path)
@worksheet=@workbook.Worksheets(1)
end #获取excel第一行第一列的标题文本
def get_title
@worksheet.Range("a1").Value
end def get_receive
@worksheet.Range("i3").Value
end #获取sheet中用例行数
def get_rows
@worksheet.usedrange.rows.count
end #删除excel中上一次写入的数据
def del_excel_result
num = get_rows
for i in 3..num
@worksheet.Range("g#{i}").Value=''
@worksheet.Range("g#{i}").Interior.ColorIndex = 0 #无色 end
end #获取flag等于1的文件名称以及行数
def get_runinterface
num= get_rows
arr=[]
rows=[]
for i in 3..num
t=@worksheet.Range("d#{i}").Value
if t=='1'
rows<<i
arr<<@worksheet.Range("c#{i}").Value+'.rb'
end
end
return arr,rows
end #将执行结果写入excel
def judge_pass_fail file_path,rows
n=rows
if File.exist?("#{file_path}")
f=File.open("#{file_path}",mode='r')
case_str =f.readlines[2..-1]
case_str.each do|item|
@@i+=1
if item.include?('passed')
@worksheet.Range("g#{n}").Value='Pass'
@worksheet.Range("g#{n}").Interior.ColorIndex = 4 #绿色
elsif item.include? 'failed'
@@f +=1
@worksheet.Range("g#{n}").Value='Fail'
@worksheet.Range("g#{n}").Interior.ColorIndex = 3 #红色
else
@worksheet.Range("g#{n}").Value='wrong'
@worksheet.Range("g#{n}").Interior.ColorIndex = 40 #黄色
end
n +=1
end
else
puts 'not exist file'
end
[@@i,@@f]
end #关闭excel
def excel_close
@workbook.close(1)
end #获取case用例文件txt
def get_interface_result(file_path,rows)
if File.directory? file_path
i=0
Dir.foreach(file_path) do |file|
if file !="." and file !=".."
# p file_path+"/#{file}"
@one_line=judge_pass_fail(file_path+"/#{file}",rows[i])
i+=1
end
end
return @one_line
else
puts "file_path is not exist!"
end
end #删除上一次用例执行结果txt
def delete_spec list
if File.directory? list
FileUtils.rm_rf(list)
end
end def auto_write end end

ruby中excel简单操作以及文件读取操作方法的更多相关文章

  1. C# 使用自带Microsoft.Office.Interop.Excel简单操作Excel文件

    项目添加应用 Microsoft.Office.Interop.Excel.dll 文件 引用命名空间: using Excel = Microsoft.Office.Interop.Excel; 简 ...

  2. Perl读写Excel简单操作

    Perl读写Excel简单操作 使用模块 Spreadsheet::ParseExcel Spreadsheet::WriteExcel 读Excel #!/usr/bin/perl -w use s ...

  3. excel简单操作

    百度网盘(npoi.dll): http://pan.baidu.com/s/14eJRw //先创建一个文件流,指向磁盘上的某个Excel文件 using (FileStream fsRead = ...

  4. JAVA中通过Jaxp操作XML文件基础

    Java中有多种方式操作XML文件,目前讲一讲以SUN公司提供的DocumentBuilderFactory工厂类对象操作XML. 使用XML基本操作就是需要CRUD(增删改查),那么首先通过一个查询 ...

  5. Java代码操作properties文件(读取,新增/修改,删除)

    项目中需要用到操作properties文件中的数据,记录一下 package com.bonc.savepic.save; import java.io.FileNotFoundException; ...

  6. C# 文件操作 把文件读取到字节数组

    string zipfile = "c:\\a.zip"; //方法1 FileStream fs = new FileStream(zipfile, FileMode.Open) ...

  7. JavaScript中使用ActiveXObject操作本地文件夹的方法

    转载地址    http://www.jb51.net/article/48538.htm 在Windows平台上, js可以调用很多Windows提供的ActivexObject,本文就使用js来实 ...

  8. 【解决】SQL Server作业中Excel Application不能访问文件

    在通过SQL Server作业来实现定时任务时,出现如下错误: FullyQualifiedErrorId : ComMethodTargetInvocation使用“1”个参数调用“Add”时发生异 ...

  9. .NET中的IO操作之文件流

    读操作 //1.创建文件流 FileStream fsRead =new FileStream("1.txt",FileMode.Open); //2.创建缓冲区,正常情况下,是不 ...

随机推荐

  1. HDU 4336 容斥原理 || 状压DP

    状压DP :F(S)=Sum*F(S)+p(x1)*F(S^(1<<x1))+p(x2)*F(S^(1<<x2))...+1; F(S)表示取状态为S的牌的期望次数,Sum表示 ...

  2. 阿里云服务器远程mysql连不上

    使用grant all privilege命令添加了远程访问账号,可是还是怎么都连不上,查了好多才知道,原来在linux下,需要开启允许对外访问的网络端口才行. 使用以下步骤即可开启3306端口: / ...

  3. Python 程序员经常犯的 10 个错误

    关于PythonPython是一种解释性.面向对象并具有动态语义的高级程序语言.它内建了高级的数据结构,结合了动态类型和动态绑定的优点,这使得... 关于Python Python是一种解释性.面向对 ...

  4. supervisord 小记

    此篇仅用作supervisord的用法,不涉及理论说明和基础介绍 supervisor(一)基础篇 使用supervisord来管理process 进程的守护神 - Supervisor superv ...

  5. hibernate一级缓存

    理解 Hibernate 一级缓存 Hibernate 一级缓存默认是打开,不需要任何的配置.实际上,你无法强制禁止它的使用. 如果你理解了一级缓存实际上和会话是关联的,就很容易理解一级缓存.总所周知 ...

  6. HTML label标签的for属性--input标签的accesskey属性

    本次示例是在firefox演示(如果其他浏览器对accesskey操作不成功的,请参考文章最后各浏览器下的快捷键)label的for属性是和input的id绑定,当我们点击input前面的文本标识会自 ...

  7. iOS AppStore提交错误收集

    ERROR ITMS-90535: "Unexpected CFBundleExecutable Key. The bundle at 'Payload/创可贴.app/TencentOpe ...

  8. javascript中escape()、unescape()、encodeURI()、encodeURIComponent()、decodeURI()、decodeURIComponent()比较

    这些URI方法encodeURI.encodeURIComponent().decodeURI().decodeURIComponent()代替了BOM的escape()和unescape()方法.U ...

  9. 转载《Android Handler、Message》

    之前也是由于周末通宵看TI3比赛,一直没找到时间写博客,导致已经有好久没更新了.惭愧!后面还会恢复进度,尽量保证每周都写吧.这里也是先恭喜一下来自瑞典的Alliance战队夺得了TI3的冠军,希望明年 ...

  10. 第七章:LED将为我闪烁:控制发光二极管

        在之前章节了解到Linux驱动程序可以控制软硬件,可以实现软硬件之间的交互.在这章我们学习LED驱动的实现原理.Linux内核提供了多个与I/O内存交互的函数可以实现控制硬件.    编写LE ...