从SAP GridView中获取数据

class SapGuiGridView:
    """
    SAP中GridView组件数据的表示对象类。

    用于从SAP的GridView中读取指定的数据。
    """

    @staticmethod
    def get_data(session, _id, columns, handler=None):
        """
        读取查询到的表格数据。

        :param session: SAP回话Session
        :param _id: SAP组件ID。
        :param columns: 列名称
        :param handler: 过滤函数
        """
        rows = []
        try:
            session.findById(_id)
        except Exception as _:
            # 无数据,直接返回
            return rows
        grid_view = session.findById(_id)
        row_count = grid_view.RowCount
        row_number = 0
        page_size = grid_view.VisibleRowCount

        while True:
            for i in range(page_size):
                row = [grid_view.GetCellValue(row_number, column) for column in columns]
                row_number += 1

                # print(row_number, row)

                tmp = handler(row) if handler else row
                if tmp:
                    # print(row_number, tmp)
                    rows.append(tmp)
                else:
                    # print('Delete', row_number)
                    pass

                if row_number >= row_count:
                    break
            if row_number >= row_count:
                break
            elif row_number + page_size < row_count:
                grid_view.firstVisibleRow = row_number
            else:
                grid_view.firstVisibleRow = row_count - page_size

        return rows

  

 

https://blog.csdn.net/chenguangqi/article/details/125787117?spm=1001.2014.3001.5502

posted @ 2023-08-24 21:50  CrossPython  阅读(100)  评论(0编辑  收藏  举报