吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1101|回复: 2
收起左侧

[求助] [求助]python,pyqt5的tableview编辑功能

[复制链接]
as19880115 发表于 2020-7-15 19:10
请大佬帮忙看一下怎么弄,万分感谢!

这边先写了一个自定义的pandasmodel,如下:
from PyQt5.QtCore import QAbstractTableModel,Qt

#TableView显示模块
class pandasModel(QAbstractTableModel):

    def __init__(self, data):
        QAbstractTableModel.__init__(self)
        self.data = data

    def rowCount(self, parent=None):
        return self.data.shape[0]

    def columnCount(self, parnet=None):
        return self.data.shape[1]

    def data(self, index, role=Qt.DisplayRole):
        if index.isValid():
            if role == Qt.DisplayRole:
                return str(self.data.iloc[index.row(), index.column()])
        return None
    #设置标题
    def headerData(self, col, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            return self.data.columns[col]
        return None

通过pd.read_excel读取了excel表格后,setmodel显示在了tableView里,后面的问题来了,需要通过tableview界面直接更改数据并且直接更改到真实的excel里应该怎么写?
这里tableview里显示的dateframe还是通过pd.merge()合并后的,请大佬忙帮指导一下,万分感谢!

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

崎岖人 发表于 2020-7-15 20:25
我太菜了,我的labview只能拖拖拖
 楼主| as19880115 发表于 2020-7-19 07:49
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-26 08:09

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表