zoukankan      html  css  js  c++  java
  • Excel 筛选功能

    Excel 筛选功能

    file_path = r"C:Users闫佳怡Desktop雅诗兰黛实施PR2823-202002.xlsx"
    book = excel.open(file_path, visible=True, wps=False)
    # sht = book.get_sheet('Sheet1')
    
    def filter2(book, sheet_name, ranges, col, criteria1):
        """
        :criteria1: 筛选条件
    
        """
        from openpyxl.utils import get_column_letter
        allrow, allcol = book.get_sheet(sheet_name).get_row_col()
        # 处理range
        if ranges is None or ranges == "":
            end_position = get_column_letter(allcol)
            ranges = "A1:{0}{1}".format(end_position, allrow)
        sht = book.get_sheet(sheet_name).sht
        sht.Range(ranges).AutoFilter(Field=col, Criteria1=criteria1, Operator=7)
        filter_result = []
        for Area in sht.Range(ranges).SpecialCells(Type=12).Areas:
            for row in list(map(lambda x: list(x), Area.GetValue())):
                filter_result.append(row)
        return filter_result
    
    print(filter2(book=book, sheet_name="Sheet1", ranges="", col="1", criteria1="<0"))
    
  • 相关阅读:
    Linux的命令2
    运维书
    管理MariaDB
    MariaDB基础命令
    Linux创建桥接网络
    聚合网络
    kickstart
    VLAN原理
    进程优先和ACL
    计划任务at、crontab
  • 原文地址:https://www.cnblogs.com/yanjiayi098-001/p/12627880.html
Copyright © 2011-2022 走看看