写一段代码 pyqt读取并显示Excel
时间: 2023-03-14 13:17:40 浏览: 225
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog
from PyQt5.QAxContainer import QAxWidget
import xlrdclass Window(QMainWindow):
def __init__(self):
super().__init__()
self.initUI() def initUI(self):
self.setGeometry(100,100,400,300)
self.setWindowTitle('PyQt读取并显示Excel') self.btnExcel = QFileDialog()
self.btnExcel.fileSelected.connect(self.openExcel) self.show() def openExcel(self):
fname = self.btnExcel.selectedFiles()
workbook = xlrd.open_workbook(fname[0])
sheet = workbook.sheet_by_index(0) for row in range(sheet.nrows):
for col in range(sheet.ncols):
print(sheet.cell_value(row, col))if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
sys.exit(app.exec_())
阅读全文