Метод, который вы указали, работает правильно.
import sys
import xlrd
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QAxContainer import QAxWidget
class AxWidget(QWidget):
def __init__(self, *args, **kwargs):
super(AxWidget, self).__init__(*args, **kwargs)
self.resize(800, 600)
layout = QVBoxLayout(self)
self.axWidget = QAxWidget(self)
layout.addWidget(self.axWidget)
layout.addWidget(QPushButton('Select file', self, clicked=self.getxlsbase))
def getxlsbase(self):
filePath_base, _ = QFileDialog.getOpenFileName(self,
'Select file',
'./',
'Excel Files (*.xls *.xlsx)')
print("filePath_base->", filePath_base)
base = xlrd.open_workbook(filePath_base)
print("base->", base)
hoja_base = base.sheet_by_index(0)
print("hoja_base->", hoja_base)
num_row = hoja_base.nrows
print("num_row->", num_row)
num_col = hoja_base.ncols
print("num_col->", num_col)
return self.openOffice(filePath_base, 'Excel.Application')
def openOffice(self, path, app):
self.axWidget.clear()
if not self.axWidget.setControl(app):
return QMessageBox.critical(self, 'Error', 'No installation %s' % app)
self.axWidget.dynamicCall(
'SetVisible (bool Visible)', 'false')
self.axWidget.setProperty('DisplayAlerts', False)
self.axWidget.setControl(path)
def closeEvent(self, event):
self.axWidget.close()
self.axWidget.clear()
self.layout().removeWidget(self.axWidget)
del self.axWidget
super(AxWidget, self).closeEvent(event)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = AxWidget()
ex.show()
sys.exit(app.exec_())
![enter image description here](https://i.stack.imgur.com/i83oE.jpg)