# 查询数据 ws = openpyxl.load_workbook(output_path2).active rows = ws.iter_rows(min_row=1, values_only=True) records = [] header = next(rows) for row in rows: if (not date or row[2] == date) and (not name or row[5] == name) and (not name1 or row[8] == name1) and (not name2 or row[6] == name2): records.append(row) # 显示查询结果 table_frame = tk.Frame(self.result_text) table = ttk.Treeview(table_frame, columns=header, show='headings') table.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) # 设置表格列标题 for col in header: table.heading(col, text=col) table.column(col, width=120) # 调整间隔距离 for row in records: table.insert('', tk.END, values=row)修改為直接顯示數據,不查詢了
时间: 2024-02-14 20:16:20 浏览: 102
如果您想直接显示数据而不是查询数据,您可以删除以下代码:
```
# 查询数据
ws = openpyxl.load_workbook(output_path2).active
rows = ws.iter_rows(min_row=1, values_only=True)
records = []
header = next(rows)
for row in rows:
if (not date or row[2] == date) and (not name or row[5] == name) and (not name1 or row[8] == name1) and (not name2 or row[6] == name2):
records.append(row)
# 显示查询结果
table_frame = tk.Frame(self.result_text)
table = ttk.Treeview(table_frame, columns=header, show='headings')
table.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# 设置表格列标题
for col in header:
table.heading(col, text=col)
table.column(col, width=120) # 调整间隔距离
for row in records:
table.insert('', tk.END, values=row)
```
然后,您可以将以下代码添加到您的代码中,以显示数据:
```
# 直接显示数据
table_frame = tk.Frame(self.result_text)
table = ttk.Treeview(table_frame, columns=(1, 2, 3, 4, 5, 6, 7, 8, 9), show='headings')
table.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# 设置表格列标题
header = ['列1', '列2', '列3', '列4', '列5', '列6', '列7', '列8', '列9']
for col in header:
table.heading(col, text=col)
table.column(col, width=120) # 调整间隔距离
# 显示数据
data = [['数据1', '数据2', '数据3', '数据4', '数据5', '数据6', '数据7', '数据8', '数据9'],
['数据1', '数据2', '数据3', '数据4', '数据5', '数据6', '数据7', '数据8', '数据9']]
for row in data:
table.insert('', tk.END, values=row)
```
阅读全文