讀取Excel

適合小型的Excel表格(2007版本之後)的讀取,大型的之後再慢慢加上python

import openpyxl


def read(path, sheet_name='Sheet1'):
    """
    讀取Excel文件
    :param path: 文件路徑
    :param sheet_name: sheet名
    :return: 二維列表
    """
    workbook = openpyxl.load_workbook(path)
    sheet = workbook.get_sheet_by_name(sheet_name)
    content = []
    with open(path, 'r', encoding='utf-8') as file:
        for row in sheet.rows:
            temp = []
            for cell in row:
                temp.append(cell.value.strip())
            content.append(temp)
    return content
相關文章
相關標籤/搜索