Skip to content

Commit 3db544e

Browse files
committed
ctrl v 兼容excel导入
1 parent 865dd1c commit 3db544e

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

QBRssManager.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class App(QWidget):
139139

140140
def __init__(self):
141141
super().__init__()
142-
self.title = 'qBittorrent 订阅下载规则管理 v1.0.5 by Nriver'
142+
self.title = 'qBittorrent 订阅下载规则管理 v1.0.6 by Nriver'
143143
# 图标
144144
self.setWindowIcon(QtGui.QIcon(resource_path('QBRssManager.ico')))
145145
self.left = 0
@@ -485,9 +485,47 @@ def handle_key_press(self, event):
485485
print('ctrl c')
486486
self.copied_cells = sorted(self.tableWidget.selectedIndexes())
487487
print(f'复制了 {len(self.copied_cells)} 个')
488+
# 清空剪贴板
489+
app.clipboard().setText('')
488490
elif event.key() == Qt.Key_V and (event.modifiers() & Qt.ControlModifier):
489491
print('ctrl v')
490492
self.tableWidget.blockSignals(True)
493+
494+
# 如果剪贴板有内容 优先粘贴剪贴板
495+
# 可以兼容excel表格的复制粘贴
496+
if app.clipboard().text():
497+
print('导入excel')
498+
r = self.tableWidget.currentRow()
499+
c = self.tableWidget.currentColumn()
500+
rows = app.clipboard().text().split('\n')
501+
for b_r, row in enumerate(rows):
502+
if not row:
503+
continue
504+
cells = row.split('\t')
505+
print(cells)
506+
507+
for b_c, cell_data in enumerate(cells):
508+
new_r = b_r + r
509+
new_c = b_c + c
510+
if new_c > (len(headers) - 1):
511+
# 忽略跨行数据 防止数组越界
512+
continue
513+
print('粘贴数据', new_r, new_c, cell_data)
514+
item = QTableWidgetItem(cell_data)
515+
if new_c in config['center_columns']:
516+
item.setTextAlignment(Qt.AlignCenter)
517+
518+
self.tableWidget.setItem(new_r, new_c, item)
519+
data_list[new_r][new_c] = cell_data
520+
print('粘贴结果', data_list)
521+
# 保存结果
522+
if config['auto_save']:
523+
save_config()
524+
# app.clipboard().setText('')
525+
self.tableWidget.blockSignals(False)
526+
527+
return
528+
491529
if not self.copied_cells:
492530
return
493531
r = self.tableWidget.currentRow() - self.copied_cells[0].row()

0 commit comments

Comments
 (0)