原創|其它|編輯:郝浩|2012-10-12 13:54:49.000|閱讀 1612 次
概述:本文主要描述使用Aspose.cells處理excel表格的類,用于批量測試工具的,自己寫的,不足之處還是很多的。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
本文主要描述使用Aspose.cells處理excel表格的類,用于批量測試工具的,自己寫的,不足之處還是很多的
1.加載excel表格,會判斷excel是2007還是2003
2.sheet處理
3.行處理
using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Drawing;
    using Aspose.Cells;
    using System.IO;
    using System.Configuration;
    class ProcessExcel
    {
        //初始化excel
        public Workbook ImportExcel(string inputFile)
        {
            try
            {
                Workbook workBook = new Workbook();
                FileStream fs = new FileStream(ConfigurationSettings.AppSettings["InputFile"], FileMode.Open);
                int firstIndex=inputFile.LastIndexOf(".");
                string fileType = inputFile.Substring(firstIndex);
                if (fileType == ".xls")
                {
                    workBook.Open(fs);
                    return workBook;
                }
                else
                {
                    workBook.Open(fs, FileFormatType.Excel2007Xlsx);
                    return workBook;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("EXCEL初始化失敗,請檢查配置文件!");
                Console.ReadKey();
                return null;
            }
        }
     
        //處理sheet
        public void processSheet(Worksheet workSheet)
        {
            Cells cell = workSheet.Cells;
            int rowNum = cell.MaxDataRow;
            for (int i = 2; i <= rowNum; i++)
            {
                this.processRow(i, cell);
            }
        }
        //處理行
        public void processRow(int rowNum, Cells cell)
        {
            string userNO = cell[rowNum, 2].StringValue;
            string userContent = cell[rowNum, 3].StringValue;
            string expectReturnSMS = cell[rowNum, 4].StringValue;
            //用例標記為有效
            if (cell[rowNum, 1].StringValue == "1")
            {
                GetResult getResult = new GetResult();
                if (getResult.InvokeCMCC(userNO, userContent))
                {
                    if (getResult.GetReturnSMS(userNO))
                    {
                        getResult.GetTestResult(expectReturnSMS);
                        cell[rowNum, 5].PutValue(getResult.returnSMS);
                        if (getResult.testResult == "FALSE")
                        {
                            cell[rowNum, 6].PutValue(getResult.testResult);
                            cell[rowNum, 6].Style.BackgroundColor = Color.Red;
                        }
                        else
                        {
                            cell[rowNum, 6].PutValue(getResult.testResult);
                            cell[rowNum, 6].Style.BackgroundColor = Color.Green;
                        }
                    }
                    else
                    {
                        cell[rowNum, 6].PutValue("未獲取到返回短信");
                        cell[rowNum, 6].Style.BackgroundColor = Color.Yellow;
                    }
                }
                else
                {
                    cell[rowNum, 6].PutValue("CMCC接口調用異常");
                    cell[rowNum, 6].Style.BackgroundColor = Color.Yellow;
                }
            }   
         
            //用例無效
            else if(cell[rowNum, 1].StringValue == "0")
            {
                GetResult getResult = new GetResult();
                if (getResult.InvokeCMCC(userNO, userContent))
                {
                    Console.WriteLine("此條用例無需執行");
                    Console.WriteLine();
                }
                else
                {
                    cell[rowNum, 6].PutValue("CMCC接口調用異常");
                    Console.WriteLine();
                }
            }
        }     
}
					本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自:大頭的小寶的專欄-csdn