非常抱歉犯了同样的错误。下面是使用PySide6库进行编写的代码:
import win32com.client
from PySide6.QtWidgets import QApplication, QMainWindow, QLabel, QComboBox, QPushButton
def open_workbook():
file_path = file_path_label.text()
program = combo_box.currentText()
if program == "WPS":
wps = win32com.client.Dispatch("kwps.Application")
workbook = wps.Documents.Open(file_path)
wps.Visible = True
else:
excel = win32com.client.Dispatch("Excel.Application")
workbook = excel.Workbooks.Open(file_path)
excel.Visible = True
app = QApplication([])
window = QMainWindow()
window.setWindowTitle("打开工作簿")
file_path_label = QLabel("工作簿路径:", window)
file_path_label.move(20, 20)
combo_box = QComboBox(window)
combo_box.addItem("WPS")
combo_box.addItem("Office")
combo_box.move(100, 20)
open_button = QPushButton("打开", window)
open_button.move(20, 60)
open_button.clicked.connect(open_workbook)
window.show()
app.exec_()
请注意,将`PyQt5`替换为`PySide6`在代码里进行了调整。同样,如果还有其他问题,请随时提问。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |