ruby中excel简单操作以及文件读取操作方法
# -*-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简单操作以及文件读取操作方法的更多相关文章
- C# 使用自带Microsoft.Office.Interop.Excel简单操作Excel文件
项目添加应用 Microsoft.Office.Interop.Excel.dll 文件 引用命名空间: using Excel = Microsoft.Office.Interop.Excel; 简 ...
- Perl读写Excel简单操作
Perl读写Excel简单操作 使用模块 Spreadsheet::ParseExcel Spreadsheet::WriteExcel 读Excel #!/usr/bin/perl -w use s ...
- excel简单操作
百度网盘(npoi.dll): http://pan.baidu.com/s/14eJRw //先创建一个文件流,指向磁盘上的某个Excel文件 using (FileStream fsRead = ...
- JAVA中通过Jaxp操作XML文件基础
Java中有多种方式操作XML文件,目前讲一讲以SUN公司提供的DocumentBuilderFactory工厂类对象操作XML. 使用XML基本操作就是需要CRUD(增删改查),那么首先通过一个查询 ...
- Java代码操作properties文件(读取,新增/修改,删除)
项目中需要用到操作properties文件中的数据,记录一下 package com.bonc.savepic.save; import java.io.FileNotFoundException; ...
- C# 文件操作 把文件读取到字节数组
string zipfile = "c:\\a.zip"; //方法1 FileStream fs = new FileStream(zipfile, FileMode.Open) ...
- JavaScript中使用ActiveXObject操作本地文件夹的方法
转载地址 http://www.jb51.net/article/48538.htm 在Windows平台上, js可以调用很多Windows提供的ActivexObject,本文就使用js来实 ...
- 【解决】SQL Server作业中Excel Application不能访问文件
在通过SQL Server作业来实现定时任务时,出现如下错误: FullyQualifiedErrorId : ComMethodTargetInvocation使用“1”个参数调用“Add”时发生异 ...
- .NET中的IO操作之文件流
读操作 //1.创建文件流 FileStream fsRead =new FileStream("1.txt",FileMode.Open); //2.创建缓冲区,正常情况下,是不 ...
随机推荐
- mantis邮箱配置
1.修改/var/www/html/mantisbt-1.3.3/config下config_inc.php配置文件 以163邮箱为例 # --- Email Configuration --- $g ...
- Codeforces Round #376 (Div. 2)
A 模拟 #include <cstdio> #include <cstring> int Ans; ]; inline ?x:-x;} inline int Min(int ...
- Spring的Bean的基本概念
Spring其实就是一个大型的工厂,而Spring容器中的Bean就是该工厂的产品.Spring容器能够生产哪些产品,取决于配置文件的配置. 对于我们而言,使用Spring框架做两件事:开发Bean. ...
- JavaScript闭包模型
JavaScript闭包模型 ----- [原创翻译]2016-09-01 09:32:22 < 一> 闭包并不神秘 本文利用JavaScript代码来阐述闭包,目的是为了使普通 ...
- 关于asp.net的一点小问题有谁帮忙解答一下?
public IList<Category> Categories { get; set; } protected void Page_Load(object sender, ...
- Matlab从一系列图片导出AVI视频,导出GIF动图
平台:Win7,Matlab 2014a 从一系列图片导出AVI视频的M代码如下: clear all; % 清除变量 % 官方示例,命令窗口输入“doc VideoWriter” writerObj ...
- 网站统计中的数据收集原理及实现(share)
转载自:http://blog.codinglabs.org/articles/how-web-analytics-data-collection-system-work.html 网站数据统计分析工 ...
- [读书笔记]Java之静态分派
以下内容来自周志明的<深入理解Java虚拟机>. 静态分派和重载有关. 先看代码: public static void main(String[] args) { SuperClass ...
- HTML5上传图片到ASP.NET.MVC
@{ ViewBag.Title = "Home Page";} <!DOCTYPE HTML PUBLIC><html><head> < ...
- java.lang.NoClassDefFoundError: de.greenrobot.event.EventBus
转自:http://blog.csdn.net/jyp123123/article/details/52836905 java.lang.NoClassDefFoundError: de.greenr ...