非常抱歉,下面是更符合Python格式的代码示例:
import threading
import os
import xlrd
from openpyxl import load_workbook
class MyThread(threading.Thread):
def __init__(self, file_type, file_path):
super().__init__()
self.File_Type = file_type
self.File_Path = file_path
def run(self):
if self.File_Type == 'xls':
file_name = "汇总表.xls"
else:
file_name = "汇总表.xlsx"
# 拼接文件路径
file_path = os.path.join(self.File_Path, file_name)
if self.File_Type == 'xls':
Exclud_Book = xlrd.open_workbook(file_path)
else:
Exclud_Book = load_workbook(file_path)
for sheet_name in Exclud_Book.sheet_names():
exclude_rows_input = input()
if exclude_rows_input:
self.exclude_rows = exclude_cols_input = input()
if exclude_cols_input:
exclude_cols = exclude_rules = {'排除行': exclude_rows, '排除列': exclude_cols}
print(exclude_rules)
class BaseWindow(QWidget):
def __init__(self):
super().__init__()
# 其他初始化操作
def start_thread(self, file_type):
thread = MyThread(file_type, self.File_Path) # 将 File_Path 作为参数传递给 MyThread
thread.start()
class WindowA(BaseWindow):
def __init__(self):
super().__init__()
# 其他初始化操作
self.pushButton_1.clicked.connect(lambda: self.start_thread('xls')) # 按钮1的点击事件
self.pushButton_2.clicked.connect(lambda: self.start_thread('xlsx')) # 按钮2的点击事件
class WindowB(BaseWindow):
def __init__(self):
super().__init__()
# 其他初始化操作
self.pushButton_3.clicked.connect(lambda: self.start_thread('xls')) # 按钮3的点击事件
self.pushButton_4.clicked.connect(lambda: self.start_thread('xlsx')) # 按钮4的点击事件
希望这次的回复符合您的格式要求,如果还有其他问题,请随时提问。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |