# -*-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 # obtain excel The title text of the first row and first column
def get_title
@worksheet.Range("a1").Value
end def get_receive
@worksheet.Range("i3").Value
end # obtain sheet Chinese routine
def get_rows
@worksheet.usedrange.rows.count
end # Delete excel Data last written in
def del_excel_result
num = get_rows
for i in 3..num
@worksheet.Range("g#{i}").Value=''
@worksheet.Range("g#{i}").Interior.ColorIndex = 0 # colourless end
end # obtain flag be equal to 1 The name of the file and the number of lines
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 # Write the execution result to 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 # green
elsif item.include? 'failed'
@@f +=1
@worksheet.Range("g#{n}").Value='Fail'
@worksheet.Range("g#{n}").Interior.ColorIndex = 3 # Red
else
@worksheet.Range("g#{n}").Value='wrong'
@worksheet.Range("g#{n}").Interior.ColorIndex = 40 # yellow
end
n +=1
end
else
puts 'not exist file'
end
[@@i,@@f]
end # close excel
def excel_close
@workbook.close(1)
end # obtain case Use case files 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 # Delete the last use case execution result txt
def delete_spec list
if File.directory? list
FileUtils.rm_rf(list)
end
end def auto_write end end

ruby in excel Simple operation and file read operation method of more related articles

  1. C# Use your own Microsoft.Office.Interop.Excel Simple operation Excel file

    Project add application  Microsoft.Office.Interop.Excel.dll file Reference namespace : using Excel = Microsoft.Office.Interop.Excel; Jane ...

  2. Perl Reading and writing Excel Simple operation

    Perl Reading and writing Excel Simple operation Using modules Spreadsheet::ParseExcel Spreadsheet::WriteExcel read Excel #!/usr/bin/perl -w use s ...

  3. excel Simple operation

    Baidu SkyDrive (npoi.dll): http://pan.baidu.com/s/14eJRw // First create a file stream , Point to some... On disk Excel file using (FileStream fsRead = ...

  4. JAVA Pass through Jaxp operation XML Document basis

    Java There are many ways to operate XML file , Now let's talk about SUN Provided by the company DocumentBuilderFactory Factory class object operations XML. Use XML The basic operation is to need CRUD( Additions and deletions ), So first, through a query ...

  5. Java Code operation properties file ( Read , newly added / modify , Delete )

    Operations are needed in the project properties The data in the file , Make a note of package com.bonc.savepic.save; import java.io.FileNotFoundException; ...

  6. C# File operations Read the file into a byte array

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

  7. JavaScript Use in ActiveXObject How to operate a local folder

    Reprinted address     http://www.jb51.net/article/48538.htm stay Windows On the platform , js You can call a lot of Windows Provided ActivexObject, This article uses js Lai Shi ...

  8. 【 solve 】SQL Server In homework Excel Application Can't access file

    Through SQL Server Homework to achieve the scheduled task , The following error occurred : FullyQualifiedErrorId : ComMethodTargetInvocation Use “1” Parameters call “Add” It's different from time to time ...

  9. .NET Medium IO File stream of operation

    Read operations //1. Create file stream FileStream fsRead =new FileStream("1.txt",FileMode.Open); //2. Create buffer , Under normal circumstances , It is not ...

Random recommendation

  1. CentOS6.3 install MongoDB2.2 And install PHP Of MongoDB client

    Download the source code :( Put it in /usr/local/src Under the table of contents ) To the official website  http://www.mongodb.org/downloads  Download the source code https://fastdl.mongodb.org/li ...

  2. JSP(include Command and &lt;jsp:include&gt; The difference in action )

    <%@ page language= "java" contentType="text/html;charset=UTF-8" %><html ...

  3. hdu 5272 Dylans loves numbers

    Topic linking http://acm.hdu.edu.cn/showproblem.php?pid=5272 Dylans loves numbers Description Who is Dylans?Y ...

  4. Sass operation

    Add in CSS Can do arithmetic in , So far only calc() The function works . stay Sass in , Operation is just one of its basic characteristics . stay Sass You can do all kinds of mathematical calculations in . The addition operation is Sass One of the operations in , In variables or properties ...

  5. 【ASP.NET MVC】MVC summary

    describe This article mainly summarizes ASP.NET MVC, It includes the following contents : 1.MVC Model overview 2.WebForm summary 3.WebForm And MVC difference 4.ASP.NET MVC development history 5. Using program structure 6. ...

  6. mysql In the index USING BTREE The meaning of

    Indexes are implemented in the storage engine , So the index of each storage engine is not necessarily the same , And each storage engine does not necessarily support all index types . Define the maximum number of indexes and the maximum index length of each table according to the storage engine . All storage engines support at least... Per table 16 An index , total ...

  7. stay delphi in XLSReadWriteII. Application examples of components (2)

    Third party component :XLSReadWriteII.v.5.20.67_XE3 The source code of the example is as follows :   unit Unit1; interface uses Winapi.Windows, Winapi.Messa ...

  8. python Realization stack And test the

    Stack (stack) Also known as the stack , It's an operationally constrained linear table . The limitation is that only insert and delete operations are allowed at one end of the table . This end is called the top of the stack , relatively , Call the other end the bottom of the stack . Inserting a new element into a stack is also called a push . Push or push , It's a new The elements put ...

  9. C# Language ———— Format the table of numerical results

    character explain                                       Example                                                   Output results .C ...

  10. javascript in call,apply,bind A comparative analysis of the usage of

    This article mainly gives you a comparative analysis javascript in call,apply,bind The use of three functions , Very detailed , I recommend it to my friends .   About call,apply,bind The usage of these three functions , It's learning java ...