讀取excel,類封裝(4)

2022-06-24 03:33:10 字數 1849 閱讀 4208

#基礎用例資料類

class caseinfo:

def __init__(self,case_id,case_name,case_module,case_pri,case_step,case_result):

self.case_id=case_id

self.case_name=case_name

self.case_module=case_module

self.case_pri=case_pri

self.case_step=case_step

self.case_result=case_result

#類封裝

import os

import xlrd

from pritices_daily import case_infos

class readexcel:

def __init__(self,excel_path):

self.excel_path=excel_path

def read_excel_data_convert_info_01(self):

# 1,讀取資料存到列表中:[[用例編號,用例名稱,所在模組...],[....],[......]]

workbook = xlrd.open_workbook(self.excel_path) # 開啟工作簿

sheet = workbook.sheet_by_index(0) # 開啟第乙個表

all_case_info1 =

for i in range(1, sheet.nrows):

case_info =

for j in range(0, sheet.ncols):

return all_case_info1

# 2,做成類形成

def read_excel_data_convert_info_02(self):

workbook = xlrd.open_workbook(self.excel_path) # 開啟工作簿

sheet = workbook.sheet_by_index(0) # 開啟第乙個表

all_case_info2 =

for i in range(1, sheet.nrows):

case_id = sheet.cell_value(i, 0)

case_name = sheet.cell_value(i, 1)

case_module = sheet.cell_value(i, 2)

case_pri = sheet.cell_value(i, 3)

case_step = sheet.cell_value(i, 4)

case_result = sheet.cell_value(i, 5)

caseinfo = case_infos.caseinfo(case_id, case_name, case_module, case_pri, case_step, case_result)

return all_case_info2[0].case_name

if __name__ == '__main__':

current_path = os.path.dirname(__file__)

excel_path = os.path.join(current_path, '../data/testcases.xlsx')

rd01=readexcel(excel_path)

print(rd01.read_excel_data_convert_info_01())

print(rd01.read_excel_data_convert_info_02())

C 中讀取Excel檔案的類封裝

總是感覺對於c 中讀取excel檔案是非常麻煩,還是決定自己來封裝乙個基於com介面的類解決這個問題。整體設計以及實現如下 首先 入對於microsoft.csharp以及office object library excel object library 譬如12.0版本的引用 public se...

介面測試 封裝讀取excel

1 xlrd庫的安裝 直接使用pip工具進行安裝 當然也可以使用pycharmide進行安裝,這裡就不詳述了 2 xlrd模組的一些常用命令 開啟excel檔案並建立物件儲存 data xlrd.open workbook 檔案路徑 獲取檔案中所有工作表的名稱 data.sheet names 根據...

Excel讀取程式設計 4

1.將資料從excel中匯入到資料庫中 將資料從excel表中匯入到資料中操作的思路比較簡單,就是通過逐行獲取單元格的內容,利用getitem 行位置m,列位置n 來獲取m行n列的值,再寫個writetodatabase cstring a,cstring z 函式,將資料匯入到資料庫中.此外設計關...