????????????_??????Python_openpyxl?????????Excel????????????_008

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了????????????_??????Python_openpyxl?????????Excel????????????_008相关的知识,希望对你有一定的参考价值。

?????????color   col   ??????   odi   load   ????????????   info   ??????   ...   

??????????????????

??????????????????????????????---------------------------------------------------------------------------------

# coding=utf-8
?????????
: ?????????:????????????????????????Demo??????????????????????????????,??????????????????????????????
Excel wordbook ????????? ->>??????sheet?????? --->cell ????????? pip install openpyxl ????????? # ???????????? ??????successed # from openpyxl import load_workbook # 1.??????????????? work_book = load_workbook(???test_data.xlsx???) # 2.??????????????????sheet???????????? sheet = work_book[???test_case???] # 3.???????????????????????? cell print(sheet.cell(2, 6).value) # 4.????????????Excel???????????? ->?????????????????????,????????????????????? sheet.cell(4, 7).value = ?????????biubiubiu...??? work_book.save(???test_data.xlsx???)

 

 

# coding=utf-8
"""
: ??????:  ???????????????????????????,???????????????
"""
from openpyxl import load_workbook


class DoExcel:
    def __init__(self, filepath, sheet_name):
        self.filepath = filepath
        self.sheet_name = sheet_name

    # :??????Excel?????????,??????????????????
    def read_data(self):
        wb = load_workbook(self.filepath)
        sheet_ = wb[self.sheet_name]

        # :?????????2,??????6???
        # : ????????????????????????????????????????????????
        test_data = []
        # 2,1   2,2   2,3   2,4
        # ????????????????????????????????????
        ?????????
        ?????????for?????????????????????,?????????for?????????6???,2,1 2,3 2,4
        ?????????
        for row in range(2, sheet_.max_row + 1):  # range(2,7)->??????range???????????????????????????So???  max+1
            list_1 = []
            for column in range(1, 7):  #
                list_1.append(sheet_.cell(row, column).value)  # ???,?????????
            test_data.append(list_1)
        print(test_data)
        return test_data

    def write_data(self):  # ??????????????????
        pass


if __name__ == ???__main__???:
    t = DoExcel(???test_data.xlsx???, ???test_case???)
    t.read_data()
    one_data = t.read_data()[0]
    print(one_data)

 



以上是关于????????????_??????Python_openpyxl?????????Excel????????????_008的主要内容,如果未能解决你的问题,请参考以下文章

python中__call__方法解析

python中的__name__

求一道python编程题

Python __name__ == ‘__main__’详细解释-Python零基础入门教程

Python __dict__与dir()区别

Python零碎